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.

(cherry picked from commit 1729f540be)
This commit is contained in:
Jared Baur 2026-05-31 15:17:12 -04:00 committed by github-actions[bot]
commit 18ff143758
2 changed files with 12 additions and 5 deletions

View file

@ -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.

View file

@ -4365,11 +4365,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 { };