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

Target tab completion invokes rustup #12585

Closed
mkoncek opened this issue Aug 29, 2023 · 8 comments · Fixed by #12606
Closed

Target tab completion invokes rustup #12585

mkoncek opened this issue Aug 29, 2023 · 8 comments · Fixed by #12606
Assignees
Labels
A-completions Area: shell completions C-bug Category: bug E-easy Experience: Easy S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@mkoncek
Copy link

mkoncek commented Aug 29, 2023

Problem

Invoking cargo build --target <TAB> invokes rustup. Some environments may not have it installed and I do not see why it should be invoked if the tab completion can run equivalent of rustc --print target-list.

Steps

  1. Set up a basic Rust project with cargo
  2. Write cargo build --target on terminal and then press the TAB key.
  3. If rustup is not installed, terminal will print:
    cargo build --target bash: rustup: command not found

Possible Solution(s)

I suppose cargo could return the output of rustc --print target-list

Notes

It is generally a good idea to depend only on the most basic tools, especially if they get the job done right, like rustc does.

Version

cargo 1.71.0
release: 1.71.0
host: x86_64-unknown-linux-gnu
libgit2: 1.6.4 (sys:0.17.1 system)
libcurl: 8.0.1 (sys:0.4.61+curl-8.0.1 system ssl:OpenSSL/3.0.9)
os: Fedora 38.0.0 [64-bit]


<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_ASSIGN_START -->

<!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"Angelin01"}$$TRIAGEBOT_ASSIGN_DATA_END -->

<!-- TRIAGEBOT_ASSIGN_END -->
<!-- TRIAGEBOT_END -->
@mkoncek mkoncek added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Aug 29, 2023
@epage
Copy link
Contributor

epage commented Aug 29, 2023

Interesting, the zsh completions are using rustc --print target-list but the bash ones aren't.

zsh support for targets was added in #8740

bash support was added in #6640

I don't see any references to why different strategies were taken, so it seems like we could consolidate down to just rustc

@epage epage added A-completions Area: shell completions E-easy Experience: Easy S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review and removed S-triage Status: This issue is waiting on initial triage. labels Aug 29, 2023
@weihanglo
Copy link
Member

Another idea is we can go with rustup way first and fall back to rustc --print target-list.

@epage
Copy link
Contributor

epage commented Aug 29, 2023

Is there a reason to prefer rustup? I guess so you can check which targets are actually installed?

@weihanglo
Copy link
Member

Yes. Completing with installed ones. rustc --print target-list now prints 218 target triples which doesn't sounds too friendly.

@epage
Copy link
Contributor

epage commented Aug 29, 2023

Yeah, making both do rustup and then fallback seems like the ideal

@mkoncek
Copy link
Author

mkoncek commented Aug 29, 2023

By the way, in Fedora, the programmer does not have access to packaged rustup, but instead is supposed to install one of the additional rust-std-static-* packages (see: https://koji.fedoraproject.org/koji/buildinfo?buildID=2278881). But I don't think the upstream Rust project can / should / wants to detect such cases.

@Angelin01
Copy link
Contributor

I can probably whip this up by tomorrow, already have the bash one ready, just need to do some testing with the ZSH one.

@Angelin01
Copy link
Contributor

@rustbot claim

@bors bors closed this as completed in 11966a4 Aug 31, 2023
bors added a commit that referenced this issue Aug 31, 2023
fix(cli): Help users know possible `--target` values

### What does this PR try to resolve?

I was needing to do some more cross-compilation and forgot what the target triple was that I needed to run.  I realized i had to re-remember the command yet again.   Especially with #12585 in memory, I realized that `--target` isn't working like `--package` and other arguments that can report supported values.

In working on it, I realized I probably didn't want to report supported values yet out of concern for how big the list is (see also #12585), so I decided to just list the relevant commands for now.  We *might* be able to parse the rustup output to report those targets but I didn't receive a glowing endorsement from the rustup team about parsing the list (more of "yes, hyrums law and at least its interactive rather than CI").

Before:
```
error: a value is required for '--target <TRIPLE>' but none was supplied

For more information, try '--help'.
```

After:
```
error: "--target" takes a target architecture as an argument.

Run `rustup target list` to see possible targets.
```
(quotes were used because the other "list available" use them, we should probably work to be uniform in how we quote)

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

First PR adds a test showing the existing output and then through the rest you can see how the output changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completions Area: shell completions C-bug Category: bug E-easy Experience: Easy S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants