about summary refs log tree commit diff
path: root/pkgs/development/compilers/rust
diff options
context:
space:
mode:
authorPaul Lietar <pl2113@ic.ac.uk>2024-01-04 09:43:06 +0000
committerPaul Lietar <pl2113@ic.ac.uk>2024-01-04 10:18:33 +0000
commit8e1e16fdcb3ee87ba1308f0ba045c5a2d29c41b5 (patch)
tree9ba75ba5b7ad556b60ac0f32f8e5075cfef0ff56 /pkgs/development/compilers/rust
parent6ce10ae92e8b3453055c521a17349ee35606b714 (diff)
downloadnixlib-8e1e16fdcb3ee87ba1308f0ba045c5a2d29c41b5.tar
nixlib-8e1e16fdcb3ee87ba1308f0ba045c5a2d29c41b5.tar.gz
nixlib-8e1e16fdcb3ee87ba1308f0ba045c5a2d29c41b5.tar.bz2
nixlib-8e1e16fdcb3ee87ba1308f0ba045c5a2d29c41b5.tar.lz
nixlib-8e1e16fdcb3ee87ba1308f0ba045c5a2d29c41b5.tar.xz
nixlib-8e1e16fdcb3ee87ba1308f0ba045c5a2d29c41b5.tar.zst
nixlib-8e1e16fdcb3ee87ba1308f0ba045c5a2d29c41b5.zip
rustc: Fix building cross-compilers for no_std targets.
When building a cross-compiler, the rustc derivation does some tricks to
only build the standard library and reuse the host's compiler, leading
to much faster build time.

Unfortunately, the way the build system was invoked, it would always
build the `std` crate, whether or not the target supports it. Some
bare-metal targets only support building the `core` and `alloc` crates.

By being more vague about the build command, using `library` instead of
`library/std`, Rust's build system is able to figure out exactly which
crates to build:
https://github.com/rust-lang/rust/blob/1.74.1/src/bootstrap/compile.rs#L370-L412

Oddly enough, the install command still needs to use `library/std`, even
if building just a subset:
https://github.com/rust-lang/rust/blob/1.74.1/src/bootstrap/install.rs#L207

The following command was used to reproduce the original issue. Without
this patch, it leads to a build failure when trying to compile one of
std's dependencies. With the patch it completes succesfully and produces
a working cross-compiler.

  nix build --impure --expr '(import ./. {
    crossSystem = {
      config = "riscv32-none-elf";
      rustc.config = "riscv32imc-unknown-none-elf";
    };
  }).buildPackages.rustc'
Diffstat (limited to 'pkgs/development/compilers/rust')
-rw-r--r--pkgs/development/compilers/rust/rustc.nix2
1 files changed, 1 insertions, 1 deletions
diff --git a/pkgs/development/compilers/rust/rustc.nix b/pkgs/development/compilers/rust/rustc.nix
index 7e365f52ef30..7fe33a4011e5 100644
--- a/pkgs/development/compilers/rust/rustc.nix
+++ b/pkgs/development/compilers/rust/rustc.nix
@@ -159,7 +159,7 @@ in stdenv.mkDerivation (finalAttrs: {
     ln -s ${rustc.unwrapped}/bin/rustc build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-rustc/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/rustc-main
     touch build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-std/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/.libstd.stamp
     touch build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-rustc/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/.librustc.stamp
-    python ./x.py --keep-stage=0 --stage=1 build library/std
+    python ./x.py --keep-stage=0 --stage=1 build library
 
     runHook postBuild
   " else null;