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

Use new Cargo features & resolver to enable feature-based inclusion of crates #522

Merged

Conversation

kevinaboos
Copy link
Member

Previously, it was not easy to exclude application or kernel crates from a Theseus build. You had to either manually remove them from the set of workspace members or add it to the set of workspace excludes.

This PR introduces a dedicated crate used for specifying "global" features across all of the Theseus workspace, which allows one to specify crates that are optional in a Theseus build and thus use Cargo features to include them.
This works in cooperation with a default-members list, which species what subset of the members crates should be built by default when --all or --workspace is not passed to cargo build.

The current Makefile still builds all crates by default, which is done via the --workspace flag being the default CARGOFLAGS value if no other value for CARGOFLAGS is specified on the make command line invocation.

Thus, to actually use this new build functionality, you simply set CARGOFLAGS with the features corresponding to the optional crates you wish to build:

make CARGOFLAGS="--features 'feat1 feat2 feat3' "   ## spacing for emphasis

This would enable three features, feat1, feat2, and feat3, and the ensuing build would include four things:

  1. The nano_core and all of its dependencies
  2. The crate(s) selected by feat1 and all of it's dependencies
  3. The crate(s) selected by feat2 and all of it's dependencies
  4. The crate(s) selected by feat3 and all of it's dependencies

You can also just manually invoke cargo build --features <...> but then you'd also have to pass all of the other required arguments that Theseus's Makefile passes to cargo/rustc.

Shout-out to @epage for suggesting this technique. It's a bit hacky right now, but will continue to evolve as rust-lang/cargo#9094 progresses.

TODO: document this new cfg method in the Theseus book.

…central `theseus_config` crate that declares multiple Cargo-level features.
contents and make sure they properly match the `exclude` section of the
top-level `Cargo.toml`.

Also need to properly rename test applications and benchmark/eval
applications to be consistent. Even better is to place them directly in
`tests/` and `benchmarks/` folders, that way we can just have one
blanket `exlude` statement for both of them. Then, we also must add
those two new folders to the `APP_CRATE_NAMES` variable in the
`Makefile`.
@kevinaboos kevinaboos merged commit f0d212c into theseus-os:theseus_main Jun 7, 2022
@kevinaboos kevinaboos deleted the cargo_weak_dependencies branch June 7, 2022 17:13
github-actions bot pushed a commit that referenced this pull request Jun 7, 2022
… of crates (#522)

* Adds a dedicated `theseus_features` crate used for specifying "global" features across all of the Theseus workspace. This enables specifying which crates are optional in a Theseus build and thus which ones can be included via Cargo features. This works in cooperation with a `default-members` list, which species what subset of the members crates should be built by default when `--all` or `--workspace` is not passed to a `cargo build` invocation.

* Solves the previous problem of it being difficult to exclude application or kernel crates from a Theseus build. You had to either manually remove them from the set of workspace members or add it to the set of workspace excludes.

* By default, the current `Makefile` still builds all crates via the `--workspace` flag being the default `CARGOFLAGS` value when no other value for `CARGOFLAGS` is specified on the `make` command line invocation.

* To actually use this new build functionality, simply set `CARGOFLAGS` with the features corresponding to the optional crates you wish to build:
```
make CARGOFLAGS="--features 'feat1 feat2 feat3' "   ## spacing for emphasis
```
This enables three features, `feat1`, `feat2`, and `feat3`, and the ensuing build would include four things:

1. The nano_core and all of its dependencies
2. The crate(s) selected by feat1 and all of it's dependencies
3. The crate(s) selected by feat2 and all of it's dependencies
4. The crate(s) selected by feat3 and all of it's dependencies

* Note: you can also just manually invoke `cargo build --features <...>` but then you'd also have to pass all of the other required arguments that Theseus's Makefile passes to cargo/rustc. f0d212c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant