Skip to content

Commit

Permalink
Use checksums for recreating crates.io's directory
Browse files Browse the repository at this point in the history
Closes #138.
  • Loading branch information
Patryk27 committed Jul 26, 2023
1 parent 711ebec commit d9a33d6
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 1 deletion.
32 changes: 31 additions & 1 deletion build.nix
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,37 @@ let
''
mkdir -p $out
tar -xzf ${crate} -C $out
echo '{"package":"${sha256}","files":{}}' > $out/${name}-${version}/.cargo-checksum.json
# Most filesystems have a maximum filename length of 255
dest="$out/$(echo "${name}-${version}-${sha256}" | head -c 255)"
# Unpacked crates contain a directory named after package's name and its
# version - here we're renaming that directory to contain the package's
# checksum as well, to avoid clashes in edge cases like:
#
# ```
# [dependencies]
# rand_core = "0.6.1"
# rand = { git = "https://github.com/rust-random/rand.git", rev = "...", package = "rand_core" }
# ```
#
# ... which might end up having similar entries in the Cargo.lock file:
#
# ```
# [[package]]
# name = "rand_core"
# version = "0.6.1"
# source = "registry+https://github.com/rust-lang/crates.io-index"
# checksum = "..."
#
# [[package]]
# name = "rand_core"
# version = "0.6.1"
# source = "git+https://github.com/rust-random/rand.git?rev=..."
# ```
mv "$out/${name}-${version}" "$dest"
echo '{"package":"${sha256}","files":{}}' > "$dest/.cargo-checksum.json"
'';

unpackGitDependency = { checkout, key, name, url, ... }:
Expand Down
1 change: 1 addition & 0 deletions test/fast/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ args: {
cargo-wildcard = import ./cargo-wildcard args;
default-run = import ./default-run args;
dummyfication = import ./dummyfication args;
duplicated-cargo-lock-items = import ./duplicated-cargo-lock-items args;
git-dep = import ./git-dep args;
git-dep-by-branch = import ./git-dep-by-branch args;
git-dep-by-branch-with-slash = import ./git-dep-by-branch-with-slash args;
Expand Down
6 changes: 6 additions & 0 deletions test/fast/duplicated-cargo-lock-items/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{ naersk, ... }:

naersk.buildPackage {
src = ./fixtures;
doCheck = true;
}
22 changes: 22 additions & 0 deletions test/fast/duplicated-cargo-lock-items/fixtures/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions test/fast/duplicated-cargo-lock-items/fixtures/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "app"
version = "0.1.0"
edition = "2018"

[dependencies]
rand = { git = "https://github.com/rust-random/rand.git", rev = "bda997404d9ab8a89d590734d8b0bb72aed10758", package = "rand_core" }
rand_core = "0.6.1"
3 changes: 3 additions & 0 deletions test/fast/duplicated-cargo-lock-items/fixtures/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

0 comments on commit d9a33d6

Please sign in to comment.