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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased

### Changed
* **Breaking**: `mkCargoDerivation` now no longer automatically includes the
`remapPathPrefixHook` as a nativeBuildInput. Unfortunately, this hook's
implementation will lead to cache invalidation if built on a Nix
implementation outside of NixOS (see the API documentation for more details).
Thus using this hook is now *opt-in*.

## [0.22.0] - 2025-12-26

### Changed
Expand Down
8 changes: 0 additions & 8 deletions checks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,6 @@ onlyDrvs (
asdf = 1;
CARGO_TARGET_DIR = "target/foo";
};
compilesFreshStrip = self.compilesFresh "simple" (myLib.buildPackage) {
src = ./simple;
dontStrip = true;
};
compilesFreshWorkspace =
self.compilesFresh
{
Expand Down Expand Up @@ -674,10 +670,6 @@ onlyDrvs (
src = ./simple;
CARGO_PROFILE = "";
};
simpleNoStrip = myLib.buildPackage {
src = ./simple;
dontStrip = true;
};
simpleOnlyTests = myLib.buildPackage {
src = myLib.cleanCargoSource ./simple-only-tests;
};
Expand Down
19 changes: 11 additions & 8 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ to influence its behavior.
* `checkPhaseCargoCommand`: A command to run during the derivation's check
phase. Pre and post check hooks will automatically be run.
- Default value: `"${cargoTestCommand} ${cargoExtraArgs}"`
* `noCompressDebugSectionsSet`: Controls whether (DWARF) debug sections are
compressed via the `remapPathPrefixHook`.
- Default value: `''` if the `stdenv.hostPlatform` uses ELF as the execution
format, `'1'` otherwise.
* `doCheck`: whether the derivation's check phase should be run
- Default value: `true`
* `dummySrc`: the "dummy" source to use when building this derivation.
Expand Down Expand Up @@ -1262,7 +1258,6 @@ input to any other `nativeBuildInputs` specified by the caller:
* `configureCargoVendoredDepsHook`
* `inheritCargoArtifactsHook`
* `installCargoArtifactsHook`
* `remapPathPrefixHook`
* `replaceCargoLockHook`
* `rustc`
* `rsync`
Expand Down Expand Up @@ -1938,9 +1933,17 @@ a temporary location defined by `$postBuildInstallFromCargoBuildLogOut`

**Required nativeBuildInputs**: assumes `cargo` is available on the `$PATH`

### `craneLib.remapSourcePathPrefixHook`

> Note: this hook is not supported when building on Darwin and will do nothing
### `craneLib.remapPathPrefixHook`

> Note: this hook's implementation relies on the derivation source path being
> mounted on the same location between the `buildDepsOnly` and the "real" build.
> On NixOS, this happens to be something like `/build/${drv.src.name}`, but
> *outside* of NixOS (e.g. Nix installations on Darwin or any other Linux
> distro, including things like GitHub Actions installs) this path will look
> something like `/nix/var/nix/builds/${drv.name}.drv`, where the derivation's
> name *does differ* on the `buildDepsOnly` build. Because of this, cargo will
> observe a change in `CARGO_BUILD_RUSTFLAGS` and result in external
> (dependency) crates being recompiled from scratch!

Defines `configureRustcRemapPathPrefix()` which can be used to set up a source
map using the [`--remap-path-prefix`] option. The output of the derivation gains
Expand Down
7 changes: 0 additions & 7 deletions lib/mkCargoDerivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
lib,
mkCrossToolchainEnv,
pkgs,
remapPathPrefixHook,
replaceCargoLockHook,
rsync,
rustc,
Expand Down Expand Up @@ -100,11 +99,6 @@ chosenStdenv.mkDerivation (
# access. Directory structure should basically follow the output of `cargo vendor`.
cargoVendorDir = args.cargoVendorDir or (vendorCargoDeps args);

# compressing debug sections is only supported on elf formats (i.e. not darwin)
noCompressDebugSectionsSet =
args.noCompressDebugSectionsSet
or (lib.optionalString (chosenStdenv.hostPlatform.parsed.kernel.execFormat.name != "elf") "1");

nativeBuildInputs =
(args.nativeBuildInputs or [ ])
++ (crossEnv.nativeBuildInputs or [ ])
Expand All @@ -115,7 +109,6 @@ chosenStdenv.mkDerivation (
configureCargoVendoredDepsHook
inheritCargoArtifactsHook
installCargoArtifactsHook
remapPathPrefixHook
replaceCargoLockHook
rsync
rustc
Expand Down
18 changes: 0 additions & 18 deletions lib/setupHooks/remapPathPrefixHook.nix
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
{
lib,
makeSetupHook,
stdenv,
}:
makeSetupHook {
name = "remapPathPrefixHook";
substitutions = {
storeDir = builtins.storeDir;

# Unfortunately, we cannot support automatic path remapping on Darwin. The remap paths option
# requires absolute paths (since rustc will basically do a blind substitution). On Linux builds,
# each derivation is chrooted to `/build/{name-of-src}` which ends up being the same string for
# both the real and the deps-only derivations. On Darwin, however, this ends up being
# `/nix/var/nix/builds/{name-of-derivation}` which *is* different between the main and deps-only
# derivations. Since this value ends up in CARGO_BUILD_RUSTFLAGS, it effectively will lead to
# cache invalidation when the real derivation runs if the values differ.
#
# Moreover, we can't "just" replace the bytes ourselves since there's no guarantee that the
# original build path is the same length as the un-neutered store path. Thus we'll noop this for
# now on Darwin builders and leave it up to the caller to handle path remap if needed...
isDarwin = lib.optionalString stdenv.buildPlatform.isDarwin /* bash */ ''
echo 'automatic path remapping not supported on Darwin'
return 0
'';
};
} ./remapPathPrefixHook.sh
2 changes: 0 additions & 2 deletions lib/setupHooks/remapPathPrefixHook.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
configureRustcRemapPathPrefix() {
@isDarwin@

local remapTo="${1:-${src:?not defined}}"
local remapFrom="${2:-$(pwd)}"
local doNeuter="${3:-neuter}"
Expand Down