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

RFC: Add example of cargo add #3331

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

buggymcbugfix
Copy link

@buggymcbugfix buggymcbugfix commented Aug 28, 2022

Hi! I'm working through the Rust Book for the first time and I noticed that Cargo supports cargo add now. Maybe worth adding that to the book?

Progress

  • Add example for how to use cargo add to add the rand dependency in chapter 2
    - [ ] Re-number the no-listings so they appear in chronological order (haven't done this yet to minimise the diff for the RFC phase)
    - [ ] Explain what the output means (help, I don't know what the Features part means, it's not explained in the Cargo documentation)
    - [ ] Make a mention of the minimal Cargo version that supports this?
  • Update the Cargo documentation to explain what the Features output means.

@carols10cents carols10cents added this to the ch1 milestone Aug 29, 2022
@carols10cents
Copy link
Member

Hi! Thank you so much for this! I'm definitely into this, with one caveat: I'm working on a new print version of the book right now that won't include this, so I'm not going to merge this for the online version until I finish that in a few weeks or months.

I'm also very impressed that you've successfully figured out how to work with my convoluted listing management!!!

I actually haven't had a chance to use cargo add yet. It's really important that what ends up in Cargo.toml is rand = "0.8.3". I can't tell for sure, but based on the Cargo.lock in this PR, it looks like cargo add [email protected] ends up putting rand = "=0.8.3" in Cargo.toml? That's too strict for what the text is illustrating-- I do want the reader to get 0.8.5 since that has been released.

Is there a different cargo add syntax that will result in rand = "0.8.3" in Cargo.toml?

Re-number the no-listings so they appear in chronological order (haven't done this yet to minimise the diff for the RFC phase)

I'd prefer this in a separate PR, if you do it at all-- it's not a huge deal for me!

Explain what the output means (help, I don't know what the Features part means, it's not explained in the Cargo documentation)

It looks like it's printing the Cargo features available from the crate just added. Sounds like you could send in a cargo add doc PR too if you want!

Make a mention of the minimal Cargo version that supports this?

The minimal Rust version is mentioned in the title page, so I don't think it's necessary to reiterate here.

@buggymcbugfix
Copy link
Author

It's really important that what ends up in Cargo.toml is rand = "0.8.3". I can't tell for sure, but based on the Cargo.lock in this PR, it looks like cargo add [email protected] ends up putting rand = "=0.8.3" in Cargo.toml? That's too strict for what the text is illustrating-- I do want the reader to get 0.8.5 since that has been released.

My bad, I cargo-culted the lockfile from one of the other no-listings where the lockfile has 0.8.3. I just tried again and I can confirm it does what you want: cargo add [email protected] adds rand = "0.8.3" in the Cargo.toml, which gets resolved to 0.8.5 for me.

I'd prefer this in a separate PR, if you do it at all-- it's not a huge deal for me!

No, I don't mind at all, I thought it might be confusing for others if I don't "defragment" :)

It looks like it's printing the Cargo features available from the crate just added.

Ah, cool, thanks!

bors added a commit to rust-lang/cargo that referenced this pull request Aug 30, 2022
…epage

Very slight `cargo add` documentation improvements

As discussed in rust-lang/book#3331, a quick explanation of the `Features` part of the message that gets printed to stdout when adding some dependency.

Consider the following example:

```
cargo add my-crate
    Updating crates.io index
      Adding my-crate v0.1.0 to dependencies.
             Features:
             + foo
             - bar
```

It was not clear to me what `+foo` and `-bar` meant until `@carols10cents'` kindly explained it to me. Hopefully the documentation now clarifies this.

TODO:

- [x] Run `./build-man.sh`
@chriskrycho
Copy link
Contributor

@buggymcbugfix are you interested in pulling this apart into the relevant PRs and landing it? If not, I will also take care of that as part of the prep for the next print edition, but I wanted to give you the opportunity if you’d like to do it!

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.

3 participants