Skip to content

Add workflow to check features #2506

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

Merged
merged 5 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/bindgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions bindgen-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
4 changes: 2 additions & 2 deletions bindgen-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions bindgen-integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
6 changes: 3 additions & 3 deletions bindgen-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
9 changes: 6 additions & 3 deletions bindgen-tests/tests/stylo_sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions bindgen-tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 8 additions & 6 deletions bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
14 changes: 7 additions & 7 deletions bindgen/extra_assertions.rs
Original file line number Diff line number Diff line change
@@ -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 )* );
}
};
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/analysis/template_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions bindgen/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand All @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions bindgen/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ci/test.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' ' ',')"
Expand Down