Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importCargoLock: git deps with rev, branch or tag #137303

Merged
merged 3 commits into from
Sep 11, 2021
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
11 changes: 6 additions & 5 deletions pkgs/build-support/rust/import-cargo-lock.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -137,7 +138,7 @@ let
cat > $out/.cargo-config <<EOF
[source."${gitParts.url}"]
git = "${gitParts.url}"
${lib.optionalString (gitParts ? rev) "rev = \"${gitParts.rev}\""}
${lib.optionalString (gitParts ? type) "${gitParts.type} = \"${gitParts.value}\""}
replace-with = "vendored-sources"
EOF
''
Expand Down
6 changes: 5 additions & 1 deletion pkgs/build-support/rust/test/import-cargo-lock/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{ callPackage }:

# Build like this from nixpkgs root:
# $ nix-build -A tests.importCargoLock
{
basic = callPackage ./basic { };
gitDependency = callPackage ./git-dependency { };
gitDependencyNoRev = callPackage ./git-dependency-no-rev { };
gitDependencyRev = callPackage ./git-dependency-rev { };
gitDependencyTag = callPackage ./git-dependency-tag { };
gitDependencyBranch = callPackage ./git-dependency-branch { };
maturin = callPackage ./maturin { };
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "git-dependency-branch"
version = "0.1.0"
authors = ["Daniël de Kok <me@danieldk.eu>"]
edition = "2018"

[dependencies]
rand = { git = "https://github.com/rust-random/rand.git", branch = "master" }
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{ rustPlatform }:

rustPlatform.buildRustPackage {
pname = "git-dependency-no-rev";
pname = "git-dependency-branch";
version = "0.1.0";

src = ./.;

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
'';
}

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

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "git-dependency-no-rev"
name = "git-dependency-rev"
version = "0.1.0"
authors = ["Daniël de Kok <me@danieldk.eu>"]
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" }
Original file line number Diff line number Diff line change
@@ -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
'';
}
Original file line number Diff line number Diff line change
@@ -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);
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "git-dependency-tag"
version = "0.1.0"
authors = ["Daniël de Kok <me@danieldk.eu>"]
edition = "2018"

[dependencies]
rand = { git = "https://github.com/rust-random/rand.git", tag = "0.8.3" }
Original file line number Diff line number Diff line change
@@ -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
'';
}
Original file line number Diff line number Diff line change
@@ -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);
}
Loading