Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resolver = "2"

[workspace.package]
version = "0.5.17"
edition = "2021"
edition = "2024"
rust-version = "1.89"
authors = [
"Rohit Narurkar <rohit.narurkar@protonmail.com>",
Expand Down
31 changes: 14 additions & 17 deletions crates/svm-rs/src/bin/solc/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,21 @@ fn main() {

fn main_() -> anyhow::Result<i32> {
let mut args = std::env::args_os().skip(1).peekable();
let version = 'v: {
// Try to parse the first argument as a version specifier `+x.y.z`.
if let Some(arg) = args.peek() {
if let Some(arg) = arg.to_str() {
if let Some(stripped) = arg.strip_prefix('+') {
let version = stripped
.parse::<semver::Version>()
.context("failed to parse version specifier")?;
if !version.build.is_empty() || !version.pre.is_empty() {
anyhow::bail!(
"version specifier must not have pre-release or build metadata"
);
}
args.next();
break 'v version;
}
}

// Try to parse the first argument as a version specifier `+x.y.z`.
let version = if let Some(arg) = args.peek()
&& let Some(arg) = arg.to_str()
&& let Some(stripped) = arg.strip_prefix('+')
{
let version = stripped
.parse::<semver::Version>()
.context("failed to parse version specifier")?;
if !version.build.is_empty() || !version.pre.is_empty() {
anyhow::bail!("version specifier must not have pre-release or build metadata");
}
args.next();
version
} else {
// Fallback to the global version if one is not specified.
svm::get_global_version()?.ok_or(svm::SvmError::GlobalVersionNotSet)?
};
Expand Down
21 changes: 10 additions & 11 deletions crates/svm-rs/src/bin/svm-bin/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,16 @@ impl RemoveCmd {
.interact_text()?;
if matches!(input.as_str(), "y" | "Y" | "yes" | "Yes") {
svm::remove_version(&version)?;
if let Some(v) = current_version {
if version == v {
if let Some(i) = installed_versions.iter().position(|x| *x == v) {
installed_versions.remove(i);
if let Some(new_version) = installed_versions.pop() {
svm::set_global_version(&new_version)?;
print::set_global_version(&new_version);
} else {
svm::unset_global_version()?;
}
}
if let Some(v) = current_version
&& version == v
&& let Some(i) = installed_versions.iter().position(|x| *x == v)
{
installed_versions.remove(i);
if let Some(new_version) = installed_versions.pop() {
svm::set_global_version(&new_version)?;
print::set_global_version(&new_version);
} else {
svm::unset_global_version()?;
}
}
}
Expand Down
49 changes: 28 additions & 21 deletions crates/svm-rs/src/install.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
all_releases, data_dir, platform, releases::artifact_url, setup_data_dir, setup_version,
version_binary, SvmError,
SvmError, all_releases, data_dir, platform, releases::artifact_url, setup_data_dir,
setup_version, version_binary,
};
use semver::Version;
use sha2::Digest;
Expand Down Expand Up @@ -137,13 +137,12 @@ fn do_install_and_retry(
if err.to_string().to_lowercase().contains("text file busy") {
// busy solc can be in use for a while (e.g. if compiling a large project), so we check if the file exists and has the correct checksum
let solc_path = version_binary(&version.to_string());
if solc_path.exists() {
if let Ok(content) = fs::read(&solc_path) {
if ensure_checksum(&content, version, expected_checksum).is_ok() {
// checksum of the existing file matches the expected release checksum
return Ok(solc_path);
}
}
if solc_path.exists()
&& let Ok(content) = fs::read(&solc_path)
&& ensure_checksum(&content, version, expected_checksum).is_ok()
{
// checksum of the existing file matches the expected release checksum
return Ok(solc_path);
}

// retry after some time
Expand Down Expand Up @@ -366,9 +365,11 @@ mod tests {
install(&version).await.unwrap();
let solc_path = version_binary(version.to_string().as_str());
let output = Command::new(solc_path).arg("--version").output().unwrap();
assert!(String::from_utf8_lossy(&output.stdout)
.as_ref()
.contains("0.8.10"));
assert!(
String::from_utf8_lossy(&output.stdout)
.as_ref()
.contains("0.8.10")
);
}

#[cfg(feature = "blocking")]
Expand All @@ -379,9 +380,11 @@ mod tests {
let solc_path = version_binary(LATEST.to_string().as_str());
let output = Command::new(solc_path).arg("--version").output().unwrap();

assert!(String::from_utf8_lossy(&output.stdout)
.as_ref()
.contains(&LATEST.to_string()));
assert!(
String::from_utf8_lossy(&output.stdout)
.as_ref()
.contains(&LATEST.to_string())
);
}

#[cfg(feature = "blocking")]
Expand All @@ -393,9 +396,11 @@ mod tests {
let solc_path = version_binary(version.to_string().as_str());
let output = Command::new(solc_path).arg("--version").output().unwrap();

assert!(String::from_utf8_lossy(&output.stdout)
.as_ref()
.contains("0.8.10"));
assert!(
String::from_utf8_lossy(&output.stdout)
.as_ref()
.contains("0.8.10")
);
}

#[cfg(feature = "blocking")]
Expand Down Expand Up @@ -460,8 +465,10 @@ mod tests {
let solc_path = version_binary(version.to_string().as_str());
let output = Command::new(&solc_path).arg("--version").output().unwrap();

assert!(String::from_utf8_lossy(&output.stdout)
.as_ref()
.contains("0.7.1"));
assert!(
String::from_utf8_lossy(&output.stdout)
.as_ref()
.contains("0.7.1")
);
}
}
4 changes: 2 additions & 2 deletions crates/svm-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ mod paths;
pub use paths::{data_dir, global_version_path, setup_data_dir, version_binary, version_path};

mod platform;
pub use platform::{platform, Platform};
pub use platform::{Platform, platform};

mod releases;
pub use releases::{all_releases, BuildInfo, Releases};
pub use releases::{BuildInfo, Releases, all_releases};

#[cfg(feature = "blocking")]
pub use releases::blocking_all_releases;
Expand Down
20 changes: 7 additions & 13 deletions crates/svm-rs/src/releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,24 @@ static OLD_SOLC_RELEASES: LazyLock<Releases> = LazyLock::new(|| {

const LINUX_AARCH64_MIN: Version = Version::new(0, 5, 0);

static LINUX_AARCH64_URL_PREFIX: &str =
"https://raw.githubusercontent.com/nikitastupin/solc/0045084c85d8c159de03442a37d2018d52374445/linux/aarch64";
static LINUX_AARCH64_URL_PREFIX: &str = "https://raw.githubusercontent.com/nikitastupin/solc/0045084c85d8c159de03442a37d2018d52374445/linux/aarch64";

static LINUX_AARCH64_RELEASES_URL: &str =
"https://raw.githubusercontent.com/nikitastupin/solc/0045084c85d8c159de03442a37d2018d52374445/linux/aarch64/list.json";
static LINUX_AARCH64_RELEASES_URL: &str = "https://raw.githubusercontent.com/nikitastupin/solc/0045084c85d8c159de03442a37d2018d52374445/linux/aarch64/list.json";

// NOTE: Since version 0.8.24, universal macosx releases are available: https://binaries.soliditylang.org/macosx-amd64/list.json
const MACOS_AARCH64_NATIVE: Version = Version::new(0, 8, 5);

const UNIVERSAL_MACOS_BINARIES: Version = Version::new(0, 8, 24);

static MACOS_AARCH64_URL_PREFIX: &str =
"https://raw.githubusercontent.com/alloy-rs/solc-builds/e4b80d33bc4d015b2fc3583e217fbf248b2014e1/macosx/aarch64";
static MACOS_AARCH64_URL_PREFIX: &str = "https://raw.githubusercontent.com/alloy-rs/solc-builds/e4b80d33bc4d015b2fc3583e217fbf248b2014e1/macosx/aarch64";

static MACOS_AARCH64_RELEASES_URL: &str =
"https://raw.githubusercontent.com/alloy-rs/solc-builds/e4b80d33bc4d015b2fc3583e217fbf248b2014e1/macosx/aarch64/list.json";
static MACOS_AARCH64_RELEASES_URL: &str = "https://raw.githubusercontent.com/alloy-rs/solc-builds/e4b80d33bc4d015b2fc3583e217fbf248b2014e1/macosx/aarch64/list.json";

const ANDROID_AARCH64_MIN: Version = Version::new(0, 8, 24);

static ANDROID_AARCH64_URL_PREFIX: &str =
"https://raw.githubusercontent.com/alloy-rs/solc-builds/ac6f303a04b38e7ec507ced511fd3ed7a605179f/android/aarch64";
static ANDROID_AARCH64_URL_PREFIX: &str = "https://raw.githubusercontent.com/alloy-rs/solc-builds/ac6f303a04b38e7ec507ced511fd3ed7a605179f/android/aarch64";

static ANDROID_AARCH64_RELEASES_URL: &str =
"https://raw.githubusercontent.com/alloy-rs/solc-builds/ac6f303a04b38e7ec507ced511fd3ed7a605179f/android/aarch64/list.json";
static ANDROID_AARCH64_RELEASES_URL: &str = "https://raw.githubusercontent.com/alloy-rs/solc-builds/ac6f303a04b38e7ec507ced511fd3ed7a605179f/android/aarch64/list.json";

/// Defines the struct that the JSON-formatted release list can be deserialized into.
///
Expand Down Expand Up @@ -115,7 +109,7 @@ pub struct BuildInfo {
/// Helper serde module to serialize and deserialize bytes as hex.
mod hex_string {
use super::*;
use serde::{de, Deserializer, Serializer};
use serde::{Deserializer, Serializer, de};

pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
where
Expand Down
Loading