Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 1 | # rs_bindings_from_cc |
| 2 | |
Marcel Hlopko | 7ebafb2 | 2021-07-30 12:14:00 +0000 | [diff] [blame] | 3 | Disclaimer: This project is experimental, under heavy development, and should |
Marcel Hlopko | c355642 | 2022-03-14 16:08:14 +0000 | [diff] [blame] | 4 | not be used yet. |
Marcel Hlopko | 7ebafb2 | 2021-07-30 12:14:00 +0000 | [diff] [blame] | 5 | |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 6 | `:rs_bindings_from_cc` parses C++ headers and generates: |
| 7 | |
| 8 | * a Rust source file with bindings for the C++ API |
| 9 | * a C++ source file with the implementation of the bindings |
| 10 | |
| 11 | For convenience, `:test_wrapper` is a shell script that passes all Clang command |
| 12 | line flags from the current Blaze C++ toolchain: |
| 13 | |
| 14 | ``` |
Devin Jeanpierre | d7f4b3b | 2021-10-06 15:28:18 +0000 | [diff] [blame] | 15 | bazel run //rs_bindings_from_cc:test_wrapper -- --public_headers=hello_world.h |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 16 | ``` |
| 17 | |
| 18 | or: |
| 19 | |
| 20 | ``` |
| 21 | bazel build //rs_bindings_from_cc:test_wrapper |
Devin Jeanpierre | d7f4b3b | 2021-10-06 15:28:18 +0000 | [diff] [blame] | 22 | bazel-bin/rs_bindings_from_cc/test_wrapper --public_headers=hello_world.h |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 23 | ``` |
| 24 | |
| 25 | ## Testing |
| 26 | |
Marcel Hlopko | 5b8c112 | 2021-12-10 06:59:23 +0000 | [diff] [blame] | 27 | If possible follow these recommendations: |
Marcel Hlopko | e8f1c4e | 2021-07-28 18:12:49 +0000 | [diff] [blame] | 28 | |
Marcel Hlopko | 5b8c112 | 2021-12-10 06:59:23 +0000 | [diff] [blame] | 29 | * Unit tests for |
| 30 | [`src_code_gen`](/rs_bindings_from_cc/src_code_gen.rs) |
| 31 | should be: |
| 32 | * written in Rust |
| 33 | * have snippets of C++ as input |
| 34 | * use |
| 35 | [`assert_cc_matches!/assert_rs_matches!/assert_cc_not_matches!/assert_rs_not_matches!`](/rs_bindings_from_cc/token_stream_matchers.rs) |
| 36 | macros |
| 37 | * Unit tests for the |
Michael Forster | 500b476 | 2022-01-27 12:30:17 +0000 | [diff] [blame] | 38 | [`importer`](/rs_bindings_from_cc/importer.h) |
Marcel Hlopko | 5b8c112 | 2021-12-10 06:59:23 +0000 | [diff] [blame] | 39 | should be: |
| 40 | * written in Rust |
| 41 | ([`ir_from_cc_test.rs`](/rs_bindings_from_cc/ir_from_cc_test.rs)) |
| 42 | so they cover both AST logic and IR serialization/deserialization, but |
| 43 | C++ tests (thanks to its nice matchers) are also OK at the moment |
Michael Forster | 500b476 | 2022-01-27 12:30:17 +0000 | [diff] [blame] | 44 | ([`importer_test.cc`](/rs_bindings_from_cc/importer_test.cc)) |
Marcel Hlopko | 5b8c112 | 2021-12-10 06:59:23 +0000 | [diff] [blame] | 45 | * have snippets of C++ as input |
| 46 | * make assertions on the content of the IR |
| 47 | * Write tests for the command line interface of interop tools in |
| 48 | [`rs_bindings_from_cc_test.sh`](/rs_bindings_from_cc/test/rs_bindings_from_cc_test.sh). |
| 49 | * Write golden file tests (comparing both the C++ and Rust generated source |
| 50 | code against the checked-in files) in |
| 51 | [`test/golden`](/rs_bindings_from_cc/test/golden/). |
| 52 | Run |
| 53 | [`rs_bindings_from_cc/test/golden/update.sh`](/rs_bindings_from_cc/test/golden/update.sh) |
| 54 | to regenerate checked-in files. |
Googler | b2ef22d | 2022-01-04 11:17:22 +0000 | [diff] [blame] | 55 | * Write full executable end-to-end tests (verifying that interop tools and |
Marcel Hlopko | 5b8c112 | 2021-12-10 06:59:23 +0000 | [diff] [blame] | 56 | Blaze rules generate outputs that can be built and executed) as small |
| 57 | projects with a `rust_test` or `cc_test` on top in subpackages of `test`. |
Devin Jeanpierre | d9c382a | 2021-12-15 10:23:25 +0000 | [diff] [blame] | 58 | |
Googler | b2ef22d | 2022-01-04 11:17:22 +0000 | [diff] [blame] | 59 | To get Rust backtraces for `rs_bindings_from_cc` when running end-to-end tests, |
| 60 | use `bazel test --action_env=RUST_BACKTRACE=1` to run the tests. |
| 61 | |
Devin Jeanpierre | d9c382a | 2021-12-15 10:23:25 +0000 | [diff] [blame] | 62 | ## Contributing |
| 63 | |
| 64 | Chat room: https://chat.google.com/room/AAAAImO--WA |
| 65 | |
| 66 | 20% starter projects list: b/hotlists/3645339 |