Skip to content

Commit

Permalink
Pull adapters from crates.io instead of vendoring (#323)
Browse files Browse the repository at this point in the history
Now that Wasmtime has releases to crates.io with the adapter artifacts
use those instead of locally vendored builds to make updates a bit
easier.
  • Loading branch information
alexcrichton authored Jul 23, 2024
1 parent 7cf7368 commit 5063442
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 38 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ bytes = { workspace = true }
which = { workspace = true }
shell-escape = "0.1.5"
tempfile = { workspace = true }
wasi-preview1-component-adapter-provider = "23.0.1"

[dev-dependencies]
assert_cmd = { workspace = true }
Expand Down
Binary file removed adapters/95fee6f/wasi_snapshot_preview1.command.wasm
Binary file not shown.
Binary file removed adapters/95fee6f/wasi_snapshot_preview1.proxy.wasm
Binary file not shown.
Binary file not shown.
7 changes: 2 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use std::{path::Path, process::Command};

const WASI_ADAPTER_VERSION: &str = "95fee6f";

fn main() {
println!("cargo:rerun-if-changed=build.rs");

println!("cargo:rustc-env=WASI_ADAPTER_VERSION={WASI_ADAPTER_VERSION}");
if !commit_info() {
println!(
"cargo:rustc-env=CARGO_VERSION_INFO={} (wasi:{WASI_ADAPTER_VERSION})",
"cargo:rustc-env=CARGO_VERSION_INFO={}",
env!("CARGO_PKG_VERSION"),
);
}
Expand All @@ -34,7 +31,7 @@ fn commit_info() -> bool {
let mut next = || parts.next().unwrap();
println!("cargo:rustc-env=CARGO_GIT_HASH={}", next());
println!(
"cargo:rustc-env=CARGO_VERSION_INFO={} ({} {} wasi:{WASI_ADAPTER_VERSION})",
"cargo:rustc-env=CARGO_VERSION_INFO={} ({} {})",
env!("CARGO_PKG_VERSION"),
next(),
next()
Expand Down
24 changes: 9 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,23 +911,17 @@ fn adapter_bytes(
.warn("ignoring `proxy` setting in `Cargo.toml` for command component")?;
}

Ok(Cow::Borrowed(include_bytes!(concat!(
"../adapters/",
env!("WASI_ADAPTER_VERSION"),
"/wasi_snapshot_preview1.command.wasm"
))))
Ok(Cow::Borrowed(
wasi_preview1_component_adapter_provider::WASI_SNAPSHOT_PREVIEW1_COMMAND_ADAPTER,
))
} else if metadata.section.proxy {
Ok(Cow::Borrowed(include_bytes!(concat!(
"../adapters/",
env!("WASI_ADAPTER_VERSION"),
"/wasi_snapshot_preview1.proxy.wasm"
))))
Ok(Cow::Borrowed(
wasi_preview1_component_adapter_provider::WASI_SNAPSHOT_PREVIEW1_PROXY_ADAPTER,
))
} else {
Ok(Cow::Borrowed(include_bytes!(concat!(
"../adapters/",
env!("WASI_ADAPTER_VERSION"),
"/wasi_snapshot_preview1.reactor.wasm"
))))
Ok(Cow::Borrowed(
wasi_preview1_component_adapter_provider::WASI_SNAPSHOT_PREVIEW1_REACTOR_ADAPTER,
))
}
}

Expand Down
16 changes: 12 additions & 4 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,9 +715,13 @@ fn it_builds_with_adapter() -> Result<()> {
.failure();

let project = Project::new("foo")?;
let adapter_path = "adapter/wasi_snapshot_preview1.wasm";
project.file(
adapter_path,
wasi_preview1_component_adapter_provider::WASI_SNAPSHOT_PREVIEW1_REACTOR_ADAPTER,
)?;
project.update_manifest(|mut doc| {
doc["package"]["metadata"]["component"]["adapter"] =
value(adapter_path().to_str().unwrap());
doc["package"]["metadata"]["component"]["adapter"] = value(adapter_path);
Ok(doc)
})?;

Expand Down Expand Up @@ -894,10 +898,14 @@ fn it_warns_on_proxy_setting_for_command() -> Result<()> {
#[test]
fn it_warns_with_proxy_and_adapter_settings() -> Result<()> {
let project = Project::new("foo")?;
let adapter_path = "adapter/wasi_snapshot_preview1.wasm";
project.file(
adapter_path,
wasi_preview1_component_adapter_provider::WASI_SNAPSHOT_PREVIEW1_REACTOR_ADAPTER,
)?;
project.update_manifest(|mut doc| {
doc["package"]["metadata"]["component"]["proxy"] = value(true);
doc["package"]["metadata"]["component"]["adapter"] =
value(adapter_path().to_str().unwrap());
doc["package"]["metadata"]["component"]["adapter"] = value(adapter_path);
Ok(doc)
})?;

Expand Down
16 changes: 2 additions & 14 deletions tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ pub fn test_signing_key() -> &'static str {
"ecdsa-p256:2CV1EpLaSYEn4In4OAEDAj5O4Hzu8AFAxgHXuG310Ew="
}

pub fn adapter_path() -> PathBuf {
let mut path = std::env::current_exe().unwrap();
path.pop(); // remove test exe name
path.pop(); // remove `deps`
path.pop(); // remove `debug` or `release`
path.pop(); // remove `target`
path.push("adapters");
path.push(env!("WASI_ADAPTER_VERSION"));
path.push("wasi_snapshot_preview1.reactor.wasm");
path
}

pub fn cargo_component(args: &str) -> Command {
let mut exe = std::env::current_exe().unwrap();
exe.pop(); // remove test exe name
Expand Down Expand Up @@ -261,10 +249,10 @@ impl Project {
&self.dir
}

pub fn file<B: AsRef<Path>>(&self, path: B, body: &str) -> Result<&Self> {
pub fn file<B: AsRef<Path>>(&self, path: B, body: impl AsRef<[u8]>) -> Result<&Self> {
let path = self.root().join(path);
fs::create_dir_all(path.parent().unwrap())?;
fs::write(self.root().join(path), body)?;
fs::write(&path, body)?;
Ok(self)
}

Expand Down

0 comments on commit 5063442

Please sign in to comment.