1
- # Contributing to ` servo/rust- bindgen`
1
+ # Contributing to ` bindgen `
2
2
3
3
Hi! We'd love to have your contributions! If you want help or mentorship, reach
4
- out to us in a GitHub issue, or stop by #servo on irc.mozilla.org and introduce
5
- yourself.
6
-
7
- * [ Code of Conduct] ( #coc )
8
- * [ Filing an Issue] ( #issue )
9
- * [ Building] ( #building )
10
- * [ Testing] ( #tests )
11
- * [ Overview] ( #tests-overview )
12
- * [ Running All Tests] ( #tests-all )
13
- * [ Running a Single, Specific Test] ( #tests-one )
14
- * [ Authoring New Tests] ( #tests-new )
15
- * [ Automatic Code Formatting] ( #formatting )
16
- * [ Debug Logging] ( #logs )
17
- * [ Using ` creduce ` to Minimize Test Cases] ( #creduce )
18
-
19
- ## Code of Conduct <span id =" coc " />
4
+ out to us in a GitHub issue, or stop by
5
+ [ #servo on irc.mozilla.org] ( irc://irc.mozilla.org#servo ) and introduce yourself.
6
+
7
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
8
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
9
+
10
+
11
+ - [ Code of Conduct] ( #code-of-conduct )
12
+ - [ Filing an Issue] ( #filing-an-issue )
13
+ - [ Building] ( #building )
14
+ - [ Testing] ( #testing )
15
+ - [ Overview] ( #overview )
16
+ - [ Running All Tests] ( #running-all-tests )
17
+ - [ Authoring New Tests] ( #authoring-new-tests )
18
+ - [ Automatic code formatting] ( #automatic-code-formatting )
19
+ - [ Debug Logging] ( #debug-logging )
20
+ - [ Using ` creduce ` to Minimize Test Cases] ( #using-creduce-to-minimize-test-cases )
21
+ - [ Isolating Your Test Case] ( #isolating-your-test-case )
22
+ - [ Writing a Predicate Script] ( #writing-a-predicate-script )
23
+
24
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
25
+
26
+ ## Code of Conduct
20
27
21
28
We abide by the [ Rust Code of Conduct] [ coc ] and ask that you do as well.
22
29
23
30
[ coc ] : https://www.rust-lang.org/en-US/conduct.html
24
31
25
- ## Filing an Issue < span id = " issue " />
32
+ ## Filing an Issue
26
33
27
34
Think you've found a bug? File an issue! To help us understand and reproduce the
28
35
issue, provide us with:
@@ -33,39 +40,68 @@ issue, provide us with:
33
40
* The actual ` bindgen ` output
34
41
* The [ debugging logs] ( #logs ) generated when running ` bindgen ` on this testcase
35
42
36
- ## Building <span id =" building " />
43
+ ## Building
44
+
45
+ To build ` libbindgen ` :
46
+
47
+ ```
48
+ $ cd bindgen/libbindgen
49
+ $ cargo build
50
+ ```
51
+
52
+ To build the ` bindgen ` executable:
37
53
38
- Build instructions are in the [ README] ( ./README.md ) .
54
+ ```
55
+ $ cd bindgen/bindgen
56
+ $ cargo build
57
+ ```
58
+
59
+ If you installed multiple versions of llvm, it may not be able to locate the
60
+ latest version of libclang. In that case, you may want to either uninstall other
61
+ versions of llvm, or specify the path of the desired libclang explicitly:
62
+
63
+ ```
64
+ $ export LIBCLANG_PATH=path/to/clang-3.9/lib
65
+ ```
66
+
67
+ On Linux and macOS, you may also need to add a path to ` libclang.so ` (usually
68
+ the same path as above) to library search path. This can be done as below:
69
+
70
+ ```
71
+ $ export LD_LIBRARY_PATH=path/to/clang-3.9/lib # for Linux
72
+ $ export DYLD_LIBRARY_PATH=path/to/clang-3.9/lib # for macOS
73
+ ```
39
74
40
- Additionally, you may want to build and test with the ` _docs ` feature to ensure
75
+ Additionally, you may want to build and test with the ` docs_ ` feature to ensure
41
76
that you aren't forgetting to document types and functions. CI will catch it if
42
77
you forget, but the turn around will be a lot slower ;)
43
78
44
79
```
45
80
$ cd libbindgen && cargo build --features "llvm_stable _docs"
46
81
```
47
82
48
- ## Testing < span id = " tests " />
83
+ ## Testing
49
84
50
85
Code for binding generation and testing thereof is in the ` libbindgen ` crate.
51
86
The following sections assume you are working in that subdirectory.
52
87
53
- ### Overview < span id = " tests-overview " />
88
+ ### Overview
54
89
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
58
- ` tests/expectations/tests/my_header.rs ` .
90
+ Input C/C++ test headers reside in the ` libbindgen/tests/headers `
91
+ directory. Expected output Rust bindings live in
92
+ ` libbindgen/tests/expectations/tests ` . For example,
93
+ ` libbindgen/tests/headers/my_header.h ` 's expected generated Rust bindings would
94
+ be ` libbindgen/tests/expectations/tests/my_header.rs ` .
59
95
60
96
Run ` cargo test ` to compare generated Rust bindings to the expectations.
61
97
62
- ### Running All Tests < span id = " tests-all " />
98
+ ### Running All Tests
63
99
64
100
```
65
101
$ cargo test [--features llvm_stable]
66
102
```
67
103
68
- ### Authoring New Tests < span id = " tests-new " />
104
+ ### Authoring New Tests
69
105
70
106
To add a new test header to the suite, simply put it in the ` tests/headers `
71
107
directory. Next, run ` bindgen ` to generate the initial expected output Rust
@@ -84,7 +120,7 @@ Then verify the new Rust bindings compile and pass some basic tests:
84
120
$ cargo test -p tests_expectations
85
121
```
86
122
87
- ## Automatic code formatting < span id = " formatting " />
123
+ ## Automatic code formatting
88
124
89
125
There's a ` rustfmt.toml ` file in the repo. Ideally changes should be consistent
90
126
with the style, though that's not enforced right now.
@@ -105,10 +141,10 @@ $ cargo install rustfmt
105
141
106
142
And ensure ` ~/.cargo/bin ` is on your path.
107
143
108
- ## Debug Logging < span id = " logs " />
144
+ ## Debug Logging
109
145
110
146
To help debug what ` bindgen ` is doing, you can define the environment variable
111
- ` RUST_LOG=bindgen ` to get a bunch of debugging log spew.
147
+ ` RUST_LOG=libbindgen ` to get a bunch of debugging log spew.
112
148
113
149
```
114
150
$ RUST_LOG=libbindgen ./target/debug/bindgen [flags...] ~/path/to/some/header.h
@@ -117,10 +153,11 @@ $ RUST_LOG=libbindgen ./target/debug/bindgen [flags...] ~/path/to/some/header.h
117
153
This logging can also be used when debugging failing tests:
118
154
119
155
```
120
- $ RUST_LOG=libbindgen cd libbindgen && cargo test
156
+ $ cd libbindgen
157
+ $ RUST_LOG=libbindgen cargo test
121
158
```
122
159
123
- ## Using ` creduce ` to Minimize Test Cases < span id = " creduce " />
160
+ ## Using ` creduce ` to Minimize Test Cases
124
161
125
162
If you are hacking on ` bindgen ` and find a test case that causes an unexpected
126
163
panic, results in bad Rust bindings, or some other incorrectness in ` bindgen ` ,
0 commit comments