Skip to content

Commit

Permalink
nix build: replace fetchCargoTarball with importCargoLock (servo#…
Browse files Browse the repository at this point in the history
…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 <mukilan@igalia.com>
  • Loading branch information
mukilan authored and ektuu committed Mar 28, 2024
1 parent 2f00d30 commit f305792
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 30 deletions.
18 changes: 4 additions & 14 deletions etc/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,17 @@ stdenv.mkDerivation (androidEnvironment // rec {
# all of Servo’s dependencies get pulled into the Nix store too, wasting over 1GB of disk space.
# Filtering the lockfile to only the parts needed by crown saves space and builds faster.
(let
vendorTarball = rustPlatform.fetchCargoTarball {
src = ../support/filterlock;
hash = "sha256-EBrL0/cEJfGIXUYqFiufRYFBAk5LSf0Cd/19+9m9JZI=";
};
vendorConfig = builtins.toFile "toml" ''
[source.crates-io]
replace-with = "vendor"
[source.vendor]
directory = "vendor"
'';

# Build and run filterlock over the main Cargo.lock.
filteredLockFile = (clangStdenv.mkDerivation {
name = "lock";
buildInputs = [ rustToolchain ];
nativeBuildInputs = [ rustPlatform.cargoSetupHook ];
src = ../support/filterlock;
cargoDeps = rustPlatform.importCargoLock {
lockFile = ../support/filterlock/Cargo.lock;
};
buildPhase = ''
tar xzf ${vendorTarball}
mv cargo-deps-vendor.tar.gz vendor
mkdir .cargo
cp -- ${vendorConfig} .cargo/config.toml
> $out cargo run --offline -- ${../Cargo.lock} crown
'';
dontInstall = true;
Expand Down
32 changes: 16 additions & 16 deletions support/filterlock/Cargo.lock

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

0 comments on commit f305792

Please sign in to comment.