2024-05-01 16:37:03 +00:00
|
|
|
# Dependencies (keep sorted)
|
|
|
|
{ craneLib
|
|
|
|
, inputs
|
2024-05-22 01:01:39 +00:00
|
|
|
, jq
|
2024-04-21 22:28:35 +00:00
|
|
|
, lib
|
|
|
|
, libiconv
|
2024-05-06 18:59:59 +00:00
|
|
|
, liburing
|
2024-04-21 22:28:35 +00:00
|
|
|
, pkgsBuildHost
|
|
|
|
, rocksdb
|
|
|
|
, rust
|
2024-05-23 20:32:43 +00:00
|
|
|
, rust-jemalloc-sys
|
2024-04-21 22:28:35 +00:00
|
|
|
, stdenv
|
|
|
|
|
2024-05-01 16:37:03 +00:00
|
|
|
# Options (keep sorted)
|
2024-04-25 02:51:19 +00:00
|
|
|
, default_features ? true
|
2024-05-24 18:22:11 +00:00
|
|
|
, disable_release_max_log_level ? false
|
2024-05-23 23:18:50 +00:00
|
|
|
, all_features ? false
|
2024-05-24 18:22:11 +00:00
|
|
|
, disable_features ? []
|
2024-04-21 22:28:35 +00:00
|
|
|
, features ? []
|
|
|
|
, profile ? "release"
|
|
|
|
}:
|
|
|
|
|
2024-05-01 16:37:03 +00:00
|
|
|
let
|
2024-05-23 22:11:06 +00:00
|
|
|
# We perform default-feature unification in nix, because some of the dependencies
|
|
|
|
# on the nix side depend on feature values.
|
2024-05-23 23:18:50 +00:00
|
|
|
crateFeatures = path:
|
|
|
|
let manifest = lib.importTOML "${path}/Cargo.toml"; in
|
|
|
|
lib.remove "default" (lib.attrNames manifest.features) ++
|
|
|
|
lib.attrNames
|
|
|
|
(lib.filterAttrs
|
|
|
|
(_: dependency: dependency.optional or false)
|
|
|
|
manifest.dependencies);
|
2024-05-23 22:11:06 +00:00
|
|
|
crateDefaultFeatures = path:
|
|
|
|
(lib.importTOML "${path}/Cargo.toml").features.default;
|
2024-06-02 21:08:52 +00:00
|
|
|
allDefaultFeatures = crateDefaultFeatures "${inputs.self}/src/main";
|
|
|
|
allFeatures = crateFeatures "${inputs.self}/src/main";
|
2024-05-23 22:11:06 +00:00
|
|
|
features' = lib.unique
|
|
|
|
(features ++
|
2024-05-23 23:18:50 +00:00
|
|
|
lib.optionals default_features allDefaultFeatures ++
|
|
|
|
lib.optionals all_features allFeatures);
|
2024-05-24 18:22:11 +00:00
|
|
|
disable_features' = disable_features ++ lib.optionals disable_release_max_log_level ["release_max_log_level"];
|
|
|
|
features'' = lib.subtractLists disable_features' features';
|
2024-05-23 22:11:06 +00:00
|
|
|
|
2024-05-24 18:22:11 +00:00
|
|
|
featureEnabled = feature : builtins.elem feature features'';
|
2024-05-23 20:32:43 +00:00
|
|
|
|
2024-07-06 00:13:21 +00:00
|
|
|
enableLiburing = featureEnabled "io_uring" && !stdenv.isDarwin;
|
2024-05-26 01:04:17 +00:00
|
|
|
|
2024-05-23 20:32:43 +00:00
|
|
|
# This derivation will set the JEMALLOC_OVERRIDE variable, causing the
|
|
|
|
# tikv-jemalloc-sys crate to use the nixpkgs jemalloc instead of building it's
|
|
|
|
# own. In order for this to work, we need to set flags on the build that match
|
|
|
|
# whatever flags tikv-jemalloc-sys was going to use. These are dependent on
|
|
|
|
# which features we enable in tikv-jemalloc-sys.
|
|
|
|
rust-jemalloc-sys' = (rust-jemalloc-sys.override {
|
|
|
|
# tikv-jemalloc-sys/unprefixed_malloc_on_supported_platforms feature
|
|
|
|
unprefixed = true;
|
|
|
|
}).overrideAttrs (old: {
|
|
|
|
configureFlags = old.configureFlags ++
|
|
|
|
# tikv-jemalloc-sys/profiling feature
|
|
|
|
lib.optional (featureEnabled "jemalloc_prof") "--enable-prof";
|
|
|
|
});
|
|
|
|
|
2024-05-01 16:37:03 +00:00
|
|
|
buildDepsOnlyEnv =
|
|
|
|
let
|
2024-05-24 03:12:50 +00:00
|
|
|
rocksdb' = (rocksdb.override {
|
2024-05-23 20:32:43 +00:00
|
|
|
jemalloc = rust-jemalloc-sys';
|
2024-05-24 03:06:00 +00:00
|
|
|
# rocksdb fails to build with prefixed jemalloc, which is required on
|
|
|
|
# darwin due to [1]. In this case, fall back to building rocksdb with
|
|
|
|
# libc malloc. This should not cause conflicts, because all of the
|
|
|
|
# jemalloc symbols are prefixed.
|
|
|
|
#
|
|
|
|
# [1]: https://github.com/tikv/jemallocator/blob/ab0676d77e81268cd09b059260c75b38dbef2d51/jemalloc-sys/src/env.rs#L17
|
|
|
|
enableJemalloc = featureEnabled "jemalloc" && !stdenv.isDarwin;
|
2024-05-24 03:12:50 +00:00
|
|
|
}).overrideAttrs (old: {
|
|
|
|
# TODO: static rocksdb fails to build on darwin
|
|
|
|
# build log at <https://girlboss.ceo/~strawberry/pb/JjGH>
|
|
|
|
meta.broken = stdenv.hostPlatform.isStatic && stdenv.isDarwin;
|
2024-07-06 00:13:21 +00:00
|
|
|
enableLiburing = enableLiburing;
|
2024-05-24 03:12:50 +00:00
|
|
|
});
|
2024-05-01 16:37:03 +00:00
|
|
|
in
|
|
|
|
{
|
2024-05-22 01:01:39 +00:00
|
|
|
# https://crane.dev/faq/rebuilds-bindgen.html
|
|
|
|
NIX_OUTPATH_USED_AS_RANDOM_SEED = "aaaaaaaaaa";
|
|
|
|
|
2024-05-01 16:37:03 +00:00
|
|
|
CARGO_PROFILE = profile;
|
|
|
|
ROCKSDB_INCLUDE_DIR = "${rocksdb'}/include";
|
|
|
|
ROCKSDB_LIB_DIR = "${rocksdb'}/lib";
|
|
|
|
}
|
|
|
|
//
|
|
|
|
(import ./cross-compilation-env.nix {
|
|
|
|
# Keep sorted
|
|
|
|
inherit
|
|
|
|
lib
|
|
|
|
pkgsBuildHost
|
|
|
|
rust
|
|
|
|
stdenv;
|
|
|
|
});
|
2024-04-21 22:28:35 +00:00
|
|
|
|
2024-05-01 16:37:03 +00:00
|
|
|
buildPackageEnv = {
|
2024-04-27 01:38:29 +00:00
|
|
|
CONDUWUIT_VERSION_EXTRA = inputs.self.shortRev or inputs.self.dirtyShortRev or "";
|
2024-05-06 18:59:59 +00:00
|
|
|
} // buildDepsOnlyEnv // {
|
2024-05-26 01:04:17 +00:00
|
|
|
# Only needed in static stdenv because these are transitive dependencies of rocksdb
|
|
|
|
CARGO_BUILD_RUSTFLAGS = buildDepsOnlyEnv.CARGO_BUILD_RUSTFLAGS
|
|
|
|
+ lib.optionalString (enableLiburing && stdenv.hostPlatform.isStatic)
|
|
|
|
" -L${lib.getLib liburing}/lib -luring";
|
|
|
|
};
|
2024-05-06 18:59:59 +00:00
|
|
|
|
|
|
|
|
2024-05-01 16:37:03 +00:00
|
|
|
|
|
|
|
commonAttrs = {
|
|
|
|
inherit
|
|
|
|
(craneLib.crateNameFromCargoToml {
|
|
|
|
cargoToml = "${inputs.self}/Cargo.toml";
|
|
|
|
})
|
|
|
|
pname
|
|
|
|
version;
|
|
|
|
|
|
|
|
src = let filter = inputs.nix-filter.lib; in filter {
|
|
|
|
root = inputs.self;
|
2024-04-21 22:28:35 +00:00
|
|
|
|
2024-05-01 16:37:03 +00:00
|
|
|
# Keep sorted
|
|
|
|
include = [
|
|
|
|
"Cargo.lock"
|
|
|
|
"Cargo.toml"
|
2024-05-09 22:59:08 +00:00
|
|
|
"deps"
|
2024-05-01 16:37:03 +00:00
|
|
|
"src"
|
|
|
|
];
|
|
|
|
};
|
2024-04-21 22:28:35 +00:00
|
|
|
|
2024-05-23 20:32:43 +00:00
|
|
|
buildInputs = lib.optional (featureEnabled "jemalloc") rust-jemalloc-sys';
|
|
|
|
|
2024-05-01 16:37:03 +00:00
|
|
|
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
|
2024-05-22 01:01:39 +00:00
|
|
|
|
|
|
|
# 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
|
2024-04-21 22:28:35 +00:00
|
|
|
]
|
2024-05-12 05:13:23 +00:00
|
|
|
++ lib.optionals stdenv.isDarwin [
|
2024-05-12 03:30:37 +00:00
|
|
|
# https://github.com/NixOS/nixpkgs/issues/206242
|
2024-05-12 05:13:23 +00:00
|
|
|
libiconv
|
|
|
|
|
2024-05-12 03:30:37 +00:00
|
|
|
# https://stackoverflow.com/questions/69869574/properly-adding-darwin-apple-sdk-to-a-nix-shell
|
|
|
|
# https://discourse.nixos.org/t/compile-a-rust-binary-on-macos-dbcrossbar/8612
|
2024-05-12 05:13:23 +00:00
|
|
|
pkgsBuildHost.darwin.apple_sdk.frameworks.Security
|
|
|
|
];
|
2024-05-01 16:37:03 +00:00
|
|
|
};
|
|
|
|
in
|
|
|
|
|
|
|
|
craneLib.buildPackage ( commonAttrs // {
|
|
|
|
cargoArtifacts = craneLib.buildDepsOnly (commonAttrs // {
|
|
|
|
env = buildDepsOnlyEnv;
|
|
|
|
});
|
2024-04-21 22:28:35 +00:00
|
|
|
|
2024-05-23 22:11:06 +00:00
|
|
|
cargoExtraArgs = "--no-default-features "
|
2024-04-25 02:51:19 +00:00
|
|
|
+ lib.optionalString
|
2024-05-24 18:22:11 +00:00
|
|
|
(features'' != [])
|
|
|
|
"--features " + (builtins.concatStringsSep "," features'');
|
2024-04-21 22:28:35 +00:00
|
|
|
|
2024-05-03 07:35:36 +00:00
|
|
|
# This is redundant with CI
|
|
|
|
cargoTestCommand = "";
|
2024-05-12 03:31:10 +00:00
|
|
|
cargoCheckCommand = "";
|
2024-05-01 16:37:03 +00:00
|
|
|
doCheck = false;
|
|
|
|
|
|
|
|
env = buildPackageEnv;
|
2024-04-21 22:28:35 +00:00
|
|
|
|
|
|
|
passthru = {
|
2024-05-01 16:37:03 +00:00
|
|
|
env = buildPackageEnv;
|
2024-04-21 22:28:35 +00:00
|
|
|
};
|
2024-05-01 16:37:03 +00:00
|
|
|
|
|
|
|
meta.mainProgram = commonAttrs.pname;
|
|
|
|
})
|