Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
new: Improve OS/arch detection. (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Jul 13, 2023
1 parent ae660cd commit 7e51481
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ crate-type = ['cdylib']

[dependencies]
extism-pdk = "0.3.3"
proto_pdk = "0.2.2"
proto_pdk = "0.2.3"
serde = "1.0.167"

[dev-dependencies]
proto_core = "0.12.2"
proto_pdk_test_utils = "0.1.2"
proto_pdk_test_utils = "0.1.3"
starbase_sandbox = "0.1.5"
tokio = "1.29.1"
23 changes: 11 additions & 12 deletions src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,27 @@ pub fn register_tool(Json(_): Json<ToolMetadataInput>) -> FnResult<Json<ToolMeta
pub fn download_prebuilt(
Json(input): Json<DownloadPrebuiltInput>,
) -> FnResult<Json<DownloadPrebuiltOutput>> {
check_supported_os_and_arch(
NAME,
&input.env,
permutations! [
HostOS::Linux => [HostArch::X64, HostArch::Arm64],
HostOS::MacOS => [HostArch::X64, HostArch::Arm64],
],
)?;

let version = input.env.version;

let arch = match input.env.arch {
HostArch::Arm64 => "aarch64",
HostArch::X64 => "x64",
other => {
return Err(PluginError::UnsupportedArchitecture {
tool: NAME.into(),
arch: other.to_string(),
})?;
}
_ => unreachable!(),
};

let prefix = match input.env.os {
HostOS::Linux => format!("bun-linux-{arch}"),
HostOS::MacOS => format!("bun-darwin-{arch}"),
other => {
return Err(PluginError::UnsupportedPlatform {
tool: NAME.into(),
platform: other.to_string(),
})?;
}
_ => unreachable!(),
};

let filename = format!("{prefix}.zip");
Expand Down
2 changes: 1 addition & 1 deletion tests/download_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn supports_macos_x64() {
}

#[test]
#[should_panic(expected = "Unable to install Bun, unsupported platform windows.")]
#[should_panic(expected = "Unable to install Bun, unsupported OS windows.")]
fn doesnt_support_windows() {
let sandbox = create_empty_sandbox();
let plugin = create_plugin("bun-test", sandbox.path());
Expand Down

0 comments on commit 7e51481

Please sign in to comment.