Skip to content

proc-macros used as build-depedencies and normal depedencies have features unified #15251

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

Closed
Baptistemontan opened this issue Mar 1, 2025 · 2 comments
Labels
A-features2 Area: issues specifically related to the v2 feature resolver A-proc-macro Area: compiling proc-macros C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@Baptistemontan
Copy link

Problem

If a package depends on a crate both as a dev-depedency and a normal depedency, and that crate pass feature flags to a macro, the features flags for the macro will be unified.

# workspace Cargo.toml
[workspace]
resolver = "2"
members = ["app", "common", "macros"]

[workspace.dependencies]
macros = { path = "./macros" }
common = { path = "./common" }
# app package Cargo.toml
[package]
name = "app"
version = "0.1.0"

[dependencies]
common = { workspace = true }

[build-dependencies]
common = { workspace = true, features = ["foo"] }
# common package Cargo.toml
[package]
name = "common"
version = "0.1.0"

[dependencies]
macros = { workspace = true }

[features]
default = []
foo = ["macros/foo"]
# macros package Cargo.toml
[package]
name = "macros"
version = "0.1.0"

[lib]
proc-macro = true

[features]
default = []
foo = ["macros/foo"]

When compiling the app package, the common package will have the "foo" feature enabled in the build.rs script (as expected), but will not during the normal build (as expected), BUT the macros package will have the "foo" feature enabled at both.

This create an issue when the macros package expect the common package to also have the feature enabled (to use some exported items for exemple).

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.86.0-nightly (2928e3273 2025-02-07)
release: 1.86.0-nightly
commit-hash: 2928e32734b04925ee51e1ae88bea9a83d2fd451
commit-date: 2025-02-07
host: x86_64-pc-windows-msvc
libgit2: 1.9.0 (sys:0.20.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:Schannel)
os: Windows 10.0.26100 (Windows 11 Professional) [64-bit]
@Baptistemontan Baptistemontan added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Mar 1, 2025
@Baptistemontan Baptistemontan changed the title proc-macros used as build-depencies and normal depedencies have features unified proc-macros used as build-depedencies and normal depedencies have features unified Mar 1, 2025
@epage epage added A-features2 Area: issues specifically related to the v2 feature resolver A-proc-macro Area: compiling proc-macros labels Mar 3, 2025
@epage
Copy link
Contributor

epage commented Mar 3, 2025

This sounds like a duplicate of #14415 and so I'm closing in favor of that. If there is a reason for us to keep this open separately, let us know! If so, please add a full reproduction case with instructions in how to observe the behavior.

@epage epage closed this as completed Mar 3, 2025
@Baptistemontan
Copy link
Author

Thanks, I couldn't find any related issue, it is indeed the same problem, sorry for opening this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-features2 Area: issues specifically related to the v2 feature resolver A-proc-macro Area: compiling proc-macros C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants