diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 48ca13e54..d2625f736 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 diff --git a/examples/wasmtime/Makefile b/examples/wasmtime/Makefile index b7d445b00..2eeb70957 100644 --- a/examples/wasmtime/Makefile +++ b/examples/wasmtime/Makefile @@ -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: diff --git a/examples/wasmtime/build.rs b/examples/wasmtime/build.rs index 7a79c46b2..76658686a 100644 --- a/examples/wasmtime/build.rs +++ b/examples/wasmtime/build.rs @@ -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 +}