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

[Feature request] Support feature flag for compile-time library deactivation #59

Open
matrach opened this issue May 8, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@matrach
Copy link

matrach commented May 8, 2022

Hi!

Thanks for such a great library! It is really convenient to use in our no-alloc project.

Would it be possible to add a no-color feature flag similarly to colored, that would make the library compile to a no-op and completely disappear in the resulting binary after llvm optimizations? In very constrained environments it would save a lot of Flash memory among others. With this option, the same codebase could be shared between different scales of available resources (like tens of KB Flash to MBs of Flash).

The other benefit is that users of the binary could use the simple interface without having to place if_support_colors everywhere, and then compile-time determine whether the logs should be colorful (e.g. in debug builds) or plain-text (in release).

@jam1garner
Copy link
Owner

I think it would be possible, I'll try to find time in the next few weeks to figure out an implementation

@jam1garner jam1garner added the enhancement New feature or request label May 25, 2022
@pacak
Copy link
Contributor

pacak commented Dec 15, 2022

Generally features should be additive only otherwise this might results in unexpected behavior in large codebases

https://github.com/rust-lang/cargo/blob/master/src/doc/src/reference/features.md#feature-unification

@sunshowers
Copy link
Collaborator

I think that's generally true @pacak, but in this case it would be okay because something like this would ideally only be set at the top level. Rhai uses a similar pattern: https://rhai.rs/book/start/features.html

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

No branches or pull requests

4 participants