Skip to content

Ability to build a crate with the features selected by another crate #9696

@Manishearth

Description

@Manishearth

Problem

Let's say you have a workspace that contains a library (library) and some tooling (tool). Something like this. You want the library to support no_std, but the tooling does not. (In general, this isn't specific to tooling, perhaps a subset of your workspace supports no_std)

One would expect that building library for a baremetal target would work (and build serde with no_std), and building the entire workspace or tool for a baremetal target would not. Furthermore, it's common to use cargo build -p serde to just build serde; and it's useful if it builds the serde that-would-be-built-by-running-cargo build-in-the-same-folder, because it helps for things like incrementally getting dependencies to work with no_std.

This is indeed how it works on resolver = "1", note that cargo check and cargo check -p serde both succeed from the library folder, but not the root folder:

Details
[10:09:15] à€®anishearth@manishearth-glaptop ~/sand/workspace-test/library ^_^ 
$ cargo check --target thumbv7m-none-eabi
(succeeds)
[10:09:22] à€®anishearth@manishearth-glaptop ~/sand/workspace-test/library ^_^ 
$ cargo check --target thumbv7m-none-eabi -p serde
(succeeds)
[10:09:27] à€®anishearth@manishearth-glaptop ~/sand/workspace-test/library ^_^ 
$ cd ..
[10:09:29] à€®anishearth@manishearth-glaptop ~/sand/workspace-test ^_^ 
$ cargo check --target thumbv7m-none-eabi 
(fails)
[10:09:33] à€®anishearth@manishearth-glaptop ~/sand/workspace-test O_o 
$ cargo check --target thumbv7m-none-eabi  -p serde
(fails)

However, with resolver = "2", cargo check succeeds in the library folder, but not cargo check -p serde:

Details
[10:45:55] à€®anishearth@manishearth-glaptop ~/sand/workspace-test/library ^_^ 
$ cargo check --target thumbv7m-none-eabi 
(succeeds)
[10:45:58] à€®anishearth@manishearth-glaptop ~/sand/workspace-test/library ^_^ 
$ cargo check --target thumbv7m-none-eabi  -p serde
(fails)
[10:46:02] à€®anishearth@manishearth-glaptop ~/sand/workspace-test/library ^_^ 
$ cd ..
[10:46:03] à€®anishearth@manishearth-glaptop ~/sand/workspace-test ^_^ 
$ cargo check --target thumbv7m-none-eabi 
(fails)
[10:46:05] à€®anishearth@manishearth-glaptop ~/sand/workspace-test O_o 
$ cargo check --target thumbv7m-none-eabi  -p serde
(fails)

This seems a bit counterintuitive to me: the new resolver is intended to reduce this kind of problem. It would be nice if the old behavior still worked here, and this seems like a regression to me.

Steps

  1. Check out https://github.com/Manishearth/cargo-resolver-bug
  2. Uncomment the resolver = "2" line in Cargo.toml
  3. Install some no_std target (I'm using thumbv7m-none-eabi). You can alternatively use -v in the build commands to check if serde is built with std enabled
  4. cd library && cargo check --target thumbv7m-none-eabi -p serde

Notes

Output of cargo version:

$ cargo version
cargo 1.55.0-nightly (9233aa06c 2021-06-22)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-featuresArea: features — conditional compilationC-bugCategory: bugS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions