nix build: replace fetchCargoTarball with importCargoLock (#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>
This commit is contained in:
Mukilan Thiyagarajan 2024-03-25 11:02:55 +05:30 committed by GitHub
parent 58081579e9
commit c50df5ccbe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 30 deletions

View file

@ -96,27 +96,17 @@ stdenv.mkDerivation (androidEnvironment // rec {
# all of Servos 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;

View file

@ -24,9 +24,9 @@ checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
[[package]]
name = "indexmap"
version = "2.1.0"
version = "2.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4"
dependencies = [
"equivalent",
"hashbrown",
@ -40,9 +40,9 @@ checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
[[package]]
name = "proc-macro2"
version = "1.0.74"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2de98502f212cfcea8d0bb305bd0f49d7ebdd75b64ba0a68f937d888f4e0d6db"
checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
dependencies = [
"unicode-ident",
]
@ -58,18 +58,18 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.194"
version = "1.0.197"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b114498256798c94a0689e1a15fec6005dee8ac1f41de56404b67afc2a4b773"
checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.194"
version = "1.0.197"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3385e45322e8f9931410f01b3031ec534c3947d0e94c18049af4d9f9907d4e0"
checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
dependencies = [
"proc-macro2",
"quote",
@ -87,9 +87,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.46"
version = "2.0.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89456b690ff72fddcecf231caedbe615c59480c93358a93dfae7fc29e3ebbf0e"
checksum = "7383cd0e49fff4b6b90ca5670bfd3e9d6a733b3f90c686605aa7eec8c4996032"
dependencies = [
"proc-macro2",
"quote",
@ -98,9 +98,9 @@ dependencies = [
[[package]]
name = "toml"
version = "0.8.8"
version = "0.8.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35"
checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3"
dependencies = [
"indexmap",
"serde",
@ -120,9 +120,9 @@ dependencies = [
[[package]]
name = "toml_edit"
version = "0.21.0"
version = "0.22.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03"
checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4"
dependencies = [
"indexmap",
"serde",
@ -139,9 +139,9 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "winnow"
version = "0.5.31"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97a4882e6b134d6c28953a387571f1acdd3496830d5e36c5e3a1075580ea641c"
checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8"
dependencies = [
"memchr",
]