blob: df4fe0a718ca64bda08e0a6622e0eb0acde398d4 [file] [log] [blame] [view]
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +00001# rs_bindings_from_cc
2
Marcel Hlopko7ebafb22021-07-30 12:14:00 +00003Disclaimer: This project is experimental, under heavy development, and should
Marcel Hlopkoc3556422022-03-14 16:08:14 +00004not be used yet.
Marcel Hlopko7ebafb22021-07-30 12:14:00 +00005
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +00006`: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
11For convenience, `:test_wrapper` is a shell script that passes all Clang command
12line flags from the current Blaze C++ toolchain:
13
14```
Devin Jeanpierred7f4b3b2021-10-06 15:28:18 +000015bazel run //rs_bindings_from_cc:test_wrapper -- --public_headers=hello_world.h
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +000016```
17
18or:
19
20```
21bazel build //rs_bindings_from_cc:test_wrapper
Devin Jeanpierred7f4b3b2021-10-06 15:28:18 +000022bazel-bin/rs_bindings_from_cc/test_wrapper --public_headers=hello_world.h
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +000023```
24
25## Testing
26
Marcel Hlopko5b8c1122021-12-10 06:59:23 +000027If possible follow these recommendations:
Marcel Hlopkoe8f1c4e2021-07-28 18:12:49 +000028
Marcel Hlopko5b8c1122021-12-10 06:59:23 +000029* 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 Forster500b4762022-01-27 12:30:17 +000038 [`importer`](/rs_bindings_from_cc/importer.h)
Marcel Hlopko5b8c1122021-12-10 06:59:23 +000039 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 Forster500b4762022-01-27 12:30:17 +000044 ([`importer_test.cc`](/rs_bindings_from_cc/importer_test.cc))
Marcel Hlopko5b8c1122021-12-10 06:59:23 +000045 * 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.
Googlerb2ef22d2022-01-04 11:17:22 +000055* Write full executable end-to-end tests (verifying that interop tools and
Marcel Hlopko5b8c1122021-12-10 06:59:23 +000056 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 Jeanpierred9c382a2021-12-15 10:23:25 +000058
Googlerb2ef22d2022-01-04 11:17:22 +000059To get Rust backtraces for `rs_bindings_from_cc` when running end-to-end tests,
60use `bazel test --action_env=RUST_BACKTRACE=1` to run the tests.
61
Devin Jeanpierred9c382a2021-12-15 10:23:25 +000062## Contributing
63
64Chat room: https://chat.google.com/room/AAAAImO--WA
65
6620% starter projects list: b/hotlists/3645339