mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-06-17 17:01:05 +00:00
the solc binaries list downloader
Signed-off-by: xermicus <bigcyrill@hotmail.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
[package]
|
||||
name = "revive-dt-compiler"
|
||||
description = "Library for compiling Solidity contracts to EVM and PVM"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
@@ -39,6 +39,12 @@ pub struct Compiler<T: SolidityCompiler> {
|
||||
base_path: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for Compiler<solc::Solc> {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Compiler<T>
|
||||
where
|
||||
T: SolidityCompiler,
|
||||
|
||||
@@ -1,2 +1,25 @@
|
||||
//! Implements the [SolidityCompiler] trait with solc for
|
||||
//! compiling contracts to EVM bytecode.
|
||||
|
||||
use revive_solc_json_interface::{SolcStandardJsonInput, SolcStandardJsonOutput};
|
||||
use semver::Version;
|
||||
|
||||
use crate::SolidityCompiler;
|
||||
|
||||
pub struct Solc {}
|
||||
|
||||
impl SolidityCompiler for Solc {
|
||||
type Options = ();
|
||||
|
||||
fn build(
|
||||
&self,
|
||||
_input: &SolcStandardJsonInput,
|
||||
_extra_options: &Option<Self::Options>,
|
||||
) -> anyhow::Result<SolcStandardJsonOutput> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn new(_solc_version: &Version) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[package]
|
||||
name = "revive-dt-node-interaction"
|
||||
description = "send and trace transactions to EVM and PVM nodes"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
[package]
|
||||
name = "revive-dt-solc-binaries"
|
||||
dependencies = "Download and cache solc binaries"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
license.workspace = true
|
||||
edition.workspace = true
|
||||
repository.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
[features]
|
||||
default = ["download"]
|
||||
download = ["reqwest"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = { workspace = true }
|
||||
once_cell = { workspace = true }
|
||||
reqwest = { workspace = true, optional = true }
|
||||
semver = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
@@ -0,0 +1,61 @@
|
||||
//! This module downloads solc binaries.
|
||||
|
||||
use std::{collections::HashMap, sync::Mutex};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::list::List;
|
||||
|
||||
pub static LIST_CACHE: Lazy<Mutex<HashMap<&'static str, List>>> = Lazy::new(Default::default);
|
||||
|
||||
impl List {
|
||||
pub const LINUX_URL: &str = "https://binaries.soliditylang.org/linux-amd64/list.json";
|
||||
pub const WINDOWS_URL: &str = "https://binaries.soliditylang.org/windows-amd64/list.json";
|
||||
pub const MACOSX_URL: &str = "https://binaries.soliditylang.org/macosx-amd64/list.json";
|
||||
pub const WASM_URL: &str = "https://binaries.soliditylang.org/wasm/list.json";
|
||||
|
||||
/// Try to downloads the list from the given URL.
|
||||
///
|
||||
/// Caches the list retrieved from the `url` into [LIST_CACHE],
|
||||
/// subsequent calls with the same `url` will return the cached list.
|
||||
pub fn download(url: &'static str) -> anyhow::Result<Self> {
|
||||
if let Some(list) = LIST_CACHE.lock().unwrap().get(url) {
|
||||
return Ok(list.clone());
|
||||
}
|
||||
|
||||
let body: List = reqwest::blocking::get(url)?.json()?;
|
||||
|
||||
LIST_CACHE.lock().unwrap().insert(url, body.clone());
|
||||
|
||||
Ok(body)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::list::List;
|
||||
|
||||
#[test]
|
||||
fn try_get_windows_list() {
|
||||
List::download(List::WINDOWS_URL).unwrap();
|
||||
List::download(List::WINDOWS_URL).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_get_macosx_list() {
|
||||
List::download(List::MACOSX_URL).unwrap();
|
||||
List::download(List::MACOSX_URL).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_get_linux_list() {
|
||||
List::download(List::LINUX_URL).unwrap();
|
||||
List::download(List::LINUX_URL).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_get_wasm_list() {
|
||||
List::download(List::WASM_URL).unwrap();
|
||||
List::download(List::WASM_URL).unwrap();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
//! This crates provides serializable Rust type definitions for the [solc binary lists][0].
|
||||
//! The `download` feature enables helpers to download and cache solc binaries.
|
||||
//!
|
||||
//! [0]: https://binaries.soliditylang.org
|
||||
|
||||
#[cfg(feature = "download")]
|
||||
pub mod download;
|
||||
pub mod list;
|
||||
@@ -0,0 +1,26 @@
|
||||
//! Rust type definitions for the solc binary lists.
|
||||
|
||||
use std::{collections::HashMap, path::PathBuf};
|
||||
|
||||
use semver::Version;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
|
||||
pub struct List {
|
||||
pub builds: Vec<Build>,
|
||||
pub releases: HashMap<Version, String>,
|
||||
#[serde(rename = "latestRelease")]
|
||||
pub latest_release: Version,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
|
||||
pub struct Build {
|
||||
pub path: PathBuf,
|
||||
pub version: Version,
|
||||
pub build: String,
|
||||
#[serde(rename = "longVersion")]
|
||||
pub long_version: String,
|
||||
keccak256: String,
|
||||
sha256: String,
|
||||
urls: Vec<String>,
|
||||
}
|
||||
Reference in New Issue
Block a user