Skip to content

Commit

Permalink
rustc: set up sysroot for wasm32-wasi and fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaesar committed Jul 14, 2024
1 parent 12a3f8b commit 92669f8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/systems/examples.nix
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ rec {

wasi32 = {
config = "wasm32-unknown-wasi";
rustc.config = "wasm32-wasip1";
useLLVM = true;
};

Expand Down
4 changes: 3 additions & 1 deletion pkgs/development/compilers/rust/rustc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,16 @@ 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}"
] ++ optionals stdenv.hostPlatform.isMusl [
"${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) [
Expand Down
6 changes: 6 additions & 0 deletions pkgs/development/libraries/wasilibc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 92669f8

Please sign in to comment.