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

Disable logging calls via conditional compilation when all defmt features are disabled #477

Merged
merged 1 commit into from
May 17, 2021

Conversation

WasabiFan
Copy link
Contributor

@WasabiFan WasabiFan commented May 17, 2021

This is my take on fixing #411. It's not clear whether this is the "right" fix, as that issue was marked with a "medium" difficulty tag which would seem to imply there was more work expected here. Either way, it allows the sample in the linked issue to build for me, and fixes the usage in my own project.

The change here is to replace an "if" emitted by the logging macros (albeit with constant boolean conditions at macro evaluation time) with an explicit #[cfg(...)] annotation. With the new form, the compiler seems to successfully strip out the unreachable macro body and as such there are no broken references to the nonexistent symbols.

@WasabiFan
Copy link
Contributor Author

Oh, yeah, and this has only gone through cursory testing and only on Windows. If there's a sensible place for me to introduce a test for this behavior, I'd be happy to do that; I don't see any tests for these macros as of now.

@jonas-schievink
Copy link
Contributor

Thanks, this looks good!

bors r+

@bors
Copy link
Contributor

bors bot commented May 17, 2021

Build succeeded:

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

Successfully merging this pull request may close these issues.

2 participants