diff --git a/pkgs/remapSourcePathPrefixHook.sh b/pkgs/remapSourcePathPrefixHook.sh index 98eb677..82576d5 100644 --- a/pkgs/remapSourcePathPrefixHook.sh +++ b/pkgs/remapSourcePathPrefixHook.sh @@ -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 `-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 diff --git a/tests/default.nix b/tests/default.nix index a63afad..a3b76b2 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -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