diff --git a/Cargo.toml b/Cargo.toml index 1be96c3..b1e8391 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ resolver = "2" [workspace.package] version = "0.5.17" -edition = "2021" +edition = "2024" rust-version = "1.89" authors = [ "Rohit Narurkar ", diff --git a/crates/svm-rs/src/bin/solc/main.rs b/crates/svm-rs/src/bin/solc/main.rs index dff7a3b..91b8ca5 100644 --- a/crates/svm-rs/src/bin/solc/main.rs +++ b/crates/svm-rs/src/bin/solc/main.rs @@ -25,24 +25,21 @@ fn main() { fn main_() -> anyhow::Result { 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::() - .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::() + .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)? }; diff --git a/crates/svm-rs/src/bin/svm-bin/remove.rs b/crates/svm-rs/src/bin/svm-bin/remove.rs index 20d1a8e..86ffd6a 100644 --- a/crates/svm-rs/src/bin/svm-bin/remove.rs +++ b/crates/svm-rs/src/bin/svm-bin/remove.rs @@ -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()?; } } } diff --git a/crates/svm-rs/src/install.rs b/crates/svm-rs/src/install.rs index d82af97..806f1a5 100644 --- a/crates/svm-rs/src/install.rs +++ b/crates/svm-rs/src/install.rs @@ -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; @@ -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 @@ -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")] @@ -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")] @@ -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")] @@ -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") + ); } } diff --git a/crates/svm-rs/src/lib.rs b/crates/svm-rs/src/lib.rs index 7ca5768..851cf1e 100644 --- a/crates/svm-rs/src/lib.rs +++ b/crates/svm-rs/src/lib.rs @@ -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; diff --git a/crates/svm-rs/src/releases.rs b/crates/svm-rs/src/releases.rs index fc8476d..1cb8346 100644 --- a/crates/svm-rs/src/releases.rs +++ b/crates/svm-rs/src/releases.rs @@ -30,30 +30,24 @@ static OLD_SOLC_RELEASES: LazyLock = 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. /// @@ -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, D::Error> where