Make remapSourcePathPrefixHook potentially customizable

This commit is contained in:
Ivan Petkov 2021-12-31 18:18:19 -08:00
parent 32ca849598
commit 8d6d973261
No known key found for this signature in database
GPG Key ID: BB6F9EFC065832B6
2 changed files with 26 additions and 22 deletions

View File

@ -1,9 +1,11 @@
remapPathPrefix() {
if [ -z "${cargoVendorDir-}" ]; then
return
fi
local remapArgs="--remap-path-prefix ${cargoVendorDir}=/sources"
# We unfortunately cannot get away with *just* stripping a `/nix/store` prefix
# since nix will still find references to the `<sha>-dirname` floating around
# and decide that the binaries must depend on the source files themselves.
# To get around this we actually have to strip the entire prefix of the vendored
# directory (or provided input).
local prefixToRemap=${1:?prefixToRemap not specified}
local remapArgs="--remap-path-prefix ${prefixToRemap}=/sources"
if [ -n "${RUSTFLAGS}" ]; then
export RUSTFLAGS="${RUSTFLAGS} ${remapArgs}"
@ -18,6 +20,12 @@ remapPathPrefix() {
fi
}
remapPathPrefixToVendoredDir() {
if [ -n "${cargoVendorDir-}" ]; then
remapPathPrefix "${cargoVendorDir}"
fi
}
if [ "1" = "${doRemapSourcePathPrefix-}" ]; then
postConfigureHooks+=(remapPathPrefix)
postConfigureHooks+=(remapPathPrefixToVendoredDir)
fi

View File

@ -17,7 +17,6 @@ pkgs.lib.makeScope myLib.newScope (self:
compilesFresh = callPackage ./compilesFresh.nix { };
compilesFreshSimple = self.compilesFresh ./simple "simple";
compilesFreshOverlappingTargets = self.compilesFresh
./overlapping-targets
(builtins.concatStringsSep "\n" [
@ -29,12 +28,11 @@ pkgs.lib.makeScope myLib.newScope (self:
customCargoTargetDirectory =
let
simple = myLib.buildWithCargo {
simple = self.simple.overrideAttrs (old: {
name = "customCargoTargetDirectory";
doCopyTargetToOutput = false;
src = ./simple;
CARGO_TARGET_DIR = "some/nested/custom-cargo-dir";
};
});
in
pkgs.runCommand "smoke-simple" { } ''
# does it run?
@ -42,18 +40,16 @@ pkgs.lib.makeScope myLib.newScope (self:
touch $out
'';
smokeSimple =
let
simple = myLib.buildWithCargo {
doCopyTargetToOutput = false;
src = ./simple;
};
in
pkgs.runCommand "smoke-simple" { } ''
# does it run?
${simple}/bin/simple
touch $out
'';
simple = myLib.buildWithCargo {
doCopyTargetToOutput = false;
src = ./simple;
};
smokeSimple = pkgs.runCommand "smoke-simple" { } ''
# does it run?
${self.simple}/bin/simple
touch $out
'';
smokeOverlappingTargets =
let