-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Features fail to contain optional dependencies that got enabled indirectly #146
Comments
Hmmm, it is a bit weird because there is even a unit test for something very similar: "pkg_num" = {
crateName = "num";
dependencies = [
{
name = "num-bigint";
packageId = "pkg_num_bigint";
usesDefaultFeatures = false;
optional = true;
}
];
features = {
"default" = [ "std" ];
"std" = [ "num-bigint/std" ];
};
}; |
When Cargo see For more detail, please see #165. |
Is there any work-around for this or planned work? I am hitting this exact issue on this exact crate. |
For us, I did something like this: cargoNix = pkgs.callPackage ./nix/Cargo.nix {
inherit nixpkgs;
buildRustCrate = null;
defaultCrateOverrides = pkgs.defaultCrateOverrides // {
num-rational = attrs:
attrs // {
# https://github.com/kolloch/crate2nix/issues/146
features = attrs.features ++ [ "num-bigint" ];
};
}; |
When Cargo sees a dependency feature `opt_crate/feat` for an optional dependency `opt_crate`, it implicitly adds `opt_crate` to the feature set for the current crate. For example, `num-rational` crate relies on this behavior for importing `num-bigint`, which is optional. This patch lets crate2nix mimic this behavior. Closes nix-community#146 and nix-community#182.
When Cargo sees a dependency feature `opt_crate/feat` for an optional dependency `opt_crate`, it implicitly adds `opt_crate` to the feature set for the current crate. For example, `num-rational` crate relies on this behavior for importing `num-bigint`, which is optional. This patch lets crate2nix mimic this behavior. Closes #146 and #182.
Consider the following Cargo.toml:
It currently fails to build despite succeeding with cargo. The reason is because when
crate2nix
is buildingnum-rational
it somehow drops the feature for an optionalnum-bigint
dependency. This optional dependency ends up being enabled indirectly, throughnum
depending on bothnum-rational
andnum-bigint
.Both
cargo metadata
and the generatedCargo.nix
containsnum-bigint
in theresolvedDefaultFeatures
:But the final invocation of
buildRustCrate
ends up not being provided the feature in the end. And sonum-rational
is compiled without a--cfg feature="num-bigint"
flag.I admit that this is the first time I’m reading templates/nix/crate2nix/default.nix at all seriously, but from what I can tell it just throws away the information
cargo
already computed and attempts to compute its own feature sets. Is that correct? Why?The text was updated successfully, but these errors were encountered: