Skip to content

Commit 6b285e6

Browse files
author
bors-servo
authored
Auto merge of #204 - jdub:logless-library, r=emilio
Split off bindgen library into a sub-crate - Unfortunately there's a dependency on log via syntex_errors, so we don't get rid of it all - I can't find a more sensible way to set dependencies based on whether you're building the lib or bin - So `--no-default-features` means you need to know what you're doing, as only the lib will build without the logging crates for now - The replacement log macros are pretty gross too, but they show a proof of concept ;-)
2 parents 6e78bb8 + 073b12f commit 6b285e6

File tree

284 files changed

+250
-861
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+250
-861
lines changed

.gitignore

-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
bindgen
2-
libbindgen*
3-
41
# Cargo
52
target/
63
Cargo.lock
74
*~
85
#*#
9-

.travis.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ cache:
2424

2525
before_install: . ./ci/before_install.sh
2626

27+
before_script: cd libbindgen
28+
2729
script:
28-
- cargo build --verbose --features "$BINDGEN_FEATURES"
2930
- cargo test --features "$BINDGEN_FEATURES"
30-
- cargo build --release --verbose --features "$BINDGEN_FEATURES"
3131
- cargo test --release --features "$BINDGEN_FEATURES"
3232
- git add -A
3333
- git diff @
3434
- git diff-index --quiet HEAD
3535
- cargo test -p tests_expectations
3636
- cargo build --features "$BINDGEN_FEATURES _docs"
37+
- cd ..
38+
- cargo test --features "$BINDGEN_FEATURES"
39+
- cargo test --release --features "$BINDGEN_FEATURES"
3740

3841
notifications:
3942
webhooks: http://build.servo.org:54856/travis

CONTRIBUTING.md

+14-34
Original file line numberDiff line numberDiff line change
@@ -42,46 +42,34 @@ that you aren't forgetting to document types and functions. CI will catch it if
4242
you forget, but the turn around will be a lot slower ;)
4343

4444
```
45-
$ cargo build --features "llvm_stable _docs"
45+
$ cd libbindgen && cargo build --features "llvm_stable _docs"
4646
```
4747

4848
## Testing <span id="tests"/>
4949

50+
Code for binding generation and testing thereof is in the `libbindgen` crate.
51+
The following sections assume you are working in that subdirectory.
52+
5053
### Overview <span id="tests-overview"/>
5154

52-
Input C/C++ test headers reside in the `tests/headers` directory. The expected
53-
output rust bindings live in `tests/expectations/tests`; for example,
54-
`tests/headers/my_header.h`'s expected generated rust bindings would be
55+
Input C/C++ test headers reside in the `tests/headers` directory. Expected
56+
output Rust bindings live in `tests/expectations/tests`. For example,
57+
`tests/headers/my_header.h`'s expected generated Rust bindings would be
5558
`tests/expectations/tests/my_header.rs`.
5659

57-
The `tests/tools/run-bindgen.py` script runs `bindgen` on the test headers and
58-
compares the results to the expectations.
60+
Run `cargo test` to compare generated Rust bindings to the expectations.
5961

6062
### Running All Tests <span id="tests-all"/>
6163

6264
```
6365
$ cargo test [--features llvm_stable]
6466
```
6567

66-
This spawns a `tests/tools/run-bindgen.py` subprocess for each test header.
67-
68-
### Running a Single, Specific Test <span id="tests-one"/>
69-
70-
```
71-
$ ./tests/tools/run-bindgen.py ./target/debug/bindgen ./tests/headers/some_header.h
72-
```
73-
74-
To learn more about the options available with `run-bindgen.py`:
75-
76-
```
77-
$ ./tests/tools/run-bindgen.py --help
78-
```
79-
8068
### Authoring New Tests <span id="tests-new"/>
8169

8270
To add a new test header to the suite, simply put it in the `tests/headers`
83-
directory. Next, run the `run-bindgen.py` script with the new test header, which
84-
will generate the initial expected output rust bindings.
71+
directory. Next, run `bindgen` to generate the initial expected output Rust
72+
bindings. Put those in `tests/expectations/tests`.
8573

8674
If your new test requires certain flags to be passed to `bindgen`, you can
8775
specify them at the top of the test header, with a comment like this:
@@ -90,14 +78,7 @@ specify them at the top of the test header, with a comment like this:
9078
// bindgen-flags: --enable-cxx-namespaces -- -std=c++14
9179
```
9280

93-
If your new test requires `bindgen` to be built with certain features, you can
94-
specify the required features at the top of the test header in a similar manner:
95-
96-
```c
97-
// bingden-features: llvm_stable
98-
```
99-
100-
Then verify the new rust bindings compile and its tests pass:
81+
Then verify the new Rust bindings compile and pass some basic tests:
10182

10283
```
10384
$ cargo test -p tests_expectations
@@ -130,14 +111,13 @@ To help debug what `bindgen` is doing, you can define the environment variable
130111
`RUST_LOG=bindgen` to get a bunch of debugging log spew.
131112

132113
```
133-
$ RUST_LOG=bindgen ./target/debug/bindgen [flags...] ~/path/to/some/header.h
114+
$ RUST_LOG=libbindgen ./target/debug/bindgen [flags...] ~/path/to/some/header.h
134115
```
135116

136-
This logging can also be used when debugging failing tests under
137-
`run-bindgen.py`:
117+
This logging can also be used when debugging failing tests:
138118

139119
```
140-
$ RUST_LOG=bindgen ./tests/tools/run-bindgen.py ./target/debug/bindgen tests/headers/whatever.h
120+
$ RUST_LOG=libbindgen cd libbindgen && cargo test
141121
```
142122

143123
## Using `creduce` to Minimize Test Cases <span id="creduce"/>

Cargo.toml

+2-40
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ authors = [
44
"Emilio Cobos Álvarez <[email protected]>",
55
"The Servo project developers",
66
]
7-
build = "build.rs"
87
description = "A binding generator for Rust"
98
homepage = "https://github.com/servo/rust-bindgen"
109
keywords = ["bindings", "ffi", "code-generation"]
@@ -14,50 +13,13 @@ readme = "README.md"
1413
repository = "https://github.com/servo/rust-bindgen"
1514
version = "0.17.0"
1615

17-
[[bin]]
18-
doc = false
19-
name = "bindgen"
20-
21-
[build-dependencies]
22-
quasi_codegen = "0.20"
23-
2416
[dependencies]
25-
cfg-if = "0.1.0"
2617
clang-sys = "0.8.0"
2718
clap = "2"
28-
lazy_static = "0.1.*"
29-
libc = "0.2"
19+
libbindgen = { path = "libbindgen" }
3020
log = "0.3"
3121
env_logger = "0.3"
3222
rustc-serialize = "0.3.19"
33-
syntex_syntax = "0.44"
34-
regex = "0.1"
35-
cexpr = "0.2"
36-
37-
[dependencies.aster]
38-
features = ["with-syntex"]
39-
version = "0.28"
40-
41-
[dependencies.clippy]
42-
optional = true
43-
version = "*"
44-
45-
[dependencies.quasi]
46-
features = ["with-syntex"]
47-
version = "0.20"
4823

4924
[features]
50-
llvm_stable = []
51-
static = []
52-
# This feature only exists for CI -- don't use it!
53-
_docs = []
54-
55-
[lib]
56-
name = "bindgen"
57-
path = "src/lib.rs"
58-
59-
[dev-dependencies.tests_expectations]
60-
path = "tests/expectations"
61-
62-
[[test]]
63-
name = "tests"
25+
llvm_stable = ["libbindgen/llvm_stable"]

Makefile

-34
This file was deleted.

README.md

+34-8
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,40 @@ $ LIBCLANG_PATH=path/to/clang-3.9/build/lib \
7676
cargo build
7777
```
7878

79+
# Library usage with `build.rs`
80+
81+
In `Cargo.toml`:
82+
83+
```toml
84+
[package]
85+
...
86+
build = "build.rs"
87+
88+
[build-dependencies.libbindgen]
89+
git = "https://github.com/servo/rust-bindgen"
90+
features = ["llvm_stable"]
91+
```
92+
93+
In `build.rs`:
94+
95+
```rust
96+
extern crate libbindgen;
97+
98+
fn main() {
99+
let _ = libbindgen::builder()
100+
.header("example.h")
101+
.use_core()
102+
.generate().unwrap()
103+
.write_to_file(concat!(env!("OUT_DIR"), "/example.rs"));
104+
}
105+
```
106+
107+
In `src/main.rs`:
108+
109+
```rust
110+
include!(concat!(env!("OUT_DIR"), "/example.rs"));
111+
```
112+
79113
# Command Line Usage
80114

81115
There are a few options documented when running `./bindgen --help`. Other
@@ -142,11 +176,3 @@ the ones that would be generated for `nsTArray_Simple`.
142176
143177
The `nocopy` annotation is used to prevent bindgen to autoderive the `Copy`
144178
and `Clone` traits for a type.
145-
146-
# Macro Usage
147-
148-
This mode isn't actively maintained, so no promises are made around it. Check
149-
out the upstream documentation for info about how it *should* work.
150-
151-
[sm-script]: https://github.com/servo/rust-mozjs/blob/master/etc/bindings.sh
152-
[stylo-scripts]: https://github.com/servo/servo/tree/master/components/style/binding_tools

bindgen_plugin/Cargo.toml

-20
This file was deleted.

0 commit comments

Comments
 (0)