Skip to content

Commit 0d96be1

Browse files
ShamrockLeegepbird
authored andcommitted
rustPlatform.buildRustPackage: Pass env.RUSTFLAGS only when specified or needed
Prevent shadowing RUSTFLAGS-like variables with lower priorities, such as mint-mod-mamanager's CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUSTFLAGS Co-authored-by: Gergő Gutyina <gutyina.gergo.2@gmail.com>
1 parent 1306659 commit 0d96be1

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

pkgs/build-support/rust/build-rust-package/default.nix

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,20 @@ lib.extendMkDerivation {
8989
"buildRustPackage: `useFetchCargoVendor` is non‐optional and enabled by default as of 25.05, remove it"
9090
true;
9191
{
92-
env = {
93-
PKG_CONFIG_ALLOW_CROSS = if stdenv.buildPlatform != stdenv.hostPlatform then 1 else 0;
94-
RUST_LOG = logLevel;
95-
RUSTFLAGS =
96-
lib.optionalString (
97-
stdenv.hostPlatform.isDarwin && buildType == "debug"
98-
) "-C split-debuginfo=packed "
99-
# Workaround the existing RUSTFLAGS specified as a list.
100-
+ interpolateString (args.RUSTFLAGS or "");
101-
}
102-
// args.env or { };
92+
env =
93+
let
94+
isDarwinDebug = stdenv.hostPlatform.isDarwin && buildType == "debug";
95+
in
96+
{
97+
PKG_CONFIG_ALLOW_CROSS = if stdenv.buildPlatform != stdenv.hostPlatform then 1 else 0;
98+
RUST_LOG = logLevel;
99+
# Prevent shadowing *_RUSTFLAGS environment variables
100+
${if args ? RUSTFLAGS || isDarwinDebug then "RUSTFLAGS" else null} =
101+
lib.optionalString isDarwinDebug "-C split-debuginfo=packed "
102+
# Workaround the existing RUSTFLAGS specified as a list.
103+
+ interpolateString (args.RUSTFLAGS or "");
104+
}
105+
// args.env or { };
103106

104107
cargoDeps =
105108
if cargoVendorDir != null then

0 commit comments

Comments
 (0)