diff --git a/pkgs/build-support/rust/import-cargo-lock.nix b/pkgs/build-support/rust/import-cargo-lock.nix index 83f4e0df4f2d..3973aff398ab 100644 --- a/pkgs/build-support/rust/import-cargo-lock.nix +++ b/pkgs/build-support/rust/import-cargo-lock.nix @@ -12,14 +12,15 @@ let # Parse a git source into different components. parseGit = src: let - parts = builtins.match ''git\+([^?]+)(\?rev=(.*))?#(.*)?'' src; - rev = builtins.elemAt parts 2; + parts = builtins.match ''git\+([^?]+)(\?(rev|tag|branch)=(.*))?#(.*)'' src; + type = builtins.elemAt parts 2; # rev, tag or branch + value = builtins.elemAt parts 3; in if parts == null then null else { url = builtins.elemAt parts 0; - sha = builtins.elemAt parts 3; - } // lib.optionalAttrs (rev != null) { inherit rev; }; + sha = builtins.elemAt parts 4; + } // lib.optionalAttrs (type != null) { inherit type value; }; packages = (builtins.fromTOML (builtins.readFile lockFile)).package; @@ -137,7 +138,7 @@ let cat > $out/.cargo-config <"] +edition = "2018" + +[dependencies] +rand = { git = "https://github.com/rust-random/rand.git", branch = "master" } diff --git a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-no-rev/default.nix b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-branch/default.nix similarity index 60% rename from pkgs/build-support/rust/test/import-cargo-lock/git-dependency-no-rev/default.nix rename to pkgs/build-support/rust/test/import-cargo-lock/git-dependency-branch/default.nix index fc36edc40772..f274d86c52b8 100644 --- a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-no-rev/default.nix +++ b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-branch/default.nix @@ -1,7 +1,7 @@ { rustPlatform }: rustPlatform.buildRustPackage { - pname = "git-dependency-no-rev"; + pname = "git-dependency-branch"; version = "0.1.0"; src = ./.; @@ -9,13 +9,13 @@ rustPlatform.buildRustPackage { cargoLock = { lockFile = ./Cargo.lock; outputHashes = { - "rand-0.8.3" = "0ya2hia3cn31qa8894s3av2s8j5bjwb6yq92k0jsnlx7jid0jwqa"; + "rand-0.8.4" = "1ilk9wvfw3mdm57g199ys8f5nrgdrh0n3a4c8b7nz6lgnqvfrv6z"; }; }; doInstallCheck = true; installCheckPhase = '' - $out/bin/git-dependency-no-rev + $out/bin/git-dependency-branch ''; } diff --git a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-no-rev/src/main.rs b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-branch/src/main.rs similarity index 100% rename from pkgs/build-support/rust/test/import-cargo-lock/git-dependency-no-rev/src/main.rs rename to pkgs/build-support/rust/test/import-cargo-lock/git-dependency-branch/src/main.rs diff --git a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-no-rev/Cargo.lock b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-rev/Cargo.lock similarity index 76% rename from pkgs/build-support/rust/test/import-cargo-lock/git-dependency-no-rev/Cargo.lock rename to pkgs/build-support/rust/test/import-cargo-lock/git-dependency-rev/Cargo.lock index 54b9c7c5739d..684d9419479d 100644 --- a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-no-rev/Cargo.lock +++ b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-rev/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "cfg-if" version = "1.0.0" @@ -18,7 +20,7 @@ dependencies = [ ] [[package]] -name = "git-dependency-no-rev" +name = "git-dependency-rev" version = "0.1.0" dependencies = [ "rand", @@ -39,7 +41,7 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] name = "rand" version = "0.8.3" -source = "git+https://github.com/rust-random/rand.git#f0e01ee0a7257753cc51b291f62666f4765923ef" +source = "git+https://github.com/rust-random/rand.git?rev=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7" dependencies = [ "libc", "rand_chacha", @@ -50,7 +52,7 @@ dependencies = [ [[package]] name = "rand_chacha" version = "0.3.0" -source = "git+https://github.com/rust-random/rand.git#f0e01ee0a7257753cc51b291f62666f4765923ef" +source = "git+https://github.com/rust-random/rand.git?rev=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7" dependencies = [ "ppv-lite86", "rand_core", @@ -58,8 +60,8 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.2" -source = "git+https://github.com/rust-random/rand.git#f0e01ee0a7257753cc51b291f62666f4765923ef" +version = "0.6.1" +source = "git+https://github.com/rust-random/rand.git?rev=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7" dependencies = [ "getrandom", ] @@ -67,7 +69,7 @@ dependencies = [ [[package]] name = "rand_hc" version = "0.3.0" -source = "git+https://github.com/rust-random/rand.git#f0e01ee0a7257753cc51b291f62666f4765923ef" +source = "git+https://github.com/rust-random/rand.git?rev=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7" dependencies = [ "rand_core", ] diff --git a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-no-rev/Cargo.toml b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-rev/Cargo.toml similarity index 51% rename from pkgs/build-support/rust/test/import-cargo-lock/git-dependency-no-rev/Cargo.toml rename to pkgs/build-support/rust/test/import-cargo-lock/git-dependency-rev/Cargo.toml index 770dfb86f523..3500325ae579 100644 --- a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-no-rev/Cargo.toml +++ b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-rev/Cargo.toml @@ -1,8 +1,8 @@ [package] -name = "git-dependency-no-rev" +name = "git-dependency-rev" version = "0.1.0" authors = ["Daniël de Kok "] edition = "2018" [dependencies] -rand = { git = "https://github.com/rust-random/rand.git" } +rand = { git = "https://github.com/rust-random/rand.git", rev = "0.8.3" } diff --git a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-rev/default.nix b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-rev/default.nix new file mode 100644 index 000000000000..40487d6829a2 --- /dev/null +++ b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-rev/default.nix @@ -0,0 +1,21 @@ +{ rustPlatform }: + +rustPlatform.buildRustPackage { + pname = "git-dependency-rev"; + version = "0.1.0"; + + src = ./.; + + cargoLock = { + lockFile = ./Cargo.lock; + outputHashes = { + "rand-0.8.3" = "0l3p174bpwia61vcvxz5mw65a13ri3wy94z04xrnyy5lzciykz4f"; + }; + }; + + doInstallCheck = true; + + installCheckPhase = '' + $out/bin/git-dependency-rev + ''; +} diff --git a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-rev/src/main.rs b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-rev/src/main.rs new file mode 100644 index 000000000000..50b4ed799e43 --- /dev/null +++ b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-rev/src/main.rs @@ -0,0 +1,9 @@ +use rand::Rng; + +fn main() { + let mut rng = rand::thread_rng(); + + // Always draw zero :). + let roll: u8 = rng.gen_range(0..1); + assert_eq!(roll, 0); +} diff --git a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-tag/Cargo.lock b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-tag/Cargo.lock new file mode 100644 index 000000000000..9f8ec19a366a --- /dev/null +++ b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-tag/Cargo.lock @@ -0,0 +1,81 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "getrandom" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "git-dependency-tag" +version = "0.1.0" +dependencies = [ + "rand", +] + +[[package]] +name = "libc" +version = "0.2.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" + +[[package]] +name = "ppv-lite86" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" + +[[package]] +name = "rand" +version = "0.8.3" +source = "git+https://github.com/rust-random/rand.git?tag=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.3.0" +source = "git+https://github.com/rust-random/rand.git?tag=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.1" +source = "git+https://github.com/rust-random/rand.git?tag=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.3.0" +source = "git+https://github.com/rust-random/rand.git?tag=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7" +dependencies = [ + "rand_core", +] + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" diff --git a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-tag/Cargo.toml b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-tag/Cargo.toml new file mode 100644 index 000000000000..1bda7336c263 --- /dev/null +++ b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-tag/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "git-dependency-tag" +version = "0.1.0" +authors = ["Daniël de Kok "] +edition = "2018" + +[dependencies] +rand = { git = "https://github.com/rust-random/rand.git", tag = "0.8.3" } diff --git a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-tag/default.nix b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-tag/default.nix new file mode 100644 index 000000000000..2a2f860ac8a1 --- /dev/null +++ b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-tag/default.nix @@ -0,0 +1,21 @@ +{ rustPlatform }: + +rustPlatform.buildRustPackage { + pname = "git-dependency-tag"; + version = "0.1.0"; + + src = ./.; + + cargoLock = { + lockFile = ./Cargo.lock; + outputHashes = { + "rand-0.8.3" = "0l3p174bpwia61vcvxz5mw65a13ri3wy94z04xrnyy5lzciykz4f"; + }; + }; + + doInstallCheck = true; + + installCheckPhase = '' + $out/bin/git-dependency-tag + ''; +} diff --git a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-tag/src/main.rs b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-tag/src/main.rs new file mode 100644 index 000000000000..50b4ed799e43 --- /dev/null +++ b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency-tag/src/main.rs @@ -0,0 +1,9 @@ +use rand::Rng; + +fn main() { + let mut rng = rand::thread_rng(); + + // Always draw zero :). + let roll: u8 = rng.gen_range(0..1); + assert_eq!(roll, 0); +} diff --git a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency/Cargo.lock b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency/Cargo.lock index 50600ef4caa5..fa71865b3e5f 100644 --- a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency/Cargo.lock +++ b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "cfg-if" version = "1.0.0" @@ -39,7 +41,7 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] name = "rand" version = "0.8.3" -source = "git+https://github.com/rust-random/rand.git?rev=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7" +source = "git+https://github.com/rust-random/rand.git#f0e01ee0a7257753cc51b291f62666f4765923ef" dependencies = [ "libc", "rand_chacha", @@ -50,7 +52,7 @@ dependencies = [ [[package]] name = "rand_chacha" version = "0.3.0" -source = "git+https://github.com/rust-random/rand.git?rev=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7" +source = "git+https://github.com/rust-random/rand.git#f0e01ee0a7257753cc51b291f62666f4765923ef" dependencies = [ "ppv-lite86", "rand_core", @@ -58,8 +60,8 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.1" -source = "git+https://github.com/rust-random/rand.git?rev=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7" +version = "0.6.2" +source = "git+https://github.com/rust-random/rand.git#f0e01ee0a7257753cc51b291f62666f4765923ef" dependencies = [ "getrandom", ] @@ -67,7 +69,7 @@ dependencies = [ [[package]] name = "rand_hc" version = "0.3.0" -source = "git+https://github.com/rust-random/rand.git?rev=0.8.3#6ecbe2626b2cc6110a25c97b1702b347574febc7" +source = "git+https://github.com/rust-random/rand.git#f0e01ee0a7257753cc51b291f62666f4765923ef" dependencies = [ "rand_core", ] diff --git a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency/Cargo.toml b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency/Cargo.toml index 11ee8b1763e6..a902dea9fcd0 100644 --- a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency/Cargo.toml +++ b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency/Cargo.toml @@ -5,4 +5,4 @@ authors = ["Daniël de Kok "] edition = "2018" [dependencies] -rand = { git = "https://github.com/rust-random/rand.git", rev = "0.8.3" } +rand = { git = "https://github.com/rust-random/rand.git" } diff --git a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency/default.nix b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency/default.nix index 17276c5f5c3c..944de9b45cb5 100644 --- a/pkgs/build-support/rust/test/import-cargo-lock/git-dependency/default.nix +++ b/pkgs/build-support/rust/test/import-cargo-lock/git-dependency/default.nix @@ -9,7 +9,7 @@ rustPlatform.buildRustPackage { cargoLock = { lockFile = ./Cargo.lock; outputHashes = { - "rand-0.8.3" = "0l3p174bpwia61vcvxz5mw65a13ri3wy94z04xrnyy5lzciykz4f"; + "rand-0.8.3" = "0ya2hia3cn31qa8894s3av2s8j5bjwb6yq92k0jsnlx7jid0jwqa"; }; };