Skip to content

Commit

Permalink
Merge pull request #621 from hermit-os/wasmtime-compat
Browse files Browse the repository at this point in the history
fix(wasmtime/build.rs): pin wasm toolchain to `nightly-2024-07-31`
  • Loading branch information
mkroening authored Sep 16, 2024
2 parents 3f153b3 + 5a67a8f commit 3493848
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 27 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ jobs:
- uses: dtolnay/rust-toolchain@nightly
with:
components: rust-src
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-07-31
targets: wasm32-wasip1
- uses: mkroening/rust-toolchain-toml@main
- run: |
rustup component add clippy llvm-tools
rustup target add wasm32-wasi
- run: rustup component add clippy llvm-tools
- name: Clippy
run: |
cargo clippy --all-targets
Expand Down Expand Up @@ -51,10 +53,12 @@ jobs:
- uses: dtolnay/rust-toolchain@nightly
with:
components: rust-src
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-07-31
targets: wasm32-wasip1
- uses: mkroening/rust-toolchain-toml@main
- run: |
rustup component add llvm-tools
rustup target add wasm32-wasi
- run: rustup component add llvm-tools
- name: Check docs
run: cargo doc --no-deps --document-private-items

Expand Down
2 changes: 1 addition & 1 deletion examples/wasmtime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ target/x86_64-unknown-hermit/release/wasmi_demo: $(SOURCE_FILES) Cargo.* wasm/fi
--release

wasm/fib.wasm:
cd examples; cd fib; cargo build --target wasm32-wasi --release; cp target/wasm32-wasi/release/fib.wasm ../../wasm
cd examples; cd fib; cargo build --target wasm32-wasip1 --release; cp target/wasm32-wasip1/release/fib.wasm ../../wasm

.PHONY: clean
clean:
Expand Down
69 changes: 49 additions & 20 deletions examples/wasmtime/build.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,64 @@
use std::path::PathBuf;
use std::process::Command;
use std::{env, io};

fn main() -> io::Result<()> {
let cargo = env::var_os("CARGO").unwrap();
let mut cargo = cargo();
let out_dir = env::var_os("OUT_DIR").unwrap();

#[cfg(not(feature = "ci"))]
let status = Command::new(cargo)
.arg("build")
.arg("-Zunstable-options")
.arg("-Zbuild-std=std,panic_abort")
.arg("--target=wasm32-wasi")
.arg("--package=wasm-test")
.arg("--release")
.arg("--target-dir=target")
.arg("--artifact-dir")
.arg(&out_dir)
.status()?;
#[cfg(feature = "ci")]
let status = Command::new(cargo)
let package = if cfg!(feature = "ci") {
"hello_world"
} else {
"wasm-test"
};

cargo
.arg("+nightly-2024-07-31")
.arg("build")
.arg("-Zunstable-options")
.arg("-Zbuild-std=std,panic_abort")
.arg("--target=wasm32-wasi")
.arg("--package=hello_world")
.arg("--target=wasm32-wasip1")
.args(["--package", package])
.arg("--release")
.arg("--target-dir=target")
.arg("--artifact-dir")
.arg(&out_dir)
.status()?;
.arg(&out_dir);
let status = cargo.status()?;
assert!(status.success());

Ok(())
}

pub fn cargo() -> Command {
sanitize("cargo")
}

fn sanitize(cmd: &str) -> Command {
let cmd = {
let exe = format!("{cmd}{}", env::consts::EXE_SUFFIX);
// On windows, the userspace toolchain ends up in front of the rustup proxy in $PATH.
// To reach the rustup proxy nonetheless, we explicitly query $CARGO_HOME.
let mut cargo_home = PathBuf::from(env::var_os("CARGO_HOME").unwrap());
cargo_home.push("bin");
cargo_home.push(&exe);
if cargo_home.exists() {
cargo_home
} else {
PathBuf::from(exe)
}
};

let mut cmd = Command::new(cmd);

// Remove rust-toolchain-specific environment variables from kernel cargo
cmd.env_remove("LD_LIBRARY_PATH");
env::vars()
.filter(|(key, _value)| {
key.starts_with("CARGO") && !key.starts_with("CARGO_HOME")
|| key.starts_with("RUST") && !key.starts_with("RUSTUP_HOME")
})
.for_each(|(key, _value)| {
cmd.env_remove(&key);
});

cmd
}

0 comments on commit 3493848

Please sign in to comment.