2024-05-01 18:37:03 +02:00
|
|
|
# Dependencies (keep sorted)
|
|
|
|
{ craneLib
|
|
|
|
, inputs
|
2024-04-22 00:28:35 +02:00
|
|
|
, lib
|
|
|
|
, libiconv
|
|
|
|
, pkgsBuildHost
|
|
|
|
, rocksdb
|
|
|
|
, rust
|
2024-05-23 22:32:43 +02:00
|
|
|
, rust-jemalloc-sys
|
2024-04-22 00:28:35 +02:00
|
|
|
, stdenv
|
|
|
|
|
2024-05-01 18:37:03 +02:00
|
|
|
# Options (keep sorted)
|
2024-04-25 04:51:19 +02:00
|
|
|
, default_features ? true
|
2024-05-24 01:18:50 +02:00
|
|
|
, all_features ? false
|
2024-04-22 00:28:35 +02:00
|
|
|
, features ? []
|
|
|
|
, profile ? "release"
|
|
|
|
}:
|
|
|
|
|
2024-05-01 18:37:03 +02:00
|
|
|
let
|
2024-05-24 00:11:06 +02:00
|
|
|
# We perform default-feature unification in nix, because some of the dependencies
|
|
|
|
# on the nix side depend on feature values.
|
|
|
|
workspaceMembers = builtins.map (member: "${inputs.self}/src/${member}")
|
|
|
|
(builtins.attrNames (builtins.readDir "${inputs.self}/src"));
|
2024-05-24 01:18:50 +02: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-24 00:11:06 +02:00
|
|
|
crateDefaultFeatures = path:
|
|
|
|
(lib.importTOML "${path}/Cargo.toml").features.default;
|
|
|
|
allDefaultFeatures = lib.unique
|
|
|
|
(lib.flatten (builtins.map crateDefaultFeatures workspaceMembers));
|
2024-05-24 01:18:50 +02:00
|
|
|
allFeatures = lib.unique
|
|
|
|
(lib.flatten (builtins.map crateFeatures workspaceMembers));
|
2024-05-24 00:11:06 +02:00
|
|
|
features' = lib.unique
|
|
|
|
(features ++
|
2024-05-24 01:18:50 +02:00
|
|
|
lib.optionals default_features allDefaultFeatures ++
|
|
|
|
lib.optionals all_features allFeatures);
|
2024-05-24 00:11:06 +02:00
|
|
|
|
|
|
|
featureEnabled = feature : builtins.elem feature features';
|
2024-05-23 22:32:43 +02: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 18:37:03 +02:00
|
|
|
buildDepsOnlyEnv =
|
|
|
|
let
|
2024-05-24 05:12:50 +02:00
|
|
|
rocksdb' = (rocksdb.override {
|
2024-05-23 22:32:43 +02:00
|
|
|
jemalloc = rust-jemalloc-sys';
|
2024-05-24 05:06:00 +02: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 05:12:50 +02: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-05-01 18:37:03 +02: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-22 00:28:35 +02:00
|
|
|
|
2024-05-01 18:37:03 +02:00
|
|
|
buildPackageEnv = {
|
2024-04-27 03:38:29 +02:00
|
|
|
CONDUWUIT_VERSION_EXTRA = inputs.self.shortRev or inputs.self.dirtyShortRev or "";
|
2024-05-01 18:37:03 +02: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-22 00:28:35 +02:00
|
|
|
|
2024-05-01 18:37:03 +02:00
|
|
|
# Keep sorted
|
|
|
|
include = [
|
|
|
|
"Cargo.lock"
|
|
|
|
"Cargo.toml"
|
2024-05-10 00:59:08 +02:00
|
|
|
"deps"
|
2024-05-01 18:37:03 +02:00
|
|
|
"src"
|
|
|
|
];
|
|
|
|
};
|
2024-04-22 00:28:35 +02:00
|
|
|
|
2024-05-23 22:32:43 +02:00
|
|
|
buildInputs = lib.optional (featureEnabled "jemalloc") rust-jemalloc-sys';
|
|
|
|
|
2024-05-01 18:37:03 +02: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-22 00:28:35 +02:00
|
|
|
]
|
2024-05-12 07:13:23 +02:00
|
|
|
++ lib.optionals stdenv.isDarwin [
|
2024-05-12 05:30:37 +02:00
|
|
|
# https://github.com/NixOS/nixpkgs/issues/206242
|
2024-05-12 07:13:23 +02:00
|
|
|
libiconv
|
|
|
|
|
2024-05-12 05:30:37 +02: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 07:13:23 +02:00
|
|
|
pkgsBuildHost.darwin.apple_sdk.frameworks.Security
|
|
|
|
];
|
2024-05-01 18:37:03 +02:00
|
|
|
};
|
|
|
|
in
|
|
|
|
|
|
|
|
craneLib.buildPackage ( commonAttrs // {
|
|
|
|
cargoArtifacts = craneLib.buildDepsOnly (commonAttrs // {
|
|
|
|
env = buildDepsOnlyEnv;
|
|
|
|
});
|
2024-04-22 00:28:35 +02:00
|
|
|
|
2024-05-24 00:11:06 +02:00
|
|
|
cargoExtraArgs = "--no-default-features "
|
2024-04-25 04:51:19 +02:00
|
|
|
+ lib.optionalString
|
2024-05-24 00:11:06 +02:00
|
|
|
(features' != [])
|
|
|
|
"--features " + (builtins.concatStringsSep "," features');
|
2024-04-22 00:28:35 +02:00
|
|
|
|
2024-05-03 09:35:36 +02:00
|
|
|
# This is redundant with CI
|
|
|
|
cargoTestCommand = "";
|
2024-05-12 05:31:10 +02:00
|
|
|
cargoCheckCommand = "";
|
2024-05-01 18:37:03 +02:00
|
|
|
doCheck = false;
|
|
|
|
|
2024-05-03 18:05:01 +02:00
|
|
|
# https://crane.dev/faq/rebuilds-bindgen.html
|
|
|
|
NIX_OUTPATH_USED_AS_RANDOM_SEED = "aaaaaaaaaa";
|
|
|
|
|
2024-05-01 18:37:03 +02:00
|
|
|
env = buildPackageEnv;
|
2024-04-22 00:28:35 +02:00
|
|
|
|
|
|
|
passthru = {
|
2024-05-01 18:37:03 +02:00
|
|
|
env = buildPackageEnv;
|
2024-04-22 00:28:35 +02:00
|
|
|
};
|
2024-05-01 18:37:03 +02:00
|
|
|
|
|
|
|
meta.mainProgram = commonAttrs.pname;
|
2024-05-24 05:40:29 +02:00
|
|
|
# Dynamically-linked jemalloc is broken on linux due to link-order problems,
|
|
|
|
# where the symbols are being resolved to libc malloc/free before jemalloc is
|
|
|
|
# loaded. This problem does not occur on darwin for unknown reasons.
|
|
|
|
meta.broken =
|
|
|
|
stdenv.isLinux &&
|
|
|
|
!stdenv.hostPlatform.isStatic &&
|
|
|
|
(featureEnabled "jemalloc");
|
2024-05-01 18:37:03 +02:00
|
|
|
})
|