diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 147e669..c38bd54 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,6 +14,7 @@ jobs: matrix: rust: [1.0.0, 1.5.0, 1.10.0, 1.15.0, 1.20.0, 1.25.0, 1.30.0, 1.35.0, 1.40.0, 1.45.0, 1.50.0, 1.55.0, 1.60.0, 1.65.0, 1.70.0, 1.75.0, + 1.80.0, # first version with rustc-check-cfg stable, beta, nightly] steps: - uses: actions/checkout@v4 @@ -22,6 +23,8 @@ jobs: toolchain: ${{ matrix.rust }} - run: cargo build --verbose - run: cargo test --verbose + - run: cargo run + working-directory: ./ci/verify-check-cfg # try probing a target that doesn't have std at all no_std: diff --git a/ci/verify-check-cfg/.gitignore b/ci/verify-check-cfg/.gitignore new file mode 100644 index 0000000..4683d3e --- /dev/null +++ b/ci/verify-check-cfg/.gitignore @@ -0,0 +1,3 @@ +# Rust +/target +/Cargo.lock diff --git a/ci/verify-check-cfg/Cargo.toml b/ci/verify-check-cfg/Cargo.toml new file mode 100644 index 0000000..7602ccd --- /dev/null +++ b/ci/verify-check-cfg/Cargo.toml @@ -0,0 +1,12 @@ +[package] +# NOTE: Cannot be in workspace because of rustc 1.0 support +name = "autocfg-verify-check-cfg" +description = "A dummy crate to verify autocfg is emitting check-cfg directives" +version = "0.1.0" +edition = "2021" +# only for testing +publish = false + +[build-dependencies] +autocfg = { path = "../.." } + diff --git a/ci/verify-check-cfg/build.rs b/ci/verify-check-cfg/build.rs new file mode 100644 index 0000000..9df82c0 --- /dev/null +++ b/ci/verify-check-cfg/build.rs @@ -0,0 +1,43 @@ +pub fn main() { + let cfg = autocfg::AutoCfg::new().unwrap(); + + // + // tests + // + + // always true + cfg.emit_rustc_version(1, 0); + // should always be false + cfg.emit_rustc_version(7, u32::MAX as usize); + + // always true + cfg.emit_has_path("std::vec::Vec"); + cfg.emit_path_cfg("std::vec::Vec", "has_path_std_vec"); + // always false + cfg.emit_has_path("dummy::DummyPath"); + cfg.emit_path_cfg("dummy::DummyPath", "has_path_dummy"); + + // always true + cfg.emit_has_trait("std::ops::Add"); + cfg.emit_trait_cfg("std::ops::Add", "has_trait_add"); + // always false + cfg.emit_has_trait("dummy::DummyTrait"); + cfg.emit_trait_cfg("dummy::DummyTrait", "has_trait_dummy"); + + // always true + cfg.emit_has_type("i32"); + cfg.emit_type_cfg("i32", "has_type_i32"); + // always false + cfg.emit_has_type("i7billion"); + cfg.emit_type_cfg("i7billion", "has_type_i7billion"); + + // always true + cfg.emit_expression_cfg("3 + 7", "has_working_addition"); + // always false + cfg.emit_expression_cfg("3 ^^^^^ 12", "has_working_5xor"); + + // always true + cfg.emit_constant_cfg("7", "has_const_7"); + // false - Opening file should never be `const` + cfg.emit_constant_cfg("std::fs::File::open(\"foo.txt\")", "has_const_file_open"); +} diff --git a/ci/verify-check-cfg/src/main.rs b/ci/verify-check-cfg/src/main.rs new file mode 100644 index 0000000..9df9f40 --- /dev/null +++ b/ci/verify-check-cfg/src/main.rs @@ -0,0 +1,42 @@ +#![deny(unexpected_cfgs)] + +macro_rules! test_cfgs { + ($($cfg:ident,)*) => {$({ + let cfg_desc = format!("cfg!({})", stringify!($cfg)); + if cfg!($cfg) { + println!("Enabled: {}", cfg_desc); + } else { + println!("Disabled: {}", cfg_desc); + } + })*}; + +} + +pub fn main() { + test_cfgs!( + // emit_rustc_version + rustc_1_0, + rustc_7_4294967295, + // emit_has_path, emit_path_cfg + has_std__vec__Vec, + has_path_std_vec, + has_dummy__DummyPath, + has_path_dummy, + // emit_has_trait, emit_trait_cfg + has_std__ops__Add, + has_trait_add, + has_dummy__DummyTrait, + has_trait_dummy, + // emit_has_type, has_type_i32 + has_i32, + has_type_i32, + has_i7billion, + has_type_i7billion, + // emit_expression_cfg + has_working_addition, + has_working_5xor, + // emit_constant_cfg + has_const_7, + has_const_file_open, + ); +}