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

Add cargo-add (from cargo-edit) to cargo proper #5586

Open
killercup opened this issue May 28, 2018 · 15 comments

Comments

@killercup
Copy link
Member

commented May 28, 2018

Cargo as well as cargo-edit have gone a long way since #4 was opened. It might now make sense to move (parts of) cargo-edit into cargo itself. Basically, we now have a format-preserving TOML library that -- at least for adding a dependency line -- work quite well (you can test this with cargo install cargo-edit --vers 0.3.0-beta.1 -f).

Speaking with @matklad, I believe I now have a somewhat solid understanding of what needs to happen to add a new built-in cargo subcommand. One important realization was that cargo-install already contains some of the parts we need.

Here are some steps to get started:

  1. Create a src/bin/cargo/commands/add.rs (as duplicate of install.rs at first)
  2. In src/bin/cargo/commands/mod.rs, add add to builtin/builtin_exec, and to the list of mods
  3. Create a src/bin/cargo/ops/cargo_add.rs (as duplicate of cargo_install.rs at first)

One thing we should aim for though, is to now just copy-paste the whole of cargo-edit but to re-use as much of cargo's infrastructure as possible. For example, we should try to use cargo's way of querying the registry as well as its CLI args handling and output formatting. We can, for example, also use args.workspace.current_manifest to get the manifest and deal with workspace.

@killercup

This comment has been minimized.

Copy link
Member Author

commented May 28, 2018

@rust-lang/cargo, is this something you'd be interested in being worked on right now? This might work as a mentored even if you can't spend much time to work on it ourselves.

@alexcrichton

This comment has been minimized.

Copy link
Member

commented May 28, 2018

I'd personally be thrilled to see this enter Cargo itself! I would ideally prefer to avoid having two TOML parsers built in but if we need to have that for the time being I think it's not the end of the world. (I don't know much about the technical design of cargo-edit right now)

@steveklabnik

This comment has been minimized.

Copy link
Member

commented May 29, 2018

This is the number one thing I want in Cargo; a simple 👍 is not enough. Tons and tons and tons of people are very excited for this 🎊

@ibaryshnikov

This comment has been minimized.

Copy link

commented May 29, 2018

I'd like to implement it, work in-progress is here
https://github.com/ibaryshnikov/cargo/tree/issue-5586-cargo-add

@japaric

This comment has been minimized.

Copy link
Member

commented Sep 6, 2018

I know that lots of people (myself included) are plenty busy with stuff for the upcoming edition release and that we don't have much spare human Rustacean resources but I still want to say that it would be AMAZING to have cargo add in Cargo 2018. As mentioned by boats, cargo add fits perfectly with the module / path changes of the edition. And I fully agree, but to me the biggest win would be not having to cargo install cargo-edit, which involves compiling / linking to C code and can be a (very) frustrating experience.

@rust-lang/cargo @killercup @aturon could we make this happen, somehow? 🙏

@steveklabnik

This comment has been minimized.

Copy link
Member

commented Sep 7, 2018

@joshtriplett

This comment has been minimized.

Copy link
Member

commented Sep 7, 2018

👍 here.

@ibaryshnikov

This comment has been minimized.

Copy link

commented Sep 7, 2018

I did some preparations in this pr like filling the boilerplate and updating errors from cargo-edit to fit more for cargo, but farther work requires some patches to toml parser which is used in cargo (in case we don't want to have two parsers), and currently I don't have enough time to do required updates in the parser on my own. If you find some of the code in this pr fits for the solution, feel free to use it.

@thejpster

This comment has been minimized.

Copy link

commented Sep 11, 2018

I just wanted to add that I think cargo-add is a great tool for people new to Rust, as is cargo-generate. Unfortunately if I recommend them in a guide or tutorial, I have to explain how to install them and that they need to first install GCC and cmake and libssl-dev, which is non-trivial.

@withoutboats

This comment has been minimized.

Copy link
Contributor

commented Sep 11, 2018

Definitely would love to see this added to cargo, since my workflow setting up a new dev environment is:

  1. Install Rust
  2. Install ripgrep
  3. cargo install cargo-edit

As @ibaryshnikov points out though, its nontrivial work since the TOML parser cargo uses right now doesn't preserve layout, whitespace, or comments. We need to migrate to using the same parser cargo-edit uses before we can upstream any of its features into cargo.

@withoutboats

This comment has been minimized.

Copy link
Contributor

commented Sep 12, 2018

We discussed this in the cargo meeting. There was strong support for upstreaming the functionality of cargo add into cargo. We doubt it can be stable in time for the 2018 edition (since the final cargo master for the edition needs to be merged roughly 5 weeks from today) but we do think its good to start making progress on adding this functionality.

We are comfortable having two TOML parsers in cargo for now (with a view to eventually merging them) so long as they share a common lexer, to be confident they aren't interpreting the TOML significantly differently. @alexcrichton says he's left a comment on the repo for the parser cargo-edit is using to this effect.

@sandangel

This comment has been minimized.

Copy link

commented Jan 5, 2019

Hi everyone, may I know the status of this issue? It's 2019 now and Happy New Year. ^^

@Eh2406

This comment has been minimized.

Copy link
Contributor

commented Jan 5, 2019

From the discord Today at 5:48 PM:
"ehuss: (btw, my format-preserving toml parser just passed all tests 🎉 😄 )"

@yhaskell

This comment has been minimized.

Copy link

commented Aug 2, 2019

Hello! Does anyone know what is the status of this?

@ordian

This comment has been minimized.

Copy link
Contributor

commented Aug 4, 2019

In #5611 (comment) a concern was raised that we should (partially) deduplicate toml parsing libraries (cargo currently uses toml-rs, but that's not a lossless toml parser, e.g. it will eat your comments, cargo-edit currently uses toml_edit) before using it in cargo. Unfortunately, I don't have time to work on it (link to issues), but would be happy to mentor if someone wants to make this happen (if you're interested, please leave a message in https://gitter.im/toml_edit/Lobby).

After the above issues are resolved, we can hopefully revive #5611.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.