Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* `mkDummySrc` can now pass the `cleanCargoTomlFilter` argument to `cleanCargoToml`
* `craneLib.filters` exposes `cargoTomlAggressive`, `cargoTomlConservative`, and
`cargoTomlDefault` for composition of custom filters for `cleanCargoToml`
* `downloadCargoPackageFromGit` now uses `cargo package -l` for generating the file
list, resulting in more accurate include/exclude rule interpretation. This fixes
builds in some dependencies, notably `aws-lc-rs` from git.

## [0.23.0] - 2026-01-13

Expand Down
26 changes: 11 additions & 15 deletions lib/downloadCargoPackageFromGit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ stdenv.mkDerivation {
cargo metadata --format-version 1 --no-deps --manifest-path "$cargoToml" |
jq -r '.packages[] | select(.manifest_path == "'"$cargoToml"'") | "\(.name)-\(.version)"'
)
local crateName=$(
cargo metadata --format-version 1 --no-deps --manifest-path "$cargoToml" |
jq -r '.packages[] | select(.manifest_path == "'"$cargoToml"'") | .name'
)

if [ -n "$crate" ]; then
if [[ -n "''${existing_crates["$crate"]}" ]]; then
Expand Down Expand Up @@ -105,21 +109,13 @@ stdenv.mkDerivation {
(
cd "$(dirname "$cargoToml")"

# NB: we tell ripgrep to ignore any ignore files (via -uuu) since we are manually
# applying the includes/excludes defined in Cargo.toml. Since this is a fresh git
# checkout, it will not include any files listed in .gitignore anyway!
crateFiles="$(rg -uuu --follow --files --ignore-file=<(
remarshal -i "$cargoToml" -if toml -of json \
| jq -r '.package | if has("include") then .include | map("!\(.)" | sub("^!!"; "")) else .exclude // [] end| .[]?'
echo '!/Cargo.toml'
# Always excluded
echo '/target'
# Always exclude subpackages (directories with `Cargo.toml`)
# mindepth 2 because ./Cargo.toml counts as a depth of 1
find ./ -mindepth 2 -name Cargo.toml -print0 \
| xargs -0 -r -n1 dirname \
| sed 's|^\.||'
) | sort)"
# Use `cargo package` to interpret the include/exclude rules
#
# XXX: throws errors on some crates, don't know why, is it the build-scripts?
#
# NB: `Cargo.lock` is excluded if it doesn't exist, because previous implementation
# handled it that way. `cargo package` has other goals than us, maybe?
crateFiles="$(cargo package --offline --exclude-lockfile -l -p "$crateName" | grep -v -e "^Cargo.toml.orig" $(if [[ ! -f Cargo.lock ]]; then echo "-e^Cargo.lock"; fi) | sort)"

(
cd "$dest"
Expand Down