Skip to content

Show the merged set of activated features to the user when inheriting… #1

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

Merged
merged 1 commit into from
Apr 25, 2022

Conversation

@Muscraft Muscraft assigned Muscraft and unassigned Muscraft Apr 25, 2022
Comment on lines 118 to 120
req_feats
.difference(&available_features)
.for_each(|unknown| unknown_features.push(unknown.to_string()));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a unknown_features.extend(req_feats.different(...)) would b clearer than the for_each approach

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you run into issues with &&str not living long enough. You can transition things to String but then you introduce .to_string() and .clone()

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try unknown_features.extend(req_feats.different(...).copied())

Comment on lines 680 to 675
let mut workspace: IndexSet<_> = dep
.inherited_features
.iter()
.flatten()
.map(|s| s.as_str())
.filter(|s| !activated.contains(s))
.collect();
workspace.sort();
let mut deactivated = dep
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't recursively activate features.

Instead add this into activated before we do the VecDeque and the rest of the code should just work out

Comment on lines 704 to 689
for feat in workspace {
shell.write_stderr(&prefix, &ColorSpec::new())?;
shell.write_stderr('+', &ColorSpec::new().set_bold(true).set_fg(Some(Green)))?;
shell.write_stderr(format_args!(" {}\n", feat), &ColorSpec::new())?;
}
for feat in deactivated {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't sorting the workspace features in with the regular ones and will look confusing.

If you merge into the activated features, this shouldn't be needed anymore

Comment on lines 5 to 7
[features]
test = []
merge = []
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to

[features]
default-base = []
default-test-base = []
default-merge-base = []
default = ["default-base", "default-test-base", "default-merge-base"]
test-base = []
test = ["test-base", "default-test-base"]
merge-base = []
merge = ["merge-base", "default-merge-base"]
unrelated = []

This will

  • Show we recursively activate all
  • Don't duplicate activations
  • Don't just enable everything :)

@@ -152,6 +155,13 @@ impl Dependency {
self
}

/// Set features as an array of string (does some basic parsing)
#[allow(dead_code)]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this dead_code?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I just copied this from above. I'll remove it

@Muscraft Muscraft force-pushed the merged-activated-features branch from 02a5439 to 55cf27e Compare April 25, 2022 21:39
@Muscraft Muscraft merged this pull request into cargo-add-support Apr 25, 2022
bors added a commit to rust-lang/cargo that referenced this pull request Apr 28, 2022
Cargo add support for workspace inheritance

Tracking issue: #8415
RFC: rust-lang/rfcs#2906

This PR adds all the required support for workspace inheritance within `cargo-add`. It was split up across a few different PRs as it required `snapbox` support from #10581 and a new `toml_edit` version from #10603. `@epage` and I decided to go ahead with this PR and add in some of the changes those PRs made. `@epage's` name on the commits is from helping to rewrite commits and some very minor additions.

Changes:
  - #10585
  - Muscraft#1
  - Muscraft#3
  - Muscraft#2
  - Muscraft#4

r? `@epage`
@Muscraft Muscraft deleted the merged-activated-features branch May 27, 2022 01:15
Muscraft pushed a commit that referenced this pull request Dec 14, 2023
Muscraft pushed a commit that referenced this pull request Apr 27, 2025
…st-lang#15405)

Resolves rust-lang#15401

Here is an example of the feature in
[kitty](https://sw.kovidgoyal.net/kitty/) `0.40.1` with the following
config set in `~/.config/kitty/kitty.conf`

```conf
underline_hyperlinks always
show_hyperlink_targets yes
allow_hyperlinks yes
# ...
```

![cargo-target-file-hyperlik-kitty-showcase](https://github.com/user-attachments/assets/04155d5a-a254-4e80-a35e-a02cc4671ae4)

Tested on `uname -a`:
```
Linux nixos 6.14.0 #1-NixOS SMP PREEMPT_DYNAMIC Mon Mar 24 14:02:41 UTC 2025 x86_64 GNU/Linux
```
Terminals tested with:
- [x] [kitty](https://sw.kovidgoyal.net/kitty/) `0.40.1`
- [x] [ghostty](https://ghostty.org/) `1.1.4-6f1b22a-nix`

![image](https://github.com/user-attachments/assets/afeb250f-009b-429a-8854-6c3053449f9e)
- [x] [alacritty](https://alacritty.org/index.html) `0.15.1`

![image](https://github.com/user-attachments/assets/9742cd72-13e5-4e90-8ece-dd101553e5cc)

- [x] VScode's version `1.98` integrated terminal aka.
[xterm.js](https://xtermjs.org/)

![image](https://github.com/user-attachments/assets/f02ce77a-18e4-47dd-b428-7b82bc013021)

The following `cargo` invocations will have their output be modified by
this change:
```shell
cargo run # If multiple binaries are defined in the manifest and [package.default-bin] is not defined
cargo run --bin
cargo run --example
cargo run --package
cargo build --bin
cargo build --example
cargo build --package
cargo test --test
cargo test --bench
```

In addition I have done a slight refactor to have the printed indent of
targets and packages be the same by using a shared constant named `const
ITEM_INDENT: &str = " ";`

This is my first PR to the cargo codebase, so I am not familiar with
what is expected in terms of test for a feature such as this.

<!--
Thanks for submitting a pull request 🎉! Here are some tips for you:

* If this is your first contribution, read "Cargo Contribution Guide"
first:
  https://doc.crates.io/contrib/
* Run `cargo fmt --all` to format your code changes.
* Small commits and pull requests are always preferable and easy to
review.
* If your idea is large and needs feedback from the community, read how:
  https://doc.crates.io/contrib/process/#working-on-large-features
* Cargo takes care of compatibility. Read our design principles:
  https://doc.crates.io/contrib/design.html
* When changing help text of cargo commands, follow the steps to
generate docs:

https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages
* If your PR is not finished, set it as "draft" PR or add "WIP" in its
title.
* It's ok to use the CI resources to test your PR, but please don't
abuse them.

### What does this PR try to resolve?

Explain the motivation behind this change.
A clear overview along with an in-depth explanation are helpful.

You can use `Fixes #<issue number>` to associate this PR to an existing
issue.

### How should we test and review this PR?

Demonstrate how you test this change and guide reviewers through your
PR.
With a smooth review process, a pull request usually gets reviewed
quicker.

If you don't know how to write and run your tests, please read the
guide:
https://doc.crates.io/contrib/tests

### Additional information

Other information you want to mention in this PR, such as prior arts,
future extensions, an unresolved problem, or a TODO list.
-->
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.

2 participants