From 92669f8e219037dff5bd1929fd658ed3843f2097 Mon Sep 17 00:00:00 2001 From: Julius Michaelis Date: Thu, 13 Jun 2024 22:44:59 +0900 Subject: [PATCH] rustc: set up sysroot for wasm32-wasi and fix build --- lib/systems/examples.nix | 1 + pkgs/development/compilers/rust/rustc.nix | 4 +++- pkgs/development/libraries/wasilibc/default.nix | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/systems/examples.nix b/lib/systems/examples.nix index 178536efb0091..ba85060d53b48 100644 --- a/lib/systems/examples.nix +++ b/lib/systems/examples.nix @@ -353,6 +353,7 @@ rec { wasi32 = { config = "wasm32-unknown-wasi"; + rustc.config = "wasm32-wasip1"; useLLVM = true; }; diff --git a/pkgs/development/compilers/rust/rustc.nix b/pkgs/development/compilers/rust/rustc.nix index a68e117658fad..656038da4e80b 100644 --- a/pkgs/development/compilers/rust/rustc.nix +++ b/pkgs/development/compilers/rust/rustc.nix @@ -146,7 +146,7 @@ in stdenv.mkDerivation (finalAttrs: { # Since fastCross only builds std, it doesn't make sense (and # doesn't work) to build a linker. "--disable-llvm-bitcode-linker" - ] ++ optionals (stdenv.isLinux && !stdenv.targetPlatform.isRedox) [ + ] ++ optionals (stdenv.isLinux && !stdenv.targetPlatform.isRedox && !stdenv.targetPlatform.isWasi) [ "--enable-profiler" # build libprofiler_builtins ] ++ optionals stdenv.buildPlatform.isMusl [ "${setBuild}.musl-root=${pkgsBuildBuild.targetPackages.stdenv.cc.libc}" @@ -154,6 +154,8 @@ in stdenv.mkDerivation (finalAttrs: { "${setHost}.musl-root=${pkgsBuildHost.targetPackages.stdenv.cc.libc}" ] ++ optionals stdenv.targetPlatform.isMusl [ "${setTarget}.musl-root=${pkgsBuildTarget.targetPackages.stdenv.cc.libc}" + ] ++ optionals stdenv.targetPlatform.isWasi [ + "${setTarget}.wasi-root=${pkgsBuildTarget.targetPackages.stdenv.cc.libc}" ] ++ optionals stdenv.targetPlatform.rust.isNoStdTarget [ "--disable-docs" ] ++ optionals (stdenv.isDarwin && stdenv.isx86_64) [ diff --git a/pkgs/development/libraries/wasilibc/default.nix b/pkgs/development/libraries/wasilibc/default.nix index c0714a78556a3..d32bd668ff1ef 100644 --- a/pkgs/development/libraries/wasilibc/default.nix +++ b/pkgs/development/libraries/wasilibc/default.nix @@ -51,6 +51,12 @@ stdenv.mkDerivation { preFixup = '' ln -s $share/share/undefined-symbols.txt $out/lib/wasi.imports + # rustc build expects lib at the path where a make install would put them without the SYSROOT_* overrides + TARGET_TRIPLE=wasm32-wasi + test -d build/$TARGET_TRIPLE # target triple might change if this is adapted to build p2 or threads, make sure the following doesn't break + ln -s $out/lib/ $out/lib/$TARGET_TRIPLE + ln -s $dev/include $dev/include/$TARGET_TRIPLE + ln -s $share/share $share/share/$TARGET_TRIPLE ''; passthru.tests = {