From 174765c52a27b9795bfedb53f51f2ae87b3e993b Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Tue, 18 Jul 2023 18:17:05 +0200 Subject: [PATCH] feat(rust): add support for `wasm32-unknown-unknown` Signed-off-by: Roman Volosatovs --- .github/workflows/build.yml | 8 ++++++++ lib/rust/default.nix | 1 + lib/rust/defaultPkgsFor.nix | 2 +- lib/rust/mkAttrs.nix | 5 +++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8531cfef..019c5812 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,6 +35,10 @@ jobs: package: rust-hello-armv7-unknown-linux-musleabihf test-bin: file ./result/bin/rust-hello + - os: macos-12 + package: rust-hello-wasm32-unknown-unknown + test-bin: nix run --inputs-from . 'nixpkgs#wasmtime' ./result/bin/rust-hello.wasm + - os: macos-12 package: rust-hello-wasm32-wasi test-bin: nix run --inputs-from . 'nixpkgs#wasmtime' ./result/bin/rust-hello.wasm @@ -102,6 +106,10 @@ jobs: test-bin: nix shell --inputs-from . 'nixpkgs#qemu' -c qemu-arm ./result/bin/rust-hello test-oci: docker load < ./result + - os: ubuntu-22.04 + package: rust-hello-wasm32-unknown-unknown + test-bin: nix run --inputs-from . 'nixpkgs#wasmtime' ./result/bin/rust-hello.wasm + - os: ubuntu-22.04 package: rust-hello-wasm32-wasi test-bin: nix run --inputs-from . 'nixpkgs#wasmtime' ./result/bin/rust-hello.wasm diff --git a/lib/rust/default.nix b/lib/rust/default.nix index bd214179..128e93ed 100644 --- a/lib/rust/default.nix +++ b/lib/rust/default.nix @@ -141,6 +141,7 @@ in { targets.aarch64-unknown-linux-gnu = "aarch64-unknown-linux-gnu"; targets.aarch64-unknown-linux-musl = "aarch64-unknown-linux-musl"; targets.armv7-unknown-linux-musleabihf = "armv7-unknown-linux-musleabihf"; + targets.wasm32-unknown-unknown = "wasm32-unknown-unknown"; targets.wasm32-wasi = "wasm32-wasi"; targets.x86_64-apple-darwin = "x86_64-apple-darwin"; targets.x86_64-pc-windows-gnu = "x86_64-pc-windows-gnu"; diff --git a/lib/rust/defaultPkgsFor.nix b/lib/rust/defaultPkgsFor.nix index a558ff49..9d1e0b54 100644 --- a/lib/rust/defaultPkgsFor.nix +++ b/lib/rust/defaultPkgsFor.nix @@ -46,7 +46,7 @@ with self.lib.rust.targets; then pkgs.pkgsCross.gnu64 else if target == x86_64-unknown-linux-musl then pkgs.pkgsCross.musl64 - else if target == wasm32-wasi + else if target == wasm32-unknown-unknown || target == wasm32-wasi then pkgs.pkgsCross.wasi32 else import nixpkgs { diff --git a/lib/rust/mkAttrs.nix b/lib/rust/mkAttrs.nix index fa64fcf7..1f8c535d 100644 --- a/lib/rust/mkAttrs.nix +++ b/lib/rust/mkAttrs.nix @@ -352,6 +352,10 @@ with self.lib.rust.targets; // optionalAttrs final.stdenv.buildPlatform.isDarwin { doCheck = warn "testing not currently supported when cross-compiling for `${target}` on Darwin" false; } + else if target == wasm32-unknown-unknown + then { + doCheck = warn "testing not currently supported when cross-compiling for `${target}`" false; + } else if target == wasm32-wasi then { CARGO_TARGET_WASM32_WASI_RUNNER = "wasmtime --disable-cache"; @@ -416,6 +420,7 @@ with self.lib.rust.targets; default.${aarch64-unknown-linux-gnu} = true; default.${aarch64-unknown-linux-musl} = true; default.${armv7-unknown-linux-musleabihf} = true; + default.${wasm32-unknown-unknown} = true; default.${wasm32-wasi} = true; default.${x86_64-apple-darwin} = prev.stdenv.buildPlatform.isDarwin && prev.stdenv.buildPlatform.isx86_64; default.${x86_64-pc-windows-gnu} = true;