Skip to content

Commit

Permalink
feat: add android-aarch64 support
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Jan 17, 2025
1 parent 0b20256 commit 433aa1c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/svm-builds/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use svm::Releases;
/// - "macosx-amd64"
/// - "macosx-aarch64"
/// - "windows-amd64"
/// - "android-aarch64"
pub const SVM_TARGET_PLATFORM: &str = "SVM_TARGET_PLATFORM";

/// The path to the releases JSON file, that was pre-fetched manually.
Expand Down
10 changes: 10 additions & 0 deletions crates/svm-rs/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum Platform {
MacOsAmd64,
MacOsAarch64,
WindowsAmd64,
AndroidAarch64,
Unsupported,
}

Expand All @@ -21,6 +22,7 @@ impl fmt::Display for Platform {
Self::MacOsAmd64 => "macosx-amd64",
Self::MacOsAarch64 => "macosx-aarch64",
Self::WindowsAmd64 => "windows-amd64",
Self::AndroidAarch64 => "android-aarch64",
Self::Unsupported => "Unsupported-platform",
};
f.write_str(s)
Expand All @@ -37,6 +39,7 @@ impl FromStr for Platform {
"macosx-amd64" => Ok(Self::MacOsAmd64),
"macosx-aarch64" => Ok(Self::MacOsAarch64),
"windows-amd64" => Ok(Self::WindowsAmd64),
"android-aarch64" => Ok(Self::AndroidAarch64),
s => Err(format!("unsupported platform {s}")),
}
}
Expand All @@ -57,6 +60,7 @@ pub fn platform() -> Platform {
("macos", "x86_64") => Platform::MacOsAmd64,
("macos", "aarch64") => Platform::MacOsAarch64,
("windows", "x86_64") => Platform::WindowsAmd64,
("android", "aarch64") => Platform::AndroidAarch64,
_ => Platform::Unsupported,
}
}
Expand Down Expand Up @@ -94,4 +98,10 @@ mod tests {
fn get_platform() {
assert_eq!(platform(), Platform::WindowsAmd64);
}

#[test]
#[cfg(all(target_os = "android", target_arch = "aarch64"))]
fn get_platform() {
assert_eq!(platform(), Platform::AndroidAarch64);
}
}
28 changes: 28 additions & 0 deletions crates/svm-rs/src/releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ static MACOS_AARCH64_URL_PREFIX: &str =
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/5a404a4839fdde4a6093aee1b3d75a8dce38f40f/android/aarch64";

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

/// Defines the struct that the JSON-formatted release list can be deserialized into.
///
/// Both the key and value are deserialized into [`semver::Version`].
Expand Down Expand Up @@ -161,6 +169,9 @@ pub fn blocking_all_releases(platform: Platform) -> Result<Releases, SvmError> {
releases.releases.append(&mut native.releases);
Ok(releases)
}
Platform::AndroidAarch64 => {
Ok(reqwest::blocking::get(ANDROID_AARCH64_RELEASES_URL)?.json::<Releases>()?)
}
_ => {
let releases =
reqwest::blocking::get(format!("{SOLC_RELEASES_URL}/{platform}/list.json"))?
Expand Down Expand Up @@ -208,6 +219,10 @@ pub async fn all_releases(platform: Platform) -> Result<Releases, SvmError> {
releases.releases.append(&mut native.releases);
Ok(releases)
}
Platform::AndroidAarch64 => Ok(get(ANDROID_AARCH64_RELEASES_URL)
.await?
.json::<Releases>()
.await?),
_ => {
let releases = get(format!("{SOLC_RELEASES_URL}/{platform}/list.json"))
.await?
Expand Down Expand Up @@ -283,6 +298,19 @@ pub(crate) fn artifact_url(
}
}

if platform == Platform::AndroidAarch64 {
if version.ge(&ANDROID_AARCH64_MIN) {
return Ok(Url::parse(&format!(
"{ANDROID_AARCH64_URL_PREFIX}/{artifact}"
))?);
} else {
return Err(SvmError::UnsupportedVersion(
version.to_string(),
platform.to_string(),
));
}
}

Ok(Url::parse(&format!(
"{SOLC_RELEASES_URL}/{platform}/{artifact}"
))?)
Expand Down

0 comments on commit 433aa1c

Please sign in to comment.