Skip to content

Commit

Permalink
buildDepsOnly: prefer dummySrc when specified for fallback values (i…
Browse files Browse the repository at this point in the history
  • Loading branch information
ipetkov authored and ulucs committed Dec 3, 2024
1 parent d590477 commit 6f3445b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed
* `removeReferencesToVendoredSources` now deduplicates any found references to
avoid pathological memory usage before removing them.
* `buildDepsOnly` will calculate fallback `pname`/`version`/`cargoVendorDir`
attributes using `dummySrc` if it was specified (rather than attempting to use
`src`)

## [0.19.3] - 2024-11-18
A republish of 0.19.2 which was incorrectly tagged.
Expand Down
14 changes: 14 additions & 0 deletions checks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,20 @@ in
touch $out
'';

customDummy = myLib.buildDepsOnly {
dummySrc = pkgs.stdenv.mkDerivation {
pname = "custom-dummy";
version = "0.0.0";
src = myLib.cleanCargoSource ./simple;
postInstall = ''
mkdir -p $out
cp -r . $out
echo 'fn main() {}' > $out/src/main.rs
find $out
'';
};
};

# https://github.com/ipetkov/crane/pull/234
nonJsonCargoBuildLog =
let
Expand Down
11 changes: 8 additions & 3 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ to influence its behavior.
be consumed without network access. Directory structure should basically
follow the output of `cargo vendor`.
- Default value: the result of `vendorCargoDeps` after applying the arguments
set (with the respective default values)
set (with the respective default values). Note if `dummySrc` is specified,
it will be used as the `src` passed into `vendorCargoDeps`
* `checkPhaseCargoCommand`: A command to run during the derivation's check
phase. Pre and post check hooks will automatically be run.
- Default value: `"${cargoTestCommand} ${cargoExtraArgs}"`
Expand All @@ -140,9 +141,13 @@ to influence its behavior.
Automatically derived if not passed in
- Default value: `mkDummySrc args.src`
* `pname`: package name of the derivation
- Default value: inherited from calling `crateNameFromCargoToml`
- Default value: inherited from calling `crateNameFromCargoToml`. Note if
`dummySrc` is specified, it will be used as the `src` passed into
`crateNameFromCargoToml`
* `version`: version of the derivation
- Default value: inherited from calling `crateNameFromCargoToml`
- Default value: inherited from calling `crateNameFromCargoToml`. Note if
`dummySrc` is specified, it will be used as the `src` passed into
`crateNameFromCargoToml`

#### Remove attributes
The following attributes will be removed before being lowered to
Expand Down
15 changes: 13 additions & 2 deletions lib/buildDepsOnly.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
, ...
}@args:
let
crateName = crateNameFromCargoToml args;
cleanedArgs = builtins.removeAttrs args [
"cargoBuildCommand"
"cargoCheckCommand"
Expand All @@ -39,6 +38,18 @@ let
args.dummySrc
else
mkDummySrc args;

# If dummySrc is define *in args*, use it as the `src` for fallback calculations,
# but DO NOT use the computed `dummySrc` above as that's likely to trigger IFD
# (in case anyone is trying to avoid that). Dummifiying the sources should preserve
# the name/version of the Cargo.toml, as well as the entirety of Cargo.lock,
# so it shouldn't matter anyway
argsMaybeDummySrcOverride =
if args ? dummySrc
then args // { src = args.dummySrc; }
else args;

crateName = crateNameFromCargoToml argsMaybeDummySrcOverride;
in
mkCargoDerivation (cleanedArgs // {
inherit doCheck;
Expand All @@ -49,7 +60,7 @@ mkCargoDerivation (cleanedArgs // {
version = args.version or crateName.version;

cargoArtifacts = null;
cargoVendorDir = args.cargoVendorDir or (vendorCargoDeps args);
cargoVendorDir = args.cargoVendorDir or (vendorCargoDeps argsMaybeDummySrcOverride);

env = (args.env or { }) // {
# Export a marker variable in case any scripts or hooks want to customize
Expand Down

0 comments on commit 6f3445b

Please sign in to comment.