From 188dea13e08a219925bf3ba87ea20a06792a0ea6 Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Thu, 23 May 2024 15:11:06 -0700 Subject: [PATCH] do default-feature unification in nix Some of the features affect nix dependencies, so we need to have a full feature list available when constructing the nix derivation. This incidentally fixes the bug where we weren't enabling jemalloc on rocksdb in CI/devshells, because jemalloc is now a default feature. It does not fix the more general class of that issue, where CI is performing an `--all-features` build in a nix devshell built for default-features. I am now passing `--no-default-features` to cargo, and having it use our unified feature list rather than duplicating the unification inside cargo. --- nix/pkgs/main/default.nix | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/nix/pkgs/main/default.nix b/nix/pkgs/main/default.nix index e4873e42..9eba2a87 100644 --- a/nix/pkgs/main/default.nix +++ b/nix/pkgs/main/default.nix @@ -16,7 +16,19 @@ }: let -featureEnabled = feature : builtins.elem feature features; +# 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")); +crateDefaultFeatures = path: + (lib.importTOML "${path}/Cargo.toml").features.default; +allDefaultFeatures = lib.unique + (lib.flatten (builtins.map crateDefaultFeatures workspaceMembers)); +features' = lib.unique + (features ++ + lib.optionals default_features allDefaultFeatures); + +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 @@ -102,13 +114,10 @@ craneLib.buildPackage ( commonAttrs // { env = buildDepsOnlyEnv; }); - cargoExtraArgs = "" + cargoExtraArgs = "--no-default-features " + lib.optionalString - (!default_features) - "--no-default-features " - + lib.optionalString - (features != []) - "--features " + (builtins.concatStringsSep "," features); + (features' != []) + "--features " + (builtins.concatStringsSep "," features'); # This is redundant with CI cargoTestCommand = "";