only set GRAPEVINE_VERSION_EXTRA for final build

This prevents us from needing to recompile the dependencies when that
environment variable changes, which generally changes on every commit,
which is far more frequently than the dependencies are actually changed.
This commit is contained in:
Charles Hall 2024-05-01 01:05:24 -07:00
parent bbb1a6fea4
commit 21a4b9e5a1
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF

View file

@ -14,15 +14,13 @@
}: }:
let let
env = buildDepsOnlyEnv =
let let
rocksdb' = rocksdb.override { rocksdb' = rocksdb.override {
enableJemalloc = builtins.elem "jemalloc" features; enableJemalloc = builtins.elem "jemalloc" features;
}; };
in in
{ {
GRAPEVINE_VERSION_EXTRA =
inputs.self.shortRev or inputs.self.dirtyShortRev;
CARGO_PROFILE = profile; CARGO_PROFILE = profile;
ROCKSDB_INCLUDE_DIR = "${rocksdb'}/include"; ROCKSDB_INCLUDE_DIR = "${rocksdb'}/include";
ROCKSDB_LIB_DIR = "${rocksdb'}/lib"; ROCKSDB_LIB_DIR = "${rocksdb'}/lib";
@ -36,9 +34,12 @@ let
rust rust
stdenv; stdenv;
}); });
in
craneLib.buildPackage rec { buildPackageEnv = {
GRAPEVINE_VERSION_EXTRA = inputs.self.shortRev or inputs.self.dirtyShortRev;
} // buildDepsOnlyEnv;
commonAttrs = {
inherit inherit
(craneLib.crateNameFromCargoToml { (craneLib.crateNameFromCargoToml {
cargoToml = "${inputs.self}/Cargo.toml"; cargoToml = "${inputs.self}/Cargo.toml";
@ -57,6 +58,20 @@ craneLib.buildPackage rec {
]; ];
}; };
nativeBuildInputs = [
# bindgen needs the build platform's libclang. Apparently due to "splicing
# weirdness", pkgs.rustPlatform.bindgenHook on its own doesn't quite do the
# right thing here.
pkgsBuildHost.rustPlatform.bindgenHook
];
};
in
craneLib.buildPackage ( commonAttrs // {
cargoArtifacts = craneLib.buildDepsOnly (commonAttrs // {
env = buildDepsOnlyEnv;
});
cargoExtraArgs = "--locked " cargoExtraArgs = "--locked "
+ lib.optionalString + lib.optionalString
(!default-features) (!default-features)
@ -68,18 +83,11 @@ craneLib.buildPackage rec {
# This is redundant with CI # This is redundant with CI
doCheck = false; doCheck = false;
nativeBuildInputs = [ env = buildPackageEnv;
# bindgen needs the build platform's libclang. Apparently due to "splicing
# weirdness", pkgs.rustPlatform.bindgenHook on its own doesn't quite do the
# right thing here.
pkgsBuildHost.rustPlatform.bindgenHook
];
inherit env;
passthru = { passthru = {
inherit env; env = buildPackageEnv;
}; };
meta.mainProgram = pname; meta.mainProgram = commonAttrs.pname;
} })