From 996b247e93c107e8ac292281e1fb86c0c38bd67e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 16 Sep 2024 13:52:30 +0200 Subject: [PATCH 1/4] refactor(wasmtime/build.rs): extract package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- examples/wasmtime/build.rs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/examples/wasmtime/build.rs b/examples/wasmtime/build.rs index 7a79c46b2..79fff0116 100644 --- a/examples/wasmtime/build.rs +++ b/examples/wasmtime/build.rs @@ -5,25 +5,18 @@ fn main() -> io::Result<()> { let cargo = env::var_os("CARGO").unwrap(); 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 package = if cfg!(feature = "ci") { + "hello_world" + } else { + "wasm-test" + }; + let status = Command::new(cargo) .arg("build") .arg("-Zunstable-options") .arg("-Zbuild-std=std,panic_abort") .arg("--target=wasm32-wasi") - .arg("--package=hello_world") + .args(["--package", package]) .arg("--release") .arg("--target-dir=target") .arg("--artifact-dir") From df12dcdb424c364f84d827836293d64d8191bc4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 16 Sep 2024 14:00:54 +0200 Subject: [PATCH 2/4] chore(wasmtime): rename `wasm32-wasi` to `wasm32-wasip1` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- .github/workflows/ci.yml | 4 ++-- examples/wasmtime/Makefile | 2 +- examples/wasmtime/build.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 48ca13e54..7d85c07c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: - uses: mkroening/rust-toolchain-toml@main - run: | rustup component add clippy llvm-tools - rustup target add wasm32-wasi + rustup target add wasm32-wasip1 - name: Clippy run: | cargo clippy --all-targets @@ -54,7 +54,7 @@ jobs: - uses: mkroening/rust-toolchain-toml@main - run: | rustup component add llvm-tools - rustup target add wasm32-wasi + rustup target add wasm32-wasip1 - 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 79fff0116..cd863763e 100644 --- a/examples/wasmtime/build.rs +++ b/examples/wasmtime/build.rs @@ -15,7 +15,7 @@ fn main() -> io::Result<()> { .arg("build") .arg("-Zunstable-options") .arg("-Zbuild-std=std,panic_abort") - .arg("--target=wasm32-wasi") + .arg("--target=wasm32-wasip1") .args(["--package", package]) .arg("--release") .arg("--target-dir=target") From 3a82ed6ee52be3fefadc94be29f4a6add876ea7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 16 Sep 2024 13:58:50 +0200 Subject: [PATCH 3/4] fix(wasmtime/build.rs): pin wasm toolchain to `nightly-2024-07-31` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- .github/workflows/ci.yml | 16 +++++++++----- examples/wasmtime/build.rs | 45 ++++++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d85c07c9..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-wasip1 + - 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-wasip1 + - run: rustup component add llvm-tools - name: Check docs run: cargo doc --no-deps --document-private-items diff --git a/examples/wasmtime/build.rs b/examples/wasmtime/build.rs index cd863763e..7183d2d86 100644 --- a/examples/wasmtime/build.rs +++ b/examples/wasmtime/build.rs @@ -1,8 +1,9 @@ +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(); let package = if cfg!(feature = "ci") { @@ -11,7 +12,8 @@ fn main() -> io::Result<()> { "wasm-test" }; - let status = Command::new(cargo) + cargo + .arg("+nightly-2024-07-31") .arg("build") .arg("-Zunstable-options") .arg("-Zbuild-std=std,panic_abort") @@ -20,9 +22,44 @@ fn main() -> io::Result<()> { .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 +} From 5a67a8f75f231553868ee65b635b55cf9aaa22bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 16 Sep 2024 14:33:40 +0200 Subject: [PATCH 4/4] fix(wasmtime/build.rs): don't build `std` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- examples/wasmtime/build.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/wasmtime/build.rs b/examples/wasmtime/build.rs index 7183d2d86..76658686a 100644 --- a/examples/wasmtime/build.rs +++ b/examples/wasmtime/build.rs @@ -16,7 +16,6 @@ fn main() -> io::Result<()> { .arg("+nightly-2024-07-31") .arg("build") .arg("-Zunstable-options") - .arg("-Zbuild-std=std,panic_abort") .arg("--target=wasm32-wasip1") .args(["--package", package]) .arg("--release")