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

Macro is unusable without declaring your own feature flags #3

Closed
seritools opened this issue Nov 15, 2021 · 3 comments
Closed

Macro is unusable without declaring your own feature flags #3

seritools opened this issue Nov 15, 2021 · 3 comments

Comments

@seritools
Copy link

seritools commented Nov 15, 2021

Currently,

#[cfg(any(debug_assertions,feature = "plot-release"))]
#[cfg(feature = "debug")]

is emitted from the macro, meaning that the crate that uses it has to define/activate these features rather than debug-plotter itself.

I think this might also relate to #2, as I've seen the same "unused variable" message in rust-analyzer until I added plot-release and debug as feature flags to my crate instead.

@fabianboesiger
Copy link
Owner

The debug feature is enabled by default, so you shouldn't need to explicitly enable it.

The idea here is that the plot! macro produces no code in release mode by default, similar to debug_assert! from the standard library. This behavior can be changed if you enable the plot-release feature.

However, this seems to cause confusion, so I'm going to change this behavior in the near feature.

@seritools
Copy link
Author

seritools commented Nov 15, 2021

The point is that the macro emits those cfgs into my code, so it'll look for feature flags in my crate.

It works in debug mode if I add

[features]
default = ["debug"]
debug = []

[dependencies]
debug-plotter = { version = "0.2.1" }

to my crate's Cargo.toml, and it works in release mode if I add

[features]
default = ["debug", "plot-release"]
debug = []
plot-release = []

[dependencies]
debug-plotter = { version = "0.2.1" }

to it. It does not work with just debug-plotter = { version = "0.2.1" } or debug-plotter = { version = "0.2.1", features = "plot-release" }. You should be able to reproduce that when creating a separate crate that consumes this (examples/bins in the same crate will reuse the lib's features).

The problem is that the conditional compilation attributes are used/set inside the macro.

@fabianboesiger
Copy link
Owner

fabianboesiger commented Nov 15, 2021

Oh sorry I misunderstood the issue in this case.

I just updated the code to avoid these features and instead use the plot! macro for plotting in debug and release mode, and debug_plot!to plot only in debug mode. This avoids this issue of leaking cfg feature flags all together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants