Skip to content

Consider reversing --cfg flags for feature detection #2259

@Darksonn

Description

@Darksonn

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions