Repository: rust-lang/rust-bindgen
Pull request #2506 (2023-04-17 19:35:03)

Add workflow to check features


Patch:
diff --git a/.github/workflows/bindgen.yml b/.github/workflows/bindgen.yml
index 59ff7c00..525984f2 100644
--- a/.github/workflows/bindgen.yml
+++ b/.github/workflows/bindgen.yml
@@ -214,6 +214,23 @@ jobs:
           BINDGEN_NO_DEFAULT_FEATURES: ${{matrix.no_default_features}}
         run: ./ci/test.sh
 
+  check-cfg:
+    runs-on: ubuntu-latest
+    env:
+      RUSTFLAGS: -D warnings
+    steps:
+      - uses: actions/checkout@v3
+      
+      - name: Install nightly
+        uses: actions-rs/toolchain@v1
+        with:
+          profile: minimal
+          toolchain: nightly
+          override: true
+      
+      - name: Check cfg
+        run: cargo check -Z unstable-options -Z check-cfg=features
+
   test-book:
     runs-on: ubuntu-latest
     steps:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 4c3398d1..33690d9a 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -222,7 +222,7 @@ have. If for some reason it can't, you can force a specific `libclang` version
 to check the bindings against with a cargo feature:
 
 ```
-$ cargo test --features testing_only_libclang_$VERSION
+$ cargo test --features __testing_only_libclang_$VERSION
 ```
 
 Where `$VERSION` is one of:
diff --git a/appveyor.yml b/appveyor.yml
index 741c59fd..973b4cdf 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -4,16 +4,16 @@ environment:
   matrix:
   - TARGET: gnu
     LLVM_VERSION: 5.0.0-1
-    BINDGEN_FEATURES: testing_only_libclang_5
+    BINDGEN_FEATURES: __testing_only_libclang_5
   - TARGET: gnu
     LLVM_VERSION: 9.0.0-1
-    BINDGEN_FEATURES: testing_only_libclang_9
+    BINDGEN_FEATURES: __testing_only_libclang_9
   - TARGET: msvc
     LLVM_VERSION: 5.0.0
-    BINDGEN_FEATURES: testing_only_libclang_5
+    BINDGEN_FEATURES: __testing_only_libclang_5
   - TARGET: msvc
     LLVM_VERSION: 9.0.0
-    BINDGEN_FEATURES: testing_only_libclang_9
+    BINDGEN_FEATURES: __testing_only_libclang_9
 
 configuration:
 - stable
diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml
index 731f1bee..c6e510e9 100644
--- a/bindgen-cli/Cargo.toml
+++ b/bindgen-cli/Cargo.toml
@@ -33,3 +33,10 @@ static = ["bindgen/static"]
 runtime = ["bindgen/runtime"]
 # Dynamically discover a `rustfmt` binary using the `which` crate
 which-rustfmt = ["bindgen/which-rustfmt"]
+
+## The following features are for intearnal use and they shouldn't be used if
+## you're not hacking on bindgen
+# Features used for CI testing 
+__testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"]
+__testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"]
+__testing_only_libclang_5 = ["bindgen/__testing_only_libclang_5"]
diff --git a/bindgen-cli/main.rs b/bindgen-cli/main.rs
index a3b36126..a3407232 100644
--- a/bindgen-cli/main.rs
+++ b/bindgen-cli/main.rs
@@ -13,9 +13,9 @@ use crate::options::builder_from_flags;
 #[cfg(feature = "logging")]
 fn clang_version_check() {
     let version = bindgen::clang_version();
-    let expected_version = if cfg!(feature = "testing_only_libclang_9") {
+    let expected_version = if cfg!(feature = "__testing_only_libclang_9") {
         Some((9, 0))
-    } else if cfg!(feature = "testing_only_libclang_5") {
+    } else if cfg!(feature = "__testing_only_libclang_5") {
         Some((5, 0))
     } else {
         None
diff --git a/bindgen-integration/Cargo.toml b/bindgen-integration/Cargo.toml
index ac1b03ee..6c9508ab 100644
--- a/bindgen-integration/Cargo.toml
+++ b/bindgen-integration/Cargo.toml
@@ -14,6 +14,6 @@ cc = "1.0"
 static = ["bindgen/static"]
 runtime = ["bindgen/runtime"]
 
-testing_only_extra_assertions = ["bindgen/testing_only_extra_assertions"]
-testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"]
-testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"]
+__testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"]
+__testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"]
+__testing_only_libclang_5 = ["bindgen/__testing_only_libclang_5"]
diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml
index 838524fd..0db33d0e 100644
--- a/bindgen/Cargo.toml
+++ b/bindgen/Cargo.toml
@@ -49,11 +49,13 @@ static = ["clang-sys/static"]
 runtime = ["clang-sys/runtime"]
 # Dynamically discover a `rustfmt` binary using the `which` crate
 which-rustfmt = ["which"]
-__cli = []
 experimental = ["annotate-snippets"]
 
-# These features only exist for CI testing -- don't use them if you're not hacking
-# on bindgen!
-testing_only_extra_assertions = []
-testing_only_libclang_9 = []
-testing_only_libclang_5 = []
+## The following features are for intearnal use and they shouldn't be used if
+## you're not hacking on bindgen
+# Features used by `bindgen-cli` 
+__cli = []
+# Features used for CI testing 
+__testing_only_extra_assertions = []
+__testing_only_libclang_9 = []
+__testing_only_libclang_5 = []
diff --git a/bindgen/extra_assertions.rs b/bindgen/extra_assertions.rs
index 0888bf39..19e47636 100644
--- a/bindgen/extra_assertions.rs
+++ b/bindgen/extra_assertions.rs
@@ -1,33 +1,33 @@
 //! Macros for defining extra assertions that should only be checked in testing
-//! and/or CI when the `testing_only_extra_assertions` feature is enabled.
+//! and/or CI when the `__testing_only_extra_assertions` feature is enabled.
 
 /// Simple macro that forwards to assert! when using
-/// testing_only_extra_assertions.
+/// __testing_only_extra_assertions.
 #[macro_export]
 macro_rules! extra_assert {
     ( $cond:expr ) => {
-        if cfg!(feature = "testing_only_extra_assertions") {
+        if cfg!(feature = "__testing_only_extra_assertions") {
             assert!($cond);
         }
     };
     ( $cond:expr , $( $arg:tt )+ ) => {
-        if cfg!(feature = "testing_only_extra_assertions") {
+        if cfg!(feature = "__testing_only_extra_assertions") {
             assert!($cond, $( $arg )* )
         }
     };
 }
 
 /// Simple macro that forwards to assert_eq! when using
-/// testing_only_extra_assertions.
+/// __testing_only_extra_assertions.
 #[macro_export]
 macro_rules! extra_assert_eq {
     ( $lhs:expr , $rhs:expr ) => {
-        if cfg!(feature = "testing_only_extra_assertions") {
+        if cfg!(feature = "__testing_only_extra_assertions") {
             assert_eq!($lhs, $rhs);
         }
     };
     ( $lhs:expr , $rhs:expr , $( $arg:tt )+ ) => {
-        if cfg!(feature = "testing_only_extra_assertions") {
+        if cfg!(feature = "__testing_only_extra_assertions") {
             assert!($lhs, $rhs, $( $arg )* );
         }
     };
diff --git a/bindgen/ir/analysis/template_params.rs b/bindgen/ir/analysis/template_params.rs
index 3e6cd5e1..e4261cf6 100644
--- a/bindgen/ir/analysis/template_params.rs
+++ b/bindgen/ir/analysis/template_params.rs
@@ -459,7 +459,7 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> {
             }
         }
 
-        if cfg!(feature = "testing_only_extra_assertions") {
+        if cfg!(feature = "__testing_only_extra_assertions") {
             // Invariant: The `used` map has an entry for every allowlisted
             // item, as well as all explicitly blocklisted items that are
             // reachable from allowlisted items.
diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs
index a5c14a8f..ee076254 100644
--- a/bindgen/ir/context.rs
+++ b/bindgen/ir/context.rs
@@ -1193,11 +1193,11 @@ If you encounter an error missing from this list, please file an issue or a PR!"
         Ok((ret, self.options))
     }
 
-    /// When the `testing_only_extra_assertions` feature is enabled, this
+    /// When the `__testing_only_extra_assertions` feature is enabled, this
     /// function walks the IR graph and asserts that we do not have any edges
     /// referencing an ItemId for which we do not have an associated IR item.
     fn assert_no_dangling_references(&self) {
-        if cfg!(feature = "testing_only_extra_assertions") {
+        if cfg!(feature = "__testing_only_extra_assertions") {
             for _ in self.assert_no_dangling_item_traversal() {
                 // The iterator's next method does the asserting for us.
             }
@@ -1218,11 +1218,11 @@ If you encounter an error missing from this list, please file an issue or a PR!"
         )
     }
 
-    /// When the `testing_only_extra_assertions` feature is enabled, walk over
+    /// When the `__testing_only_extra_assertions` feature is enabled, walk over
     /// every item and ensure that it is in the children set of one of its
     /// module ancestors.
     fn assert_every_item_in_a_module(&self) {
-        if cfg!(feature = "testing_only_extra_assertions") {
+        if cfg!(feature = "__testing_only_extra_assertions") {
             assert!(self.in_codegen_phase());
             assert!(self.current_module == self.root_module);
 
diff --git a/bindgen/ir/item.rs b/bindgen/ir/item.rs
index a50d267a..f4dce45d 100644
--- a/bindgen/ir/item.rs
+++ b/bindgen/ir/item.rs
@@ -98,13 +98,13 @@ pub(crate) trait ItemAncestors {
     fn ancestors<'a>(&self, ctx: &'a BindgenContext) -> ItemAncestorsIter<'a>;
 }
 
-#[cfg(testing_only_extra_assertions)]
+#[cfg(__testing_only_extra_assertions)]
 type DebugOnlyItemSet = ItemSet;
 
-#[cfg(not(testing_only_extra_assertions))]
+#[cfg(not(__testing_only_extra_assertions))]
 struct DebugOnlyItemSet;
 
-#[cfg(not(testing_only_extra_assertions))]
+#[cfg(not(__testing_only_extra_assertions))]
 impl DebugOnlyItemSet {
     fn new() -> Self {
         DebugOnlyItemSet


Test patch:
diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml
index 3e529fb3..9018e8e3 100644
--- a/bindgen-tests/Cargo.toml
+++ b/bindgen-tests/Cargo.toml
@@ -17,6 +17,6 @@ static = ["bindgen/static"]
 runtime = ["bindgen/runtime"]
 which-rustfmt = ["bindgen/which-rustfmt"]
 
-testing_only_extra_assertions = ["bindgen/testing_only_extra_assertions"]
-testing_only_libclang_9 = ["bindgen/testing_only_libclang_9"]
-testing_only_libclang_5 = ["bindgen/testing_only_libclang_5"]
+__testing_only_extra_assertions = ["bindgen/__testing_only_extra_assertions"]
+__testing_only_libclang_9 = ["bindgen/__testing_only_libclang_9"]
+__testing_only_libclang_5 = ["bindgen/__testing_only_libclang_5"]
diff --git a/bindgen-tests/tests/stylo_sanity.rs b/bindgen-tests/tests/stylo_sanity.rs
index 52b96355..e1ad86b0 100755
--- a/bindgen-tests/tests/stylo_sanity.rs
+++ b/bindgen-tests/tests/stylo_sanity.rs
@@ -14,10 +14,13 @@ extern crate bindgen;
 /// how long bindings generation takes for Stylo. Stylo bindings generation
 /// takes too long to be a proper `#[bench]`.
 #[test]
-#[cfg(not(any(debug_assertions, feature = "testing_only_extra_assertions",)))]
+#[cfg(not(any(
+    debug_assertions,
+    feature = "__testing_only_extra_assertions",
+)))]
 #[cfg(any(
-    feature = "testing_only_libclang_5",
-    feature = "testing_only_libclang_9"
+    feature = "__testing_only_libclang_5",
+    feature = "__testing_only_libclang_9"
 ))]
 fn sanity_check_can_generate_stylo_bindings() {
     use std::time::Instant;
diff --git a/bindgen-tests/tests/tests.rs b/bindgen-tests/tests/tests.rs
index 7a039521..e1c35faa 100644
--- a/bindgen-tests/tests/tests.rs
+++ b/bindgen-tests/tests/tests.rs
@@ -194,9 +194,9 @@ fn compare_generated_header(
     {
         let mut expectation = expectation.clone();
 
-        if cfg!(feature = "testing_only_libclang_9") {
+        if cfg!(feature = "__testing_only_libclang_9") {
             expectation.push("libclang-9");
-        } else if cfg!(feature = "testing_only_libclang_5") {
+        } else if cfg!(feature = "__testing_only_libclang_5") {
             expectation.push("libclang-5");
         } else {
             match clang_version().parsed {
@@ -237,7 +237,7 @@ fn compare_generated_header(
             BufReader::new(f).read_to_string(&mut expected)?;
         }
         None => panic!(
-            "missing test expectation file and/or 'testing_only_libclang_$VERSION' \
+            "missing test expectation file and/or '__testing_only_libclang_$VERSION' \
              feature for header '{}'; looking for expectation file at '{:?}'",
             header.display(),
             looked_at,
diff --git a/ci/test.bat b/ci/test.bat
index 507537c0..d4a1c4a0 100644
--- a/ci/test.bat
+++ b/ci/test.bat
@@ -29,10 +29,10 @@ findstr /r /c:"#include *<.*>" tests\headers\* >nul 2>&1 && (
 cargo test --features "%BINDGEN_FEATURES%" || exit /b 1
 call .\ci\assert-no-diff.bat
 
-cargo test --features "%BINDGEN_FEATURES% testing_only_extra_assertions" || exit /b 1
+cargo test --features "%BINDGEN_FEATURES% __testing_only_extra_assertions" || exit /b 1
 call .\ci\assert-no-diff.bat
 
-cargo test --release --features "%BINDGEN_FEATURES% testing_only_extra_assertions" || exit /b 1
+cargo test --release --features "%BINDGEN_FEATURES% __testing_only_extra_assertions" || exit /b 1
 call .\ci\assert-no-diff.bat
 
 ::Now test the expectations' size and alignment tests.
diff --git a/ci/test.sh b/ci/test.sh
index 835d606e..33d0f7c6 100755
--- a/ci/test.sh
+++ b/ci/test.sh
@@ -108,7 +108,7 @@ get_cargo_args() {
     features+="runtime"
   fi
   if [ "$BINDGEN_FEATURE_EXTRA_ASSERTS" == "1"  ]; then
-    features+=" testing_only_extra_assertions"
+    features+=" __testing_only_extra_assertions"
   fi
   if [ ! -z "$features" ]; then
     args+=" --features $(echo $features | tr ' ' ',')"