-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Open
Labels
C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-metadataS-triageStatus: This issue is waiting on initial triage.Status: This issue is waiting on initial triage.
Description
Problem
Hi, I currently use cargo metadata
to filter crates that are proc-macros by checking the kind
in the target metadata, and looking for "proc-macro"
. However, I noticed that this isn't very reliable. If the target spec includes a crate-type
, this check no longer works, and I cannot find any other way to get that information.
E.g.: If I run cargo metadata
using the following Cargo.toml
.
[package]
name = "proc_macro_lib"
version = "0.1.0"
edition = "2021"
[lib]
name = "lib"
crate-type = ["lib"]
proc-macro = true
path = "src/lib.rs"
I get the following metadata:
{
"metadata": null,
"packages": [
{
"authors": [],
"categories": [],
"default_run": null,
"dependencies": [],
"description": null,
"documentation": null,
"edition": "2021",
"features": {},
"homepage": null,
"id": "proc_macro_lib 0.1.0 (path+file:///tmp/lib-pmacro)",
"keywords": [],
"license": null,
"license_file": null,
"links": null,
"manifest_path": "/tmp/lib-pmacro/Cargo.toml",
"metadata": null,
"name": "proc_macro_lib",
"publish": null,
"readme": null,
"repository": null,
"rust_version": null,
"source": null,
"targets": [
{
"crate_types": [
"lib"
],
"doc": true,
"doctest": true,
"edition": "2021",
"kind": [
"lib"
],
"name": "lib",
"src_path": "/tmp/lib-pmacro/src/lib.rs",
"test": true
}
],
"version": "0.1.0"
}
],
"resolve": {
"nodes": [
{
"dependencies": [],
"deps": [],
"features": [],
"id": "proc_macro_lib 0.1.0 (path+file:///tmp/lib-pmacro)"
}
],
"root": "proc_macro_lib 0.1.0 (path+file:///tmp/lib-pmacro)"
},
"target_directory": "/tmp/lib-pmacro/target",
"version": 1,
"workspace_members": [
"proc_macro_lib 0.1.0 (path+file:///tmp/lib-pmacro)"
],
"workspace_root": "/tmp/lib-pmacro"
}
I honestly don't know why someone would do that, but at this point I just want to make sure we can gracefully handle cases like that.
Proposed Solution
I can think of two options:
- Cargo should include the value of the
proc-macro
field as part of thetarget
metadata, like it does withdoc
,test
,doctest
. - Add
"proc-macro"
to thekind
field whenever the flag is set totrue
.
Notes
No response
Metadata
Metadata
Assignees
Labels
C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-metadataS-triageStatus: This issue is waiting on initial triage.Status: This issue is waiting on initial triage.