Skip to content

Commit ab3ae47

Browse files
committed
Merge branch 'master' into feature-832-custom-rust-target
2 parents 527e0e5 + fdee9f1 commit ab3ae47

18 files changed

+1757
-946
lines changed

.travis.yml

+24-9
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,32 @@ env:
1717
global:
1818
- CARGO_TARGET_DIR=/tmp/bindgen
1919
matrix:
20-
- LLVM_VERSION=3.7.1 BINDGEN_FEATURES=testing_only_libclang_3_8
21-
- LLVM_VERSION=3.8.1 BINDGEN_FEATURES=testing_only_libclang_3_8
22-
- LLVM_VERSION=3.9.0 BINDGEN_FEATURES=testing_only_libclang_3_9
23-
- LLVM_VERSION=4.0.0 BINDGEN_FEATURES=testing_only_libclang_4
20+
- LLVM_VERSION="3.8.1" BINDGEN_JOB="test" BINDGEN_PROFILE=
21+
- LLVM_VERSION="3.8.1" BINDGEN_JOB="test" BINDGEN_PROFILE="--release"
22+
- LLVM_VERSION="3.8.1" BINDGEN_JOB="integration" BINDGEN_PROFILE=
23+
- LLVM_VERSION="3.8.1" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release"
24+
- LLVM_VERSION="3.8.1" BINDGEN_JOB="expectations" BINDGEN_PROFILE=
25+
- LLVM_VERSION="3.8.1" BINDGEN_JOB="expectations" BINDGEN_PROFILE="--release"
26+
- LLVM_VERSION="3.9.0" BINDGEN_JOB="test" BINDGEN_PROFILE=
27+
- LLVM_VERSION="3.9.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release"
28+
- LLVM_VERSION="3.9.0" BINDGEN_JOB="integration" BINDGEN_PROFILE=
29+
- LLVM_VERSION="3.9.0" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release"
30+
- LLVM_VERSION="3.9.0" BINDGEN_JOB="expectations" BINDGEN_PROFILE=
31+
- LLVM_VERSION="3.9.0" BINDGEN_JOB="expectations" BINDGEN_PROFILE="--release"
32+
- LLVM_VERSION="4.0.0" BINDGEN_JOB="test" BINDGEN_PROFILE=
33+
- LLVM_VERSION="4.0.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release"
34+
- LLVM_VERSION="4.0.0" BINDGEN_JOB="test" BINDGEN_PROFILE= BINDGEN_FEATURES="testing_only_extra_assertions"
35+
- LLVM_VERSION="4.0.0" BINDGEN_JOB="test" BINDGEN_PROFILE="--release" BINDGEN_FEATURES="testing_only_extra_assertions"
36+
- LLVM_VERSION="4.0.0" BINDGEN_JOB="integration" BINDGEN_PROFILE=
37+
- LLVM_VERSION="4.0.0" BINDGEN_JOB="integration" BINDGEN_PROFILE="--release"
38+
- LLVM_VERSION="4.0.0" BINDGEN_JOB="expectations" BINDGEN_PROFILE=
39+
- LLVM_VERSION="4.0.0" BINDGEN_JOB="expectations" BINDGEN_PROFILE="--release"
40+
- LLVM_VERSION="4.0.0" BINDGEN_JOB="misc"
2441

2542
matrix:
2643
fast_finish: true
2744
allow_failures:
28-
- env: LLVM_VERSION=3.7.1 BINDGEN_FEATURES=testing_only_libclang_3_8
45+
- env: LLVM_VERSION=4.0.0 BINDGEN_JOB=rustfmt
2946

3047
cache:
3148
directories:
@@ -35,14 +52,12 @@ cache:
3552
before_install: . ./ci/before_install.sh
3653

3754
script:
38-
# - ./ci/assert-rustfmt.sh
39-
- BINDGEN_FEATURES="$BINDGEN_FEATURES" ./ci/assert-docs.sh
40-
- BINDGEN_FEATURES="$BINDGEN_FEATURES" ./ci/test.sh
41-
- ./ci/test-book.sh
55+
- BINDGEN_JOB="$BINDGEN_JOB" BINDGEN_PROFILE="$BINDGEN_PROFILE" BINDGEN_FEATURES="$BINDGEN_FEATURES" ./ci/script.sh
4256

4357
after_success:
4458
- test "$TRAVIS_PULL_REQUEST" == "false" &&
4559
test "$TRAVIS_BRANCH" == "master" &&
60+
test "$BINDGEN_JOB" == "misc" &&
4661
./ci/deploy-book.sh
4762

4863
notifications:

CONTRIBUTING.md

+53-22
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ out to us in a GitHub issue, or stop by
1414
- [Building](#building)
1515
- [Testing](#testing)
1616
- [Overview](#overview)
17-
- [Running All Tests](#running-all-tests)
18-
- [Running a Single Test](#running-a-single-test)
17+
- [Testing Bindings Generation](#testing-bindings-generation)
18+
- [Testing Generated Bindings](#testing-generated-bindings)
19+
- [Testing a Single Header's Bindings Generation and Compiling its Bindings](#testing-a-single-headers-bindings-generation-and-compiling-its-bindings)
1920
- [Authoring New Tests](#authoring-new-tests)
2021
- [Test Expectations and `libclang` Versions](#test-expectations-and-libclang-versions)
2122
- [Automatic code formatting](#automatic-code-formatting)
@@ -85,38 +86,49 @@ $ cargo build --features testing_only_docs
8586

8687
## Testing
8788

88-
Code for binding generation and testing thereof is in the `bindgen` crate.
89-
The following sections assume you are working in that subdirectory.
90-
9189
### Overview
9290

9391
Input C/C++ test headers reside in the `tests/headers` directory. Expected
94-
output Rust bindings live in `tests/expectations/tests`.
92+
output Rust bindings live in `tests/expectations/tests`. For example,
93+
`tests/headers/my_header.h`'s expected generated Rust bindings would be
94+
`tests/expectations/tests/my_header.rs`.
9595

96-
For example, `tests/headers/my_header.h`'s expected generated Rust bindings
97-
would be `tests/expectations/tests/my_header.rs`.
96+
There is also the `./bindgen-integration` crate, which uses `bindgen` to
97+
generate bindings to some C++ code, and then uses the bindings, asserting that
98+
values are what we expect them to be both on the Rust and C++ side.
9899

99-
Run `cargo test` to compare generated Rust bindings to the expectations.
100+
### Testing Bindings Generation
100101

101-
### Running All Tests
102+
To regenerate bindings from the corpus of test headers in `tests/headers` and
103+
compare them against the expected bindings in `tests/expectations/tests`, run:
102104

103105
```
104-
$ cargo test --features testing_only_libclang_$VERSION
106+
$ cargo test
105107
```
106108

107-
Where `$VERSION` is one of:
109+
As long as you aren't making any changes to `bindgen`'s output, running this
110+
should be sufficient to test your local modifications.
108111

109-
* `4`
110-
* `3_9`
111-
* `3_8`
112+
### Testing Generated Bindings
112113

113-
depending on which version of `libclang` you have installed.
114+
If your local changes are introducing expected modifications in the
115+
`tests/expectations/tests/*` bindings files, then you should test that the
116+
generated bindings files still compile, and that their struct layout tests still
117+
pass.
114118

115-
### Running a Single Test
119+
You can do this with these commands:
116120

117-
To generate bindings for a single test header, compile the bindings, and run the
118-
layout assertion tests for those bindings, use the `tests/test-one.sh`
119-
script. It supports fuzzy searching for test headers. For example, to test
121+
```
122+
$ cd tests/expectations
123+
$ cargo test
124+
```
125+
126+
### Testing a Single Header's Bindings Generation and Compiling its Bindings
127+
128+
Sometimes its useful to work with one test header from start (generating
129+
bindings for it) to finish (compiling the bindings and running their layout
130+
tests). This can be done with the `tests/test-one.sh` script. It supports fuzzy
131+
searching for test headers. For example, to test
120132
`tests/headers/what_is_going_on.hpp`, execute this command:
121133

122134
```
@@ -132,14 +144,17 @@ bindings. Put those in `tests/expectations/tests`.
132144
If your new test requires certain flags to be passed to `bindgen`, you can
133145
specify them at the top of the test header, with a comment like this:
134146

147+
`new_test_header.hpp`:
148+
135149
```c
136150
// bindgen-flags: --enable-cxx-namespaces -- -std=c++14
137151
```
138152

139-
Then verify the new Rust bindings compile and pass some basic tests:
153+
Then verify the new Rust bindings compile and pass their layout tests:
140154

141155
```
142-
$ cargo test -p tests_expectations
156+
$ cd tests/expectations
157+
$ cargo test new_test_header
143158
```
144159

145160
### Test Expectations and `libclang` Versions
@@ -161,6 +176,22 @@ request, and then when Travis CI fails, it will log a diff of the
161176
expectations. Use the diff to patch the appropriate expectation file locally and
162177
then update your pull request.
163178

179+
Usually, `bindgen`'s test runner can infer which version of `libclang` you
180+
have. If for some reason it can't, you can force a specific `libclang` version
181+
to check the bindings against with a cargo feature:
182+
183+
```
184+
$ cargo test --features testing_only_libclang_$VERSION
185+
```
186+
187+
Where `$VERSION` is one of:
188+
189+
* `4`
190+
* `3_9`
191+
* `3_8`
192+
193+
depending on which version of `libclang` you have installed.
194+
164195
## Automatic code formatting
165196

166197
We use [`rustfmt`](https://github.com/rust-lang-nursery/rustfmt) to enforce a

ci/script.sh

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
set -xeu
4+
cd "$(dirname "$0")/.."
5+
6+
# Note that `$BINDGEN_PROFILE` is never in quotes so that it expands to nothing
7+
# (not even an empty string argument) when the variable is empty. This is
8+
# necessary so we don't pass an unexpected flag to cargo.
9+
10+
export RUST_BACKTRACE=1
11+
12+
case "$BINDGEN_JOB" in
13+
"test")
14+
cargo test $BINDGEN_PROFILE --features "$BINDGEN_FEATURES"
15+
./ci/assert-no-diff.sh
16+
;;
17+
18+
"integration")
19+
cd ./bindgen-integration
20+
cargo test $BINDGEN_PROFILE --features "$BINDGEN_FEATURES"
21+
;;
22+
23+
"expectations")
24+
cd ./tests/expectations
25+
cargo test $BINDGEN_PROFILE
26+
;;
27+
28+
"misc")
29+
./ci/assert-docs.sh
30+
./ci/test-book.sh
31+
./ci/no-includes.sh
32+
# `rustfmt` isn't reaching a fixed point on bindgen
33+
# code... https://github.com/rust-lang-nursery/rustfmt/issues/1376
34+
# ./ci/assert-rustfmt.sh
35+
;;
36+
37+
*)
38+
echo "Error! Unknown \$BINDGEN_JOB: '$BINDGEN_JOB'"
39+
exit 1
40+
esac

ci/test.sh

-38
This file was deleted.

0 commit comments

Comments
 (0)