|
| 1 | +# Contributing to `servo/rust-bindgen` |
| 2 | + |
| 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 | +* [Debug Logging](#logs) |
| 11 | +* [Testing](#tests) |
| 12 | + * [Overview](#tests-overview) |
| 13 | + * [Running All Tests](#tests-all) |
| 14 | + * [Running a Single, Specific Test](#tests-one) |
| 15 | + * [Authoring New Tests](#tests-new) |
| 16 | + |
| 17 | +## Code of Conduct <span id="coc"/> |
| 18 | + |
| 19 | +We abide by the [Rust Code of Conduct][coc] and ask that you do as well. |
| 20 | + |
| 21 | +[coc]: https://www.rust-lang.org/en-US/conduct.html |
| 22 | + |
| 23 | +## Filing an Issue <span id="issue"/> |
| 24 | + |
| 25 | +Think you've found a bug? File an issue! To help us understand and reproduce the |
| 26 | +issue, provide us with: |
| 27 | + |
| 28 | +* A (preferrably reduced) C/C++ header file that reproduces the issue |
| 29 | +* The `bindgen` flags used to reproduce the issue with the header file |
| 30 | +* The expected `bindgen` output |
| 31 | +* The actual `bindgen` output |
| 32 | +* The [debugging logs](#logs) generated when running `bindgen` on this testcase |
| 33 | + |
| 34 | +## Building <span id="building"/> |
| 35 | + |
| 36 | +Build instructions are in the [README](./README.md). |
| 37 | + |
| 38 | +## Testing <span id="tests"/> |
| 39 | + |
| 40 | +### Overview <span id="tests-overview"/> |
| 41 | + |
| 42 | +Input C/C++ test headers reside in the `tests/headers` directory. The expected |
| 43 | +output rust bindings live in `tests/expectations`; for example, |
| 44 | +`tests/headers/my_header.h`'s expected generated rust bindings would be |
| 45 | +`tests/expectations/my_header.rs`. |
| 46 | + |
| 47 | +The `tests/tools/run-bindgen.py` script runs `bindgen` on the test headers and |
| 48 | +compares the results to the expectations. |
| 49 | + |
| 50 | +### Running All Tests <span id="tests-all"/> |
| 51 | + |
| 52 | +``` |
| 53 | +$ cargo test [--features llvm_stable] |
| 54 | +``` |
| 55 | + |
| 56 | +This spawns a `tests/tools/run-bindgen.py` subprocess for each test header. |
| 57 | + |
| 58 | +### Running a Single, Specific Test <span id="tests-one"/> |
| 59 | + |
| 60 | +``` |
| 61 | +$ ./tests/tools/run-bindgen.py ./target/debug/bindgen ./tests/headers/some_header.h |
| 62 | +``` |
| 63 | + |
| 64 | +To learn more about the options available with `run-bindgen.py`: |
| 65 | + |
| 66 | +``` |
| 67 | +$ ./tests/tools/run-bindgen.py --help |
| 68 | +``` |
| 69 | + |
| 70 | +### Authoring New Tests <span id="tests-new"/> |
| 71 | + |
| 72 | +To add a new test header to the suite, simply put it in the `tests/headers` |
| 73 | +directory. Next, run the `run-bindgen.py` script with the new test header, which |
| 74 | +will generate the initial expected output rust bindings. |
| 75 | + |
| 76 | +If your new test requires certain flags to be passed to `bindgen`, you can |
| 77 | +specify them at the top of the test header, with a comment like this: |
| 78 | + |
| 79 | +```c |
| 80 | +// bindgen-flags: --enable-cxx-namespaces -- -std=c++14 |
| 81 | +``` |
| 82 | + |
| 83 | +If your new test requires `bindgen` to be built with certain features, you can |
| 84 | +specify the required features at the top of the test header in a similar manner: |
| 85 | + |
| 86 | +```c |
| 87 | +// bingden-features: llvm_stable |
| 88 | +``` |
| 89 | + |
| 90 | +## Debug Logging <span id="logs"/> |
| 91 | + |
| 92 | +To help debug what `bindgen` is doing, you can define the environment variable |
| 93 | +`RUST_LOG=bindgen` to get a bunch of debugging log spew. |
| 94 | + |
| 95 | +``` |
| 96 | +$ RUST_LOG=bindgen ./target/debug/bindgen [flags...] ~/path/to/some/header.h |
| 97 | +``` |
| 98 | + |
| 99 | +This logging can also be used when debugging failing tests under |
| 100 | +`run-bindgen.py`: |
| 101 | + |
| 102 | +``` |
| 103 | +$ RUST_LOG=bindgen ./tests/tools/run-bindgen.py ./target/debug/bindgen tests/headers/whatever.h |
| 104 | +``` |
0 commit comments