From 1729f540beec604599347964410ce0cab06374c7 Mon Sep 17 00:00:00 2001 From: Jared Baur Date: Sun, 31 May 2026 15:17:12 -0400 Subject: [PATCH] buildRustCrate: prevent pulling in two rustc variants With the addition of `remap-path-prefix` to buildRustCrate, we now can pull in two rustc variants when cross compiling, since the rustc that is string-interpolated for passing the remap flag is not pulled from the proper package-set. Depending on the host platform used, this rustc variant may not even build. In order to only pull in one variant, and to properly mask the rustc used for building with the remap-path-prefix flag, rustc is passed explicitly from pkgsBuildHost. --- .../rust/build-rust-crate/default.nix | 2 -- pkgs/top-level/all-packages.nix | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pkgs/build-support/rust/build-rust-crate/default.nix b/pkgs/build-support/rust/build-rust-crate/default.nix index 0903096ed281..8ba8bcdb1a35 100644 --- a/pkgs/build-support/rust/build-rust-crate/default.nix +++ b/pkgs/build-support/rust/build-rust-crate/default.nix @@ -155,8 +155,6 @@ crate_: lib.makeOverridable ( # The rust compiler to use. - # - # Default: pkgs.rustc { rust ? rustc, # The cargo package to use for getting some metadata. diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index ab5fbbc4ea45..81a5d2c6d34e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -4401,11 +4401,20 @@ with pkgs; ); in callPackage ../build-support/rust/build-rust-crate ( - { } - // lib.optionalAttrs (stdenv.hostPlatform.libc == null) { + lib.optionalAttrs (stdenv.hostPlatform.libc == null) { stdenv = stdenvNoCC; # Some build targets without libc will fail to evaluate with a normal stdenv. } - // lib.optionalAttrs targetAlreadyIncluded { inherit (pkgsBuildBuild) rustc cargo; } # Optimization. + // ( + if targetAlreadyIncluded then + # Optimization + { + inherit (pkgsBuildBuild) rustc cargo; + } + else + { + inherit (pkgsBuildHost) rustc cargo; + } + ) ); buildRustCrateHelpers = callPackage ../build-support/rust/build-rust-crate/helpers.nix { };