From d796fe7cd32b6ff12906092a4a013cfb4cfe634a Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Wed, 1 May 2024 00:38:55 -0700 Subject: [PATCH] make it easy to configure cargo features from nix Users of the nix package can now just use `.override` to choose what features they want. This also makes RocksDB automatically use jemalloc when Conduit is configured to use jemalloc. --- nix/pkgs/default/default.nix | 49 +++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/nix/pkgs/default/default.nix b/nix/pkgs/default/default.nix index 75c87b42..38771517 100644 --- a/nix/pkgs/default/default.nix +++ b/nix/pkgs/default/default.nix @@ -1,4 +1,4 @@ -# Keep sorted +# Dependencies (keep sorted) { craneLib , inputs , lib @@ -6,23 +6,34 @@ , rocksdb , rust , stdenv + +# Options (keep sorted) +, default-features ? true +, features ? [] }: let - env = { - CONDUIT_VERSION_EXTRA = inputs.self.shortRev or inputs.self.dirtyShortRev; - ROCKSDB_INCLUDE_DIR = "${rocksdb}/include"; - ROCKSDB_LIB_DIR = "${rocksdb}/lib"; - } - // - (import ./cross-compilation-env.nix { - # Keep sorted - inherit - lib - pkgsBuildHost - rust - stdenv; - }); + env = + let + rocksdb' = rocksdb.override { + enableJemalloc = builtins.elem "jemalloc" features; + }; + in + { + CONDUIT_VERSION_EXTRA = + inputs.self.shortRev or inputs.self.dirtyShortRev; + ROCKSDB_INCLUDE_DIR = "${rocksdb'}/include"; + ROCKSDB_LIB_DIR = "${rocksdb'}/lib"; + } + // + (import ./cross-compilation-env.nix { + # Keep sorted + inherit + lib + pkgsBuildHost + rust + stdenv; + }); in craneLib.buildPackage rec { @@ -44,6 +55,14 @@ craneLib.buildPackage rec { ]; }; + cargoExtraArgs = "--locked " + + lib.optionalString + (!default-features) + "--no-default-features " + + lib.optionalString + (features != []) + "--features " + (builtins.concatStringsSep "," features); + # This is redundant with CI doCheck = false;