Skip to content

Commit f1a8c74

Browse files
authored
remapPathPrefixHook: disable automatic path remapping on Darwin builders (#950)
1 parent 7d8ec2c commit f1a8c74

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99
### Changed
1010
* **Breaking**: dropped compatibility for Nix versions below 2.31.2
1111
* **Breaking**: dropped compatibility for nixpkgs-25.05
12+
* `remapPathPrefixHook` is now do nothing when building on Darwin since the
13+
current implementation results in validating build caches due to Nix behavior
14+
differences between Linux and Darwin.
1215

1316
### Fixed
1417
* `mkCargoDerivation` will now set `noCompressDebugSectionsSet` to disable

docs/API.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,6 +1940,8 @@ a temporary location defined by `$postBuildInstallFromCargoBuildLogOut`
19401940

19411941
### `craneLib.remapSourcePathPrefixHook`
19421942

1943+
> Note: this hook is not supported when building on Darwin and will do nothing
1944+
19431945
Defines `configureRustcRemapPathPrefix()` which can be used to set up a source
19441946
map using the [`--remap-path-prefix`] option. The output of the derivation gains
19451947
a dependency on the source code stored within the Nix store, but in return
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
{
2+
lib,
23
makeSetupHook,
4+
stdenv,
35
}:
46
makeSetupHook {
57
name = "remapPathPrefixHook";
68
substitutions = {
79
storeDir = builtins.storeDir;
10+
11+
# Unfortunately, we cannot support automatic path remapping on Darwin. The remap paths option
12+
# requires absolute paths (since rustc will basically do a blind substitution). On Linux builds,
13+
# each derivation is chrooted to `/build/{name-of-src}` which ends up being the same string for
14+
# both the real and the deps-only derivations. On Darwin, however, this ends up being
15+
# `/nix/var/nix/builds/{name-of-derivation}` which *is* different between the main and deps-only
16+
# derivations. Since this value ends up in CARGO_BUILD_RUSTFLAGS, it effectively will lead to
17+
# cache invalidation when the real derivation runs if the values differ.
18+
#
19+
# Moreover, we can't "just" replace the bytes ourselves since there's no guarantee that the
20+
# original build path is the same length as the un-neutered store path. Thus we'll noop this for
21+
# now on Darwin builders and leave it up to the caller to handle path remap if needed...
22+
isDarwin = lib.optionalString stdenv.buildPlatform.isDarwin /* bash */ ''
23+
echo 'automatic path remapping not supported on Darwin'
24+
return 0
25+
'';
826
};
927
} ./remapPathPrefixHook.sh

lib/setupHooks/remapPathPrefixHook.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
configureRustcRemapPathPrefix() {
2+
@isDarwin@
3+
24
local remapTo="${1:-${src:?not defined}}"
35
local remapFrom="${2:-$(pwd)}"
46
local doNeuter="${3:-neuter}"

0 commit comments

Comments
 (0)