mirror of
https://github.com/nix-community/naersk
synced 2024-11-10 06:04:17 +00:00
Add experimental support for git dependencies
This commit is contained in:
parent
279fe46216
commit
47b22494d9
6 changed files with 110 additions and 62 deletions
34
build.nix
34
build.nix
|
@ -29,6 +29,7 @@
|
|||
# Which drops the run-time dependency on the crates-io source thereby
|
||||
# significantly reducing the Nix closure size.
|
||||
, removeReferencesToSrcFromDocs
|
||||
, gitDependencies
|
||||
, pname
|
||||
, version
|
||||
, rustc
|
||||
|
@ -59,6 +60,10 @@ let
|
|||
|
||||
drv = stdenv.mkDerivation {
|
||||
name = "${pname}-${version}";
|
||||
gitDependencies =
|
||||
if gitDependencies != {}
|
||||
then writeText "gitdeps.json" (builtins.toJSON gitDependencies)
|
||||
else "";
|
||||
inherit
|
||||
src
|
||||
doCheck
|
||||
|
@ -143,6 +148,35 @@ let
|
|||
# TODO: figure out why "1" works whereas "0" doesn't
|
||||
find . -type f -exec touch --date=@1 {} +
|
||||
|
||||
if [ -n "$gitDependencies" ]; then
|
||||
echo "Git dependencies were set, patching Cargo.toml(s)"
|
||||
while read -r json; do
|
||||
echo "Got json: $json"
|
||||
dir=$(echo "$json" | jq -cMr '.dir')
|
||||
checkout=$(echo "$json" | jq -cMr '.checkout')
|
||||
name=$(echo "$json" | jq -cMr '.name')
|
||||
url=$(echo "$json" | jq -cMr '.url')
|
||||
echo "Found json:"
|
||||
echo " dir: $dir"
|
||||
echo " checkout: $checkout"
|
||||
echo " name: $name"
|
||||
echo " url: $url"
|
||||
echo >> Cargo.toml
|
||||
echo "[patch.\"$url\"]" >> $dir/Cargo.toml
|
||||
echo "$name = { path = \"$checkout\" }" >> $dir/Cargo.toml
|
||||
|
||||
echo "Cargo toml updated"
|
||||
done < <(cat "$gitDependencies" | jq -cMr ' '' +
|
||||
# This turns { ".": [ { "rev": "deadbeef" } ] } into
|
||||
# [ { "dir": ".", "rev": "deadbeef" } ]
|
||||
''
|
||||
to_entries | .[] | .key as $dir | .value | map(.+{ dir: $dir }) | .[]
|
||||
')
|
||||
sed -ri '/^"checksum [^ ]+ [^ ]+ [(]git[+]https/d' Cargo.lock
|
||||
sed -ri '/^source = "git/d' Cargo.lock
|
||||
sed -ri 's/ [(]git[+]https[^)]*[)]//g' Cargo.lock
|
||||
fi
|
||||
|
||||
runHook postConfigure
|
||||
'';
|
||||
|
||||
|
|
|
@ -58,6 +58,11 @@ let
|
|||
# Nix 2.3 onwards where all bugs in `builtins.fromTOML` seem to have been
|
||||
# fixed.
|
||||
usePureFromTOML = attrs0.usePureFromTOML or true;
|
||||
|
||||
# Prefetch git dependencies with `builtins.fetchGit` and add `[patch.*]`
|
||||
# sections to the `Cargo.toml`. This also removes all references to git
|
||||
# links in the `Cargo.lock`. **Highly experimental.**
|
||||
allowGitDependencies = attrs0.allowGitDependencies or false;
|
||||
};
|
||||
|
||||
argIsAttrs =
|
||||
|
@ -137,7 +142,9 @@ let
|
|||
buildPlanConfig = rec {
|
||||
inherit (sr) src root;
|
||||
# Whether we skip pre-building the deps
|
||||
isSingleStep = attrs.singleStep or false;
|
||||
isSingleStep = attrs.singleStep;
|
||||
|
||||
patchGitDeps = attrs.allowGitDependencies;
|
||||
|
||||
# The members we want to build
|
||||
# (list of directory names)
|
||||
|
|
|
@ -45,6 +45,10 @@ let
|
|||
buildPackage = arg:
|
||||
let
|
||||
config = mkConfig arg;
|
||||
gitDependencies =
|
||||
if config.patchGitDeps
|
||||
then libb.findGitDependencies { inherit (config) cargotomls; }
|
||||
else {};
|
||||
in
|
||||
import ./build.nix
|
||||
(
|
||||
|
@ -58,12 +62,14 @@ let
|
|||
if [ -f src/main.rs ] ; then touch src/main.rs; fi
|
||||
'';
|
||||
inherit (config) src cargoTestCommands copyTarget copyBins copyDocsToSeparateOutput;
|
||||
inherit gitDependencies;
|
||||
} // config.buildConfig // {
|
||||
builtDependencies = lib.optional (! config.isSingleStep)
|
||||
(
|
||||
import ./build.nix
|
||||
(
|
||||
{
|
||||
inherit gitDependencies;
|
||||
src = libb.dummySrc {
|
||||
cargoconfig =
|
||||
if builtinz.pathExists (toString config.root + "/.cargo/config")
|
||||
|
|
32
lib.nix
32
lib.nix
|
@ -56,6 +56,38 @@ rec
|
|||
mkMetadataKey = name: version:
|
||||
"checksum ${name} ${version} (registry+https://github.com/rust-lang/crates.io-index)";
|
||||
|
||||
# a record:
|
||||
# { "." = # '.' is the directory of the cargotoml
|
||||
# [
|
||||
# {
|
||||
# name = "rand";
|
||||
# url = "https://github.com/...";
|
||||
# checkout = "/nix/store/checkout"
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
findGitDependencies =
|
||||
{ cargotomls
|
||||
}:
|
||||
let
|
||||
tomlDepdencies = cargotoml:
|
||||
lib.filter (x: ! isNull x) (
|
||||
lib.mapAttrsToList
|
||||
(k: v:
|
||||
if ! builtins.hasAttr "git" v
|
||||
then null
|
||||
else
|
||||
{ name = k;
|
||||
url = v.git;
|
||||
checkout = builtins.fetchGit {
|
||||
url = v.git;
|
||||
rev = v.rev;
|
||||
};
|
||||
}
|
||||
) cargotoml.dependencies);
|
||||
in
|
||||
lib.mapAttrs (_: tomlDepdencies) cargotomls;
|
||||
|
||||
# A very minimal 'src' which makes cargo happy nonetheless
|
||||
dummySrc =
|
||||
{ cargoconfig # string
|
||||
|
|
6
test.nix
6
test.nix
|
@ -115,6 +115,12 @@ rec
|
|||
{ buildInputs = [ dummyfication ]; }
|
||||
"my-bin > $out";
|
||||
|
||||
git-dep = naersk.buildPackage {
|
||||
root = ./test/git-dep;
|
||||
cargoOptions = [ "--locked" ];
|
||||
allowGitDependencies = true;
|
||||
};
|
||||
|
||||
workspace = naersk.buildPackage {
|
||||
src = ./test/workspace;
|
||||
doDoc = false;
|
||||
|
|
85
test/git-dep/Cargo.lock
generated
85
test/git-dep/Cargo.lock
generated
|
@ -1,39 +1,26 @@
|
|||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "c2-chacha"
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cloudabi"
|
||||
version = "0.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fuchsia-cprng"
|
||||
version = "0.1.1"
|
||||
name = "cfg-if"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.1.3"
|
||||
version = "0.1.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -43,19 +30,14 @@ dependencies = [
|
|||
"rand 0.7.0-pre.1 (git+https://github.com/rust-random/rand?rev=703452450770d4b2bb0b117dfc83aea5ba61ec60)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.58"
|
||||
version = "0.2.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.5"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
|
@ -63,8 +45,8 @@ name = "rand"
|
|||
version = "0.7.0-pre.1"
|
||||
source = "git+https://github.com/rust-random/rand?rev=703452450770d4b2bb0b117dfc83aea5ba61ec60#703452450770d4b2bb0b117dfc83aea5ba61ec60"
|
||||
dependencies = [
|
||||
"getrandom 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_chacha 0.2.0 (git+https://github.com/rust-random/rand?rev=703452450770d4b2bb0b117dfc83aea5ba61ec60)",
|
||||
"rand_core 0.5.0 (git+https://github.com/rust-random/rand?rev=703452450770d4b2bb0b117dfc83aea5ba61ec60)",
|
||||
"rand_hc 0.2.0 (git+https://github.com/rust-random/rand?rev=703452450770d4b2bb0b117dfc83aea5ba61ec60)",
|
||||
|
@ -75,7 +57,7 @@ name = "rand_chacha"
|
|||
version = "0.2.0"
|
||||
source = "git+https://github.com/rust-random/rand?rev=703452450770d4b2bb0b117dfc83aea5ba61ec60#703452450770d4b2bb0b117dfc83aea5ba61ec60"
|
||||
dependencies = [
|
||||
"c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_core 0.5.0 (git+https://github.com/rust-random/rand?rev=703452450770d4b2bb0b117dfc83aea5ba61ec60)",
|
||||
]
|
||||
|
||||
|
@ -84,7 +66,7 @@ name = "rand_core"
|
|||
version = "0.5.0"
|
||||
source = "git+https://github.com/rust-random/rand?rev=703452450770d4b2bb0b117dfc83aea5ba61ec60#703452450770d4b2bb0b117dfc83aea5ba61ec60"
|
||||
dependencies = [
|
||||
"getrandom 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -96,37 +78,18 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
name = "wasi"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[metadata]
|
||||
"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd"
|
||||
"checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101"
|
||||
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
|
||||
"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
||||
"checksum getrandom 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8d1dffef07351aafe6ef177e4dd2b8dcf503e6bc765dea3b0de9ed149a3db1ec"
|
||||
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
|
||||
"checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319"
|
||||
"checksum ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e3cbf9f658cdb5000fcf6f362b8ea2ba154b9f146a61c7a20d647034c6b6561b"
|
||||
"checksum c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb"
|
||||
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
"checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407"
|
||||
"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
|
||||
"checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b"
|
||||
"checksum rand 0.7.0-pre.1 (git+https://github.com/rust-random/rand?rev=703452450770d4b2bb0b117dfc83aea5ba61ec60)" = "<none>"
|
||||
"checksum rand_chacha 0.2.0 (git+https://github.com/rust-random/rand?rev=703452450770d4b2bb0b117dfc83aea5ba61ec60)" = "<none>"
|
||||
"checksum rand_core 0.5.0 (git+https://github.com/rust-random/rand?rev=703452450770d4b2bb0b117dfc83aea5ba61ec60)" = "<none>"
|
||||
"checksum rand_hc 0.2.0 (git+https://github.com/rust-random/rand?rev=703452450770d4b2bb0b117dfc83aea5ba61ec60)" = "<none>"
|
||||
"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770"
|
||||
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
"checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d"
|
||||
|
|
Loading…
Reference in a new issue