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 new flag for inserting proc-macro = true into Cargo.toml #14708

Open
lthoerner opened this issue Oct 20, 2024 · 1 comment
Open

Add cargo new flag for inserting proc-macro = true into Cargo.toml #14708

lthoerner opened this issue Oct 20, 2024 · 1 comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-new S-needs-team-input Status: Needs input from team on whether/how to proceed.

Comments

@lthoerner
Copy link

Problem

I'm currently in the process of creating a presentation about how to implement derive macros. I found that I could express the process of creating the proc macro subcrate and adding the proper dependencies via a snippet of shell commands:

cargo new my_macros --lib
cargo add my_macros --path my_macros
cd my_macros
cargo add syn
cargo add quote
cargo add proc_macro2

There is one notable exception here: I cannot write a command that adds the proper tag to the manifest.

[lib]
proc-macro = true

Proposed Solution

It would be nice for feature parity with the --lib specification to have a CLI flag for emitting the manifest for a proc macro crate. I suspect this would be a relatively simple thing to add as well, and I am happy to work on it myself if this issue gets approved.

Specifically, I propose that cargo new have a --proc-macro flag that is mutually exclusive with --bin or --lib (to my understanding it would only be valid in the case of library crate anyway, though feel free to correct me here).

Notes

No response

@lthoerner lthoerner added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels Oct 20, 2024
@weihanglo
Copy link
Member

Thanks for the idea!

I'm not sure how often the --proc-macro flag would be useful. Personally, I seldom start new proc macro packages, but I can't speak for everyone. On the other hand, for people working on C bindings, should we also provide a --crate-type or --cdylib flag?

I might be a bit conservative when adding new flags to Cargo, as every flag is permanent. I feel like for this kind of cases it might be better to explore templating solution for proc macro package. See relevant discussions in #5151. Perhaps #8365 is also related if one wants to create a workspace with a proc-macro crate.

@weihanglo weihanglo added S-needs-team-input Status: Needs input from team on whether/how to proceed. and removed S-triage Status: This issue is waiting on initial triage. labels Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-new S-needs-team-input Status: Needs input from team on whether/how to proceed.
Projects
None yet
Development

No branches or pull requests

2 participants