diff --git a/pkgs/build-support/rust/build-rust-package/default.nix b/pkgs/build-support/rust/build-rust-package/default.nix index 7efbc8a9ea36d..7ad39a58935c7 100644 --- a/pkgs/build-support/rust/build-rust-package/default.nix +++ b/pkgs/build-support/rust/build-rust-package/default.nix @@ -15,6 +15,16 @@ windows, }: +let + interpolateString = + s: + if lib.isList s then + lib.concatMapStringsSep " " (s: "${s}") (lib.filter (s: s != null) s) + else if s == null then + "" + else + "${s}"; +in lib.extendMkDerivation { constructDrv = stdenv.mkDerivation; @@ -23,6 +33,7 @@ lib.extendMkDerivation { "cargoUpdateHook" "cargoLock" "useFetchCargoVendor" + "RUSTFLAGS" ]; extendDrvArgs = @@ -77,11 +88,19 @@ lib.extendMkDerivation { assert lib.warnIf (args ? useFetchCargoVendor) "buildRustPackage: `useFetchCargoVendor` is non‐optional and enabled by default as of 25.05, remove it" true; + { + env = { + PKG_CONFIG_ALLOW_CROSS = if stdenv.buildPlatform != stdenv.hostPlatform then 1 else 0; + RUST_LOG = logLevel; + RUSTFLAGS = + lib.optionalString ( + stdenv.hostPlatform.isDarwin && buildType == "debug" + ) "-C split-debuginfo=packed " + # Workaround the existing RUSTFLAGS specified as a list. + + interpolateString (args.RUSTFLAGS or ""); + } + // args.env or { }; - lib.optionalAttrs (stdenv.hostPlatform.isDarwin && buildType == "debug") { - RUSTFLAGS = "-C split-debuginfo=packed " + (args.RUSTFLAGS or ""); - } - // { cargoDeps = if cargoVendorDir != null then null @@ -143,15 +162,6 @@ lib.extendMkDerivation { patches = cargoPatches ++ patches; - PKG_CONFIG_ALLOW_CROSS = if stdenv.buildPlatform != stdenv.hostPlatform then 1 else 0; - - postUnpack = '' - eval "$cargoDepsHook" - - export RUST_LOG=${logLevel} - '' - + (args.postUnpack or ""); - configurePhase = args.configurePhase or '' runHook preConfigure diff --git a/pkgs/build-support/rust/hooks/cargo-setup-hook.sh b/pkgs/build-support/rust/hooks/cargo-setup-hook.sh index 1c779a6541d8a..4ba6760a1a237 100644 --- a/pkgs/build-support/rust/hooks/cargo-setup-hook.sh +++ b/pkgs/build-support/rust/hooks/cargo-setup-hook.sh @@ -1,6 +1,8 @@ cargoSetupPostUnpackHook() { echo "Executing cargoSetupPostUnpackHook" + eval "${cargoDepsHook-}" + # Some cargo builds include build hooks that modify their own vendor # dependencies. This copies the vendor directory into the build tree and makes # it writable. If we're using a tarball, the unpackFile hook already handles