2024-05-01 16:37:03 +00:00
|
|
|
# Dependencies (keep sorted)
|
|
|
|
{ craneLib
|
|
|
|
, inputs
|
2024-04-21 22:28:35 +00:00
|
|
|
, lib
|
|
|
|
, libiconv
|
|
|
|
, 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-04-21 22:28:35 +00:00
|
|
|
, features ? []
|
|
|
|
, profile ? "release"
|
|
|
|
}:
|
|
|
|
|
2024-05-01 16:37:03 +00:00
|
|
|
let
|
2024-05-23 20:32:43 +00:00
|
|
|
featureEnabled = feature : builtins.elem feature features;
|
|
|
|
|
|
|
|
# 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
|
|
|
|
rocksdb' = rocksdb.override {
|
2024-05-23 20:32:43 +00:00
|
|
|
jemalloc = rust-jemalloc-sys';
|
|
|
|
enableJemalloc = featureEnabled "jemalloc";
|
2024-05-01 16:37:03 +00:00
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
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-01 16:37:03 +00:00
|
|
|
} // buildDepsOnlyEnv;
|
|
|
|
|
|
|
|
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-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
|
|
|
|
|
|
|
cargoExtraArgs = ""
|
2024-04-25 02:51:19 +00:00
|
|
|
+ lib.optionalString
|
|
|
|
(!default_features)
|
|
|
|
"--no-default-features "
|
2024-04-21 22:28:35 +00:00
|
|
|
+ lib.optionalString
|
|
|
|
(features != [])
|
|
|
|
"--features " + (builtins.concatStringsSep "," features);
|
|
|
|
|
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;
|
|
|
|
|
2024-05-03 16:05:01 +00:00
|
|
|
# https://crane.dev/faq/rebuilds-bindgen.html
|
|
|
|
NIX_OUTPATH_USED_AS_RANDOM_SEED = "aaaaaaaaaa";
|
|
|
|
|
2024-05-01 16:37:03 +00:00
|
|
|
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;
|
|
|
|
})
|