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

Consider reversing --cfg flags for feature detection #2259

Open
Darksonn opened this issue Jan 24, 2025 · 0 comments
Open

Consider reversing --cfg flags for feature detection #2259

Darksonn opened this issue Jan 24, 2025 · 0 comments

Comments

@Darksonn
Copy link

Currently, your --cfg flags are set up such that if you pass no flags, then you get a build where all version-conditional features are disabled. This makes it difficult to use the crate with build systems that don't run the build.rs file, since you need to manually put together the list of --cfg flags to pass. If you forget to do this, the build will still pass, so you don't catch the mistake.

In Tokio, we were able to avoid this problem by reversing the meaning of the flags. For example, you would have a --cfg no_zerocopy_target_has_atomics_1_60_0 that you pass on compilers older than 1.60.0.

For projects with a non-cargo build system that does not run build.rs, this has the following advantages:

  • When using the newest compiler, you get the correct behavior by default, as the correct set of --cfg flags is the empty list. You do not need to adjust the list of cfg flags on every crate update.
  • When using an older compiler, the build will fail if you don't do anything. This ensures that you do not forget to look at the list of --cfg flags so that you pass the right set of flags.
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

1 participant