Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Attribute macro for conditional compilation options #44

@dtolnay

Description

@dtolnay

Similar idea to what https://github.com/dtolnay/rustversion does for compiler version selection, but for lots of other things people want to be conditional on.


Environment variables

Conditional compilation based on whether an environment variable is defined at build time.

For example you could use this to disable or enable specific code when building in CI:
https://docs.travis-ci.com/user/environment-variables/#default-environment-variables

#[condition::env("TRAVIS")]
fn run() {...}

#[condition::not(env("TRAVIS"))]
fn run() {...}

PATH

Conditional compilation based on whether some binary is available on the system's PATH.

For example you could conditionally ignore a test case that requires some specific binary.

#[condition::attr(not(cmd("cargo-expand")), ignore)]
fn my_test() {...}

^ This expands to #[ignore] if there is no cargo-expand on the PATH. Ignored tests are logged by the test runner and is friendlier than considering the test failed or silently passing it.


More...

Potentially other ideas.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions