-
Notifications
You must be signed in to change notification settings - Fork 86
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
Optional crate unavailable #18
Comments
Thank you very much for reporting this! Usually build errors are due to differences in the |
cargo
crate2nix
cargo (interesting)
crate2nix (interesting)
cargo passes |
It seems that I ran same problem. I think the reason is that When no feature options are given, the default feature is activated for every selected package. In my case I could solve the problem by having diff --git a/src/lib.rs b/src/lib.rs
index 5104267..f7eb976 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -10,6 +10,7 @@ use std::env;
use std::path::PathBuf;
use cargo_metadata::Metadata;
+use cargo_metadata::CargoOpt;
use cargo_metadata::PackageId;
use failure::format_err;
use failure::Error;
@@ -121,6 +122,7 @@ impl BuildInfo {
/// Call `cargo metadata` and return result.
fn cargo_metadata(config: &GenerateConfig) -> Result<Metadata, Error> {
let mut cmd = cargo_metadata::MetadataCommand::new();
+ cmd.features(CargoOpt::AllFeatures);
cmd.manifest_path(&config.cargo_toml);
cmd.exec().map_err(|e| {
format_err!( I could submit a proper PR, but maybe you (@tilpner) could test if this fixes the problem in your case as well? |
This is a different issue than the one that I was encountering. The issue here is that in the output of {
"name": "miniz_oxide",
"source": "registry+https://github.com/rust-lang/crates.io-index",
"req": "^0.3.2",
"kind": null,
"rename": null,
"optional": true,
"uses_default_features": true,
"features": [],
"target": null,
"registry": null
},
[...]
{
"name": "miniz_oxide",
"source": "registry+https://github.com/rust-lang/crates.io-index",
"req": "^0.3.2",
"kind": null,
"rename": null,
"optional": false,
"uses_default_features": true,
"features": [],
"target": "cfg(all(target_arch = \"wasm32\", not(target_os = \"emscripten\")))",
"registry": null
} So, the logic seems to be: [dependencies]
[...]
miniz_oxide = { version = "0.3.2", optional = true}
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
miniz_oxide = "0.3.2" The output generated by dependencies = {
"crc32fast" = "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)"
;
"libc" = "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)";
"miniz_oxide" = {
packageId = "miniz_oxide 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)";
target = ((target."arch" == "wasm32") && (!(target."os" == "emscripten")));
};
}; So, |
This is related to nix-community/crate2nix#18
Fixes issue nix-community#18 This allows for multiple dependencies with different targets. Before this there was an issue with the flate2 crate which had dependencies: [dependencies] [...] miniz_oxide = { version = "0.3.2", optional = true} [target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies] miniz_oxide = "0.3.2" but the generated Cargo.nix would only contain the targeted version: "miniz_oxide" = { packageId = "miniz_oxide 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)"; target = ((target."arch" == "wasm32") && (!(target."os" == "emscripten"))); }; which means that miniz_oxide would not match for non-wasm32 targets, even if it was enabled via a feature. Now the dependency appears twice: { name = "miniz_oxide"; packageId = "miniz_oxide 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)"; optional = true; } { name = "miniz_oxide"; packageId = "miniz_oxide 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)"; target = ((target."arch" == "x86_64")); } so it will match when the target matches or when the feature is enabled.
I have the same problem (and created a duplicate issue, shame on me). Here's my testcase (almost the same as your's) and my build output: Update: On the Build output
Edit:
|
This should now work on master... |
This is related to nix-community/crate2nix#18
Are there plans to make a new release containing these changes or should we just use the potentially unstable |
I plan to release very soon from Master. So you can do both.
Valentin Brandl <[email protected]> schrieb am Fr., 14. Feb. 2020,
12:54:
… Are there plans to make a new release containing these changes or should
we just use the potentially unstable master branch?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#18>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACS3GSAVC3U5MRARJ2FWRTRC2A6HANCNFSM4IPMXW2Q>
.
|
Testcase here
Builds with cargo, not with crate2nix
The text was updated successfully, but these errors were encountered: