Skip to content
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

crate2nix attempts to build binaries without their target-specific required-features #129

Open
JJJollyjim opened this issue Apr 23, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@JJJollyjim
Copy link

JJJollyjim commented Apr 23, 2020

For example, try generating and building https://github.com/aahancoc/tree_magic/tarball/0.2.3

The binary fails to build since it can't find clap. Here's the relevant Cargo.toml snippet:

[features]
cli = ["clap", "tabwriter", "scoped_threadpool", "walkdir", "num_cpus"]
# ...
default = []

[lib]
crate-type = ["lib"]
path = "src/lib.rs"

[[bin]]
required-features = ["cli"]
name = "tmagic"
path = "src/main.rs"

And here's the diffedDefaultPackageFeatures:

{
  "differentFeatures": {},
  "onlyInCargo": [
    "ansi_term",
    "atty",
    "bitflags",
    "clap",
    "cloudabi",
    "hermit-abi",
    "num_cpus",
    "redox_syscall",
    "same-file",
    "scoped_threadpool",
    "strsim",
    "tabwriter",
    "textwrap",
    "unicode-width",
    "vec_map",
    "walkdir",
    "winapi",
    "winapi-i686-pc-windows-gnu",
    "winapi-util",
    "winapi-x86_64-pc-windows-gnu"
  ],
  "onlyInCrate2Nix": []
}

Thanks :)

@kolloch kolloch added the enhancement New feature or request label Apr 23, 2020
@kolloch
Copy link
Collaborator

kolloch commented Apr 23, 2020

Thank you for the report!

Oh, yeah, at a first glance, I'd say this is unsupported. I was unaware of this feature. Target-specific features. Makes sense. ;)

You can probably workaround this limitation easily by enabling the relevant features at the build root manually:

https://github.com/kolloch/crate2nix#dynamic-feature-resolution

Tell me if that works for you!

@JJJollyjim
Copy link
Author

Yep, the workaround definitely works :)

I've now properly investigated Cargo's default behavior (I assumed it would automatically enable the feature), but it turns out to match crate2nix pretty well, except with a nice error instead of attempting to build:

$ cargo build --bin=tmagic
error: target `tmagic` in package `tree_magic` requires the features: `cli`
Consider enabling them by passing, e.g., `--features="cli"`

Or, using cargo install

$ cargo install tree_magic
    Updating crates.io index
  Installing tree_magic v0.2.3
   Compiling libc v0.2.69
   Compiling autocfg v1.0.0
   Compiling smallvec v1.4.0
   Compiling cfg-if v0.1.10
   Compiling scopeguard v1.1.0
   Compiling fixedbitset v0.2.0
   Compiling fnv v1.0.6
   Compiling lazy_static v1.4.0
   Compiling indexmap v1.3.2
   Compiling lock_api v0.3.4
   Compiling petgraph v0.5.0
   Compiling parking_lot_core v0.7.2
   Compiling memchr v1.0.2
   Compiling nom v3.2.1
   Compiling parking_lot v0.10.2
   Compiling tree_magic v0.2.3
    Finished release [optimized] target(s) in 9.81s
error: no binaries are available for install using the selected features

@kolloch
Copy link
Collaborator

kolloch commented Apr 25, 2020

Ah, OK, if we copied this behavior:

  • we'd skip building binaries for which we haven't enabled the required features,
  • fail with an error if there is nothing to build (we really should do that anyways!).

@yusdacra
Copy link
Member

yusdacra commented Dec 12, 2020

I encountered this issue while I was performing usual Cargo.nix regeneration on the Veloren project. The suggested workaround did not work for me, so I resorted to manually commenting the optional = true; from the relevant dependencies as a workaround. I'd like to fix this issue in crate2nix, but I'm not sure where to start, so some pointers would be great :D

EDIT: The cargo behaviour can be reproduced on the master branch currently by running cargo build --bin=csv_export.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants