Include cargo dependencies in the Nix tarball
This commit is contained in:
parent
0dbb249b36
commit
d722e2175e
|
@ -4,4 +4,6 @@ libnixrust_LDFLAGS_USE := -L$(d)/target/release -lnixrust -ldl
|
||||||
libnixrust_LDFLAGS_USE_INSTALLED := $(libnixrust_LDFLAGS_USE)
|
libnixrust_LDFLAGS_USE_INSTALLED := $(libnixrust_LDFLAGS_USE)
|
||||||
|
|
||||||
$(d)/target/release/libnixrust.a: $(wildcard $(d)/src/*.rs) $(d)/Cargo.toml
|
$(d)/target/release/libnixrust.a: $(wildcard $(d)/src/*.rs) $(d)/Cargo.toml
|
||||||
$(trace-gen) cd nix-rust && RUSTC_BOOTSTRAP=1 cargo build --release && touch target/release/libnixrust.a
|
$(trace-gen) cd nix-rust && CARGO_HOME=$$(if [[ -d vendor ]]; then echo vendor; fi) cargo build --release -Z offline && touch target/release/libnixrust.a
|
||||||
|
|
||||||
|
dist-files += $(d)/vendor
|
||||||
|
|
39
release.nix
39
release.nix
|
@ -10,6 +10,43 @@ let
|
||||||
|
|
||||||
jobs = rec {
|
jobs = rec {
|
||||||
|
|
||||||
|
# Create a "vendor" directory that contains the crates listed in
|
||||||
|
# Cargo.lock, and include it in the Nix tarball. This allows Nix
|
||||||
|
# to be built without network access.
|
||||||
|
vendoredCrates =
|
||||||
|
let
|
||||||
|
lockFile = builtins.fromTOML (builtins.readFile nix-rust/Cargo.lock);
|
||||||
|
|
||||||
|
files = map (pkg: import <nix/fetchurl.nix> {
|
||||||
|
url = "https://crates.io/api/v1/crates/${pkg.name}/${pkg.version}/download";
|
||||||
|
sha256 = lockFile.metadata."checksum ${pkg.name} ${pkg.version} (registry+https://github.com/rust-lang/crates.io-index)";
|
||||||
|
}) (builtins.filter (pkg: pkg.source or "" == "registry+https://github.com/rust-lang/crates.io-index") lockFile.package);
|
||||||
|
|
||||||
|
in pkgs.runCommand "cargo-vendor-dir" {}
|
||||||
|
''
|
||||||
|
mkdir -p $out/vendor
|
||||||
|
|
||||||
|
cat > $out/vendor/config <<EOF
|
||||||
|
[source.crates-io]
|
||||||
|
replace-with = "vendored-sources"
|
||||||
|
|
||||||
|
[source.vendored-sources]
|
||||||
|
directory = "vendor"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
${toString (builtins.map (file: ''
|
||||||
|
mkdir $out/vendor/tmp
|
||||||
|
tar xvf ${file} -C $out/vendor/tmp
|
||||||
|
dir=$(echo $out/vendor/tmp/*)
|
||||||
|
|
||||||
|
# Add just enough metadata to keep Cargo happy.
|
||||||
|
printf '{"files":{},"package":"${file.outputHash}"}' > "$dir/.cargo-checksum.json"
|
||||||
|
|
||||||
|
mv "$dir" $out/vendor/
|
||||||
|
rmdir $out/vendor/tmp
|
||||||
|
'') files)}
|
||||||
|
'';
|
||||||
|
|
||||||
|
|
||||||
tarball =
|
tarball =
|
||||||
with pkgs;
|
with pkgs;
|
||||||
|
@ -38,6 +75,8 @@ let
|
||||||
|
|
||||||
distPhase =
|
distPhase =
|
||||||
''
|
''
|
||||||
|
cp -prd ${vendoredCrates}/vendor/ nix-rust/vendor/
|
||||||
|
|
||||||
runHook preDist
|
runHook preDist
|
||||||
make dist
|
make dist
|
||||||
mkdir -p $out/tarballs
|
mkdir -p $out/tarballs
|
||||||
|
|
Loading…
Reference in a new issue