tree: da8240a5ed77af7ba3daeb9ad5d899c401460266 [path history] [tgz]
  1. bazel_support/
  2. importers/
  3. support/
  4. test/
  5. ast_consumer.cc
  6. ast_consumer.h
  7. ast_convert.cc
  8. ast_convert.h
  9. ast_util.cc
  10. ast_util.h
  11. bazel_types.cc
  12. bazel_types.h
  13. bazel_types_test.cc
  14. BUILD
  15. cmdline.cc
  16. cmdline.h
  17. cmdline_test.cc
  18. collect_instantiations.cc
  19. collect_instantiations.h
  20. collect_instantiations.rs
  21. collect_instantiations_test.cc
  22. collect_namespaces.cc
  23. collect_namespaces.h
  24. collect_namespaces_test.cc
  25. decl_importer.h
  26. error_report.rs
  27. frontend_action.cc
  28. frontend_action.h
  29. generate_bindings_and_metadata.cc
  30. generate_bindings_and_metadata.h
  31. generate_bindings_and_metadata_test.cc
  32. generate_bindings_for_target_with_tool_flags.sh
  33. importer.cc
  34. importer.h
  35. importer_test.cc
  36. ir.cc
  37. ir.h
  38. ir.rs
  39. ir_from_cc.cc
  40. ir_from_cc.h
  41. ir_from_cc_test.rs
  42. ir_matchers.rs
  43. ir_testing.rs
  44. json_from_cc.cc
  45. known_types_map.cc
  46. known_types_map.h
  47. README.md
  48. rs_bindings_from_cc.cc
  49. src_code_gen.cc
  50. src_code_gen.h
  51. src_code_gen.rs
rs_bindings_from_cc/README.md

rs_bindings_from_cc

Disclaimer: This project is experimental, under heavy development, and should not be used yet.

:rs_bindings_from_cc parses C++ headers and generates:

  • a Rust source file with bindings for the C++ API
  • a C++ source file with the implementation of the bindings

For convenience, :test_wrapper is a shell script that passes all Clang command line flags from the current Bazel C++ toolchain:

bazel run //rs_bindings_from_cc:test_wrapper -- --public_headers=hello_world.h

or:

bazel build //rs_bindings_from_cc:test_wrapper
bazel-bin/rs_bindings_from_cc/test_wrapper --public_headers=hello_world.h

Testing

If possible follow these recommendations:

To run individual rust tests with bazel test (like bazel test --test_filter=<test> for gtest cases), give the test function name as --test_arg=<test>.

To get Rust backtraces for rs_bindings_from_cc when running end-to-end tests, use bazel test --action_env=RUST_BACKTRACE=1 to run the tests.

Debugging

If you want to build the tool specially, for example using sanitizers, use the script at rs_bindings_from_cc/generate_bindings_for_target_with_tool_flags.sh, for example:

rs_bindings_from_cc/generate_bindings_for_target_with_tool_flags.sh \
  //base \
  --config=asan

If you want to build the tool specially and use it for generating bindings from a golden file, use the <header basename>_rs_test target. For types.h the command would be:

rs_bindings_from_cc/generate_bindings_for_target_with_tool_flags.sh \
  //rs_bindings_from_cc/test/golden:types_rs_test \
  --config=asan

If you want to see the Clang AST dump of some file (generated files work too), run:

bazel build --per_file_copt=<PATH_TO_FILE>@-Xclang,-ast-dump,-fno-color-diagnostics <TARGET> > /tmp/output_file

Contributing

Chat room (internal): https://chat.google.com/room/AAAAImO--WA

20% starter projects list (internal): b/hotlists/3645339