-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add cargo new --proc-macro and cargo init --proc-macro
#16362
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
base: master
Are you sure you want to change the base?
Conversation
|
r? @weihanglo rustbot has assigned @weihanglo. Use |
c149577 to
2ca2b1f
Compare
|
We've generally been conservative in what add to We may also want to decide on rust-lang/rfcs#3826 first as that can dramatically change what direction we may wan to go with this (especially since For myself,
Note that we encourage Issues also because that is where we are more likely to look when looking for past conversations in case this does get rejected.
This is an example of why Issues can be helpful. We could dig into this and explore alternatives like an option for less boilerplate, depending on the use case (why still use |
| ) | ||
| ._arg(flag("bin", "Use a binary (application) template [default]")) | ||
| ._arg(flag("lib", "Use a library template")) | ||
| ._arg(flag("proc-macro", "Use a library (proc-macro) template")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most features go through being unstable before becoming stable.
For more information, see https://doc.rust-lang.org/nightly/nightly-rustc/cargo/core/features/index.html
| let project_root = &project.root(); | ||
|
|
||
| snapbox::cmd::Command::cargo_ui() | ||
| .arg_line("init --proc-macro --vcs none --edition 2015") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something we've found helpful for authors, reviewers, and the community is the split PRs in at least two commits
- Add tests with them passing, showing current behavior
- Add fix or features w/ updates to tests, showing new behavior
Then the diff shows how behavior changed.
This isn't always applicable. A straightforward response to this with this PR is to just show "argument not found" errors on the use of --proc-macro. However, consider your point
Neither cargo new --lib nor cargo new --bin help with this. Because all pub items must be removed, and proc-macro crates can't have unit tests, these 2 flags are not as helpful.
You are highlighting how this improves on what is currently there, so the first commit could have tests use --lib with the follow up commit switching them to --proc-macro, with the diff showing how this new flag differs from what you would get before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is my first PR, it is a good opportunity for me to learn the codebase.
FYI my comments are in the line of helping to learn process; I am not reviewing for merging atm
2ca2b1f to
33172a2
Compare
Note: I didn't create an issue for this PR because I don't mind if it gets rejected. As this is my first PR, it is a good opportunity for me to learn the codebase.
What does this PR try to resolve?
This PR adds 2 new capabilities:
cargo new --proc-macrocargo init --proc-macroThe new
--proc-macroflag will createsrc/lib.rswith these contents:And
Cargo.tomlwith these contents:Motivation
Using proc-macros requires making a new crate, and there are many things you have to remember to do:
proc_macro::TokenStreamand notproc_macro2::TokenStream[lib] proc-macro = trueinCargo.tomlNeither
cargo new --libnorcargo new --binhelp with this. Because allpubitems must be removed, and proc-macro crates can't have unit tests, these 2 flags are not as helpful.There should be a 3rd flag which is just for creating a proc macro. This populates the
[lib] proc-macro = truesection. It also has the 3 signatures of proc-macro functions, including a derive macro with attributes.The
proc_macro::TokenStreamtype is used instead of doinguse proc_macro::TokenStreamthen usingTokenStreambecause people are likely to only need theproc_macro::TokenStreamtype in signatures of these functions, as most proc-macros useproc_macro2::TokenStreamHow to test and review this PR?
cargo test --test testsuite -- cargo_init::mutually_exclusive_flags cargo_init::simple_proc_macro