mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-16 07:11:24 +01:00
129 lines
3.3 KiB
Nix
129 lines
3.3 KiB
Nix
# Dependencies (keep sorted)
|
|
{ craneLib
|
|
, inputs
|
|
, jq
|
|
, lib
|
|
, pkgsBuildHost
|
|
, rocksdb
|
|
, rust
|
|
, rust-jemalloc-sys
|
|
, snappy
|
|
, stdenv
|
|
|
|
# Options (keep sorted)
|
|
, default-features ? true
|
|
, all-features ? false
|
|
, features ? []
|
|
, profile ? "release"
|
|
, version-extra ? inputs.self.shortRev
|
|
or inputs.self.dirtyShortRev
|
|
or null,
|
|
}:
|
|
|
|
let
|
|
# We perform default-feature unification in nix, because some of the dependencies
|
|
# on the nix side depend on feature values.
|
|
cargoManifest = lib.importTOML "${inputs.self}/Cargo.toml";
|
|
allDefaultFeatures = cargoManifest.features.default;
|
|
allFeatures = lib.unique (
|
|
lib.remove "default" (lib.attrNames cargoManifest.features) ++
|
|
lib.attrNames
|
|
(lib.filterAttrs (_: dependency: dependency.optional or false)
|
|
cargoManifest.dependencies));
|
|
features' = lib.unique
|
|
(features ++
|
|
lib.optionals default-features allDefaultFeatures ++
|
|
lib.optionals all-features allFeatures);
|
|
|
|
featureEnabled = feature : builtins.elem feature features';
|
|
|
|
buildDepsOnlyEnv =
|
|
let
|
|
rocksdb' = rocksdb.override {
|
|
enableJemalloc = featureEnabled "jemalloc";
|
|
};
|
|
in
|
|
{
|
|
NIX_OUTPATH_USED_AS_RANDOM_SEED = "randomseed";
|
|
CARGO_PROFILE = profile;
|
|
ROCKSDB_INCLUDE_DIR = "${rocksdb'}/include";
|
|
ROCKSDB_LIB_DIR = "${rocksdb'}/lib";
|
|
}
|
|
//
|
|
(import ./cross-compilation-env.nix {
|
|
# Keep sorted
|
|
inherit
|
|
lib
|
|
pkgsBuildHost
|
|
rust
|
|
snappy
|
|
stdenv;
|
|
});
|
|
|
|
buildPackageEnv =
|
|
(lib.optionalAttrs (version-extra != null) {
|
|
GRAPEVINE_VERSION_EXTRA = version-extra;
|
|
})
|
|
// buildDepsOnlyEnv;
|
|
|
|
commonAttrs = {
|
|
# Reading from cargoManifest directly instead of using
|
|
# createNameFromCargoToml to avoid IFD
|
|
pname = cargoManifest.package.name;
|
|
version = cargoManifest.package.version;
|
|
|
|
src = let filter = inputs.nix-filter.lib; in filter {
|
|
root = inputs.self;
|
|
|
|
# Keep sorted
|
|
include = [
|
|
".cargo/config.toml"
|
|
"Cargo.lock"
|
|
"Cargo.toml"
|
|
"src"
|
|
];
|
|
};
|
|
|
|
dontStrip = profile != "release";
|
|
|
|
buildInputs = lib.optional (featureEnabled "jemalloc") rust-jemalloc-sys;
|
|
|
|
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
|
|
|
|
# We don't actually depend on `jq`, but crane's `buildPackage` does, but
|
|
# its `buildDepsOnly` doesn't. This causes those two derivations to have
|
|
# differing values for `NIX_CFLAGS_COMPILE`, which contributes to spurious
|
|
# rebuilds of bindgen and its depedents.
|
|
jq
|
|
];
|
|
|
|
# Opt out of crane's automagic cross support
|
|
doIncludeCrossToolchainEnv = false;
|
|
|
|
# This is redundant with CI
|
|
doCheck = false;
|
|
};
|
|
in
|
|
|
|
craneLib.buildPackage (commonAttrs // {
|
|
cargoArtifacts = craneLib.buildDepsOnly (commonAttrs // {
|
|
env = buildDepsOnlyEnv;
|
|
});
|
|
|
|
cargoExtraArgs = "--locked --no-default-features "
|
|
+ lib.optionalString
|
|
(features' != [])
|
|
"--features " + (builtins.concatStringsSep "," features');
|
|
|
|
env = buildPackageEnv;
|
|
|
|
passthru = {
|
|
env = buildPackageEnv;
|
|
};
|
|
|
|
meta.mainProgram = commonAttrs.pname;
|
|
})
|