Skip to content

Commit 749df1e

Browse files
mukilanpull[bot]
authored andcommitted
nix build: replace fetchCargoTarball with importCargoLock (servo#31825)
[`importCargoLock`][1] allows us to use the existing Cargo.lock file. This means we no longer need to update the sha256 hash whenever the dependencies are upgraded. It also integrates with nix's rustToolchain support via `cargoSetupHooks` and automatically vendors the dependencies, allowing us to simplify the logic for `filterlock` derivation. [1]: https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/rust.section.md#vendoring-of-dependencies-vendoring-of-dependencies Signed-off-by: Mukilan Thiyagarajan <[email protected]>
1 parent ea0ca2a commit 749df1e

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

etc/shell.nix

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,27 +96,17 @@ stdenv.mkDerivation (androidEnvironment // rec {
9696
# all of Servo’s dependencies get pulled into the Nix store too, wasting over 1GB of disk space.
9797
# Filtering the lockfile to only the parts needed by crown saves space and builds faster.
9898
(let
99-
vendorTarball = rustPlatform.fetchCargoTarball {
100-
src = ../support/filterlock;
101-
hash = "sha256-EBrL0/cEJfGIXUYqFiufRYFBAk5LSf0Cd/19+9m9JZI=";
102-
};
103-
vendorConfig = builtins.toFile "toml" ''
104-
[source.crates-io]
105-
replace-with = "vendor"
106-
[source.vendor]
107-
directory = "vendor"
108-
'';
10999

110100
# Build and run filterlock over the main Cargo.lock.
111101
filteredLockFile = (clangStdenv.mkDerivation {
112102
name = "lock";
113103
buildInputs = [ rustToolchain ];
104+
nativeBuildInputs = [ rustPlatform.cargoSetupHook ];
114105
src = ../support/filterlock;
106+
cargoDeps = rustPlatform.importCargoLock {
107+
lockFile = ../support/filterlock/Cargo.lock;
108+
};
115109
buildPhase = ''
116-
tar xzf ${vendorTarball}
117-
mv cargo-deps-vendor.tar.gz vendor
118-
mkdir .cargo
119-
cp -- ${vendorConfig} .cargo/config.toml
120110
> $out cargo run --offline -- ${../Cargo.lock} crown
121111
'';
122112
dontInstall = true;

support/filterlock/Cargo.lock

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)