Building in Android
创建两个 genrule:一个用于生成 CXX 头文件,另一个用于生成 CXX 源文件。然后,这些内容会被用作 cc_library_static 的输入。
1. // Generate a C++ header containing the C++ bindings
2. // to the Rust exported functions in lib.rs.
3. genrule {
4. name: "libcxx_test_bridge_header",
5. tools: ["cxxbridge"],
6. cmd: "$(location cxxbridge) $(in) --header > $(out)",
7. srcs: ["lib.rs"],
8. out: ["lib.rs.h"],
9. }
11. // Generate the C++ code that Rust calls into.
12. genrule {
13. name: "libcxx_test_bridge_code",
14. tools: ["cxxbridge"],
15. cmd: "$(location cxxbridge) $(in) > $(out)",
16. srcs: ["lib.rs"],
17. out: ["lib.rs.cc"],
18. }
cxxbridge工具是一款独立工具,用于生成桥接模块的 C++ 端。它包含在 Android 中,并作为 Soong 工具提供。- 按照惯例,如果您的 Rust 源文件是
lib.rs,则头文件将命名为lib.rs.h,源文件将命名为lib.rs.cc。不过,系统并不强制执行此命名惯例。
