Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions pkgs/build-support/rust/build-rust-package/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -23,6 +33,7 @@ lib.extendMkDerivation {
"cargoUpdateHook"
"cargoLock"
"useFetchCargoVendor"
"RUSTFLAGS"
];

extendDrvArgs =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkgs/build-support/rust/hooks/cargo-setup-hook.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading