From 06871d5c5f78b0ae846c5758702531b4cabfab9b Mon Sep 17 00:00:00 2001 From: oxalica Date: Fri, 10 Jan 2025 23:15:59 -0500 Subject: [PATCH] {rust-bin,example}: remove WASI target workaround and fix example The un-versioned `wasm32-wasi` target is removed in favor of `wasm32-wasip?` since Rust 1.84. Examples are updated. The nixpkgs patch for WASI target name remapping is merged in 24.11. We can also safely remove the workaround. --- default.nix | 1 - examples/cross-wasi/Makefile | 2 +- examples/cross-wasi/shell.nix | 14 ++++++++++++-- flake.nix | 1 - lib/rust-bin.nix | 15 ++++----------- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/default.nix b/default.nix index edcdbd7e..9b0c117f 100644 --- a/default.nix +++ b/default.nix @@ -27,7 +27,6 @@ in { distRoot = import ./lib/dist-root.nix; } // import ./lib/rust-bin.nix { inherit lib manifests; - inherit (final.rust) toRustTarget; inherit (rust-bin) nightly; pkgs = final; }; diff --git a/examples/cross-wasi/Makefile b/examples/cross-wasi/Makefile index bb1a287c..a461e6c3 100644 --- a/examples/cross-wasi/Makefile +++ b/examples/cross-wasi/Makefile @@ -1,6 +1,6 @@ # This Makefile is expected to be run inside nix-shell. -CARGO_FLAGS := --target wasm32-wasi +CARGO_FLAGS := --target wasm32-wasip1 .PHONY: all all: Cargo.toml Cargo.lock src/main.rs diff --git a/examples/cross-wasi/shell.nix b/examples/cross-wasi/shell.nix index 69a7a9f2..d2e59234 100644 --- a/examples/cross-wasi/shell.nix +++ b/examples/cross-wasi/shell.nix @@ -2,6 +2,15 @@ (import { crossSystem = { config = "wasm32-wasi"; + + # NB. Rust use a different naming convention for target platforms and + # differentiates multiple version of WASI specification by using "wasip?". + # If this line is omitted, `wasm32-wasip1` (WASI 0.1) is assumed. + # See: + # + # If you changed this, also update `CARGO_TARGET_*_RUNNER` below. + rust.rustcTarget = "wasm32-wasip1"; + # Nixpkgs currently only supports LLVM lld linker for wasm32-wasi. useLLVM = true; }; @@ -16,7 +25,8 @@ mkShellNoCC { # This is optional for wasm32-like targets, since rustc will automatically use # the bundled `lld` for linking. - # CARGO_TARGET_WASM32_WASI_LINKER = "${stdenv.cc.targetPrefix}cc"; - CARGO_TARGET_WASM32_WASI_RUNNER = "wasmtime"; + # CARGO_TARGET_WASM32_WASIP1_LINKER = + + CARGO_TARGET_WASM32_WASIP1_RUNNER = "wasmtime run"; }) {} diff --git a/flake.nix b/flake.nix index 3b3ea13b..5dffb3bb 100644 --- a/flake.nix +++ b/flake.nix @@ -29,7 +29,6 @@ pkgs: lib.fix (rust-bin: import ./lib/rust-bin.nix { inherit lib pkgs; - inherit (pkgs.rust) toRustTarget; inherit (rust-bin) nightly; manifests = mkManifests distRoot; }); diff --git a/lib/rust-bin.nix b/lib/rust-bin.nix index 2d52c2c5..8f1da52a 100644 --- a/lib/rust-bin.nix +++ b/lib/rust-bin.nix @@ -3,7 +3,6 @@ { lib, pkgs, - toRustTarget, manifests, nightly, }: @@ -23,21 +22,15 @@ let (filter (name: set.${name} == null) (attrNames set)); - # FIXME: https://github.com/NixOS/nixpkgs/pull/146274 - toRustTarget' = platform: - if platform.isWasi then - "${platform.parsed.cpu.name}-wasi" - else - platform.rust.rustcTarget or (toRustTarget platform); + toRustTarget = platform: platform.rust.rustcTarget; # The platform where `rustc` is running. - rustHostPlatform = toRustTarget' stdenv.hostPlatform; + rustHostPlatform = toRustTarget stdenv.hostPlatform; # The platform of binary which `rustc` produces. - rustTargetPlatform = toRustTarget' stdenv.targetPlatform; + rustTargetPlatform = toRustTarget stdenv.targetPlatform; mkComponentSet = callPackage ./mk-component-set.nix { - inherit removeNulls; - toRustTarget = toRustTarget'; + inherit removeNulls toRustTarget; }; mkAggregated = callPackage ./mk-aggregated.nix {};