Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for 0.8.25 #118

Merged
merged 4 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
[<img alt="docs.rs" src="https://img.shields.io/docsrs/svm-rs/latest?color=66c2a5&label=docs-rs&style=for-the-badge" height="20">](https://docs.rs/svm-rs/latest/svm_lib/)
[<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/roynalnaruto/svm-rs/ci.yml?branch=master&style=for-the-badge" height="20">](https://github.com/roynalnaruto/svm-rs/actions?query=branch%3Amaster)

This crate provides a cross-platform support for managing Solidity compiler versions.

## Install

From [crates.io](https://crates.io):
Expand Down
32 changes: 9 additions & 23 deletions crates/svm-rs/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,10 @@ fn ensure_checksum(
#[cfg(test)]
mod tests {
use super::*;
use crate::{
platform::Platform,
releases::{all_releases, artifact_url},
};
use rand::seq::SliceRandom;

const LATEST: Version = Version::new(0, 8, 24);
#[allow(unused)]
const LATEST: Version = Version::new(0, 8, 25);

#[tokio::test]
async fn test_install() {
Expand Down Expand Up @@ -307,25 +304,14 @@ mod tests {
t.await.unwrap().unwrap();
}

// ensures we can download the latest native solc for apple silicon
// ensures we can download the latest universal solc for apple silicon
#[tokio::test(flavor = "multi_thread")]
async fn can_download_latest_native_apple_silicon() {
let artifacts = all_releases(Platform::MacOsAarch64).await.unwrap();

let artifact = artifacts.releases.get(&LATEST).unwrap();
let download_url = artifact_url(
Platform::MacOsAarch64,
&LATEST,
artifact.to_string().as_str(),
)
.unwrap();

let expected_checksum = artifacts.get_checksum(&LATEST).unwrap();

let resp = reqwest::get(download_url).await.unwrap();
assert!(resp.status().is_success());
let binbytes = resp.bytes().await.unwrap();
ensure_checksum(&binbytes, &LATEST, &expected_checksum).unwrap();
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
async fn can_install_latest_native_apple_silicon() {
let solc = install(&LATEST).await.unwrap();
let output = Command::new(solc).arg("--version").output().unwrap();
let version = String::from_utf8_lossy(&output.stdout);
assert!(version.contains("0.8.25"), "{}", version);
}

// ensures we can download the latest native solc for linux aarch64
Expand Down
31 changes: 23 additions & 8 deletions crates/svm-rs/src/releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ use url::Url;

// Updating new releases:
// 1. Update `https://github.com/nikitastupin/solc` commit for `linux/aarch64`
// 2. Update `https://github.com/alloy-rs/solc-builds` commit for `macosx/aarch64`
// 2. Update LATEST for tests

/// Base URL for all Solc releases
/// `"SOLC_RELEASES_URL}/{platform}/list.json"`:
/// `https://binaries.soliditylang.org/linux-amd64/list.json`
/// `https://binaries.soliditylang.org/windows-amd64/list.json`
/// `https://binaries.soliditylang.org/macosx-amd64/list.json`
const SOLC_RELEASES_URL: &str = "https://binaries.soliditylang.org";

const OLD_SOLC_RELEASES_DOWNLOAD_PREFIX: &str =
Expand All @@ -27,13 +32,16 @@ static OLD_SOLC_RELEASES: Lazy<Releases> = Lazy::new(|| {
const LINUX_AARCH64_MIN: Version = Version::new(0, 5, 0);

static LINUX_AARCH64_URL_PREFIX: &str =
"https://github.com/nikitastupin/solc/raw/7687d6ce15553292adbb3e6c565eafea6e0caf85/linux/aarch64";
"https://github.com/nikitastupin/solc/raw/fd781c58fe3abb978749bb3184405d1fe7c4cd26/linux/aarch64";

static LINUX_AARCH64_RELEASES_URL: &str =
"https://github.com/nikitastupin/solc/raw/7687d6ce15553292adbb3e6c565eafea6e0caf85/linux/aarch64/list.json";
"https://github.com/nikitastupin/solc/raw/fd781c58fe3abb978749bb3184405d1fe7c4cd26/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://github.com/alloy-rs/solc-builds/raw/e4b80d33bc4d015b2fc3583e217fbf248b2014e1/macosx/aarch64";

Expand Down Expand Up @@ -133,6 +141,8 @@ pub fn blocking_all_releases(platform: Platform) -> Result<Releases, SvmError> {
//
// 2. For version <= 0.8.4 we fetch releases from https://binaries.soliditylang.org and
// require Rosetta support.
//
// Note: Since 0.8.24 universal macosx releases are available
let mut native =
reqwest::blocking::get(MACOS_AARCH64_RELEASES_URL)?.json::<Releases>()?;
let mut releases = reqwest::blocking::get(format!(
Expand All @@ -145,6 +155,7 @@ pub fn blocking_all_releases(platform: Platform) -> Result<Releases, SvmError> {
.builds
.retain(|b| b.version.lt(&MACOS_AARCH64_NATIVE));
releases.builds.extend_from_slice(&native.builds);

releases.releases.append(&mut native.releases);
Ok(releases)
}
Expand Down Expand Up @@ -184,10 +195,12 @@ pub async fn all_releases(platform: Platform) -> Result<Releases, SvmError> {
.await?
.json::<Releases>()
.await?;
releases.builds.retain(|b| {
b.version.lt(&MACOS_AARCH64_NATIVE) || b.version.gt(&UNIVERSAL_MACOS_BINARIES)
});
releases
.builds
.retain(|b| b.version.lt(&MACOS_AARCH64_NATIVE));
releases.releases.retain(|v, _| v.lt(&MACOS_AARCH64_NATIVE));
.releases
.retain(|v, _| v.lt(&MACOS_AARCH64_NATIVE) || v.gt(&UNIVERSAL_MACOS_BINARIES));

releases.builds.extend_from_slice(&native.builds);
releases.releases.append(&mut native.releases);
Expand Down Expand Up @@ -252,11 +265,13 @@ pub(crate) fn artifact_url(
}

if platform == Platform::MacOsAarch64 {
if version.ge(&MACOS_AARCH64_NATIVE) {
if version.ge(&MACOS_AARCH64_NATIVE) && version.le(&UNIVERSAL_MACOS_BINARIES) {
// fetch natively build solc binaries from `https://github.com/alloy-rs/solc-builds`
return Ok(Url::parse(&format!(
"{MACOS_AARCH64_URL_PREFIX}/{artifact}"
))?);
} else {
// if version is older or universal macos binaries are available, fetch from `https://binaries.soliditylang.org`
return Ok(Url::parse(&format!(
"{}/{}/{}",
SOLC_RELEASES_URL,
Expand All @@ -282,7 +297,7 @@ mod tests {
assert_eq!(
artifact_url(Platform::LinuxAarch64, &version, artifact).unwrap(),
Url::parse(&format!(
"https://github.com/nikitastupin/solc/raw/7687d6ce15553292adbb3e6c565eafea6e0caf85/linux/aarch64/{artifact}"
"https://github.com/nikitastupin/solc/raw/fd781c58fe3abb978749bb3184405d1fe7c4cd26/linux/aarch64/{artifact}"
))
.unwrap(),
)
Expand Down