Building in Android

创建两个 genrule:一个用于生成 CXX 头文件,另一个用于生成 CXX 源文件。然后,这些内容会被用作 cc_library_static 的输入。

// Generate a C++ header containing the C++ bindings // to the Rust exported functions in lib.rs. genrule { name: "libcxx_test_bridge_header", tools: ["cxxbridge"], cmd: "$(location cxxbridge) $(in) --header > $(out)", srcs: ["lib.rs"], out: ["lib.rs.h"], } // Generate the C++ code that Rust calls into. genrule { name: "libcxx_test_bridge_code", tools: ["cxxbridge"], cmd: "$(location cxxbridge) $(in) > $(out)", srcs: ["lib.rs"], out: ["lib.rs.cc"], }

Speaker Notes

  • cxxbridge 工具是一款独立工具,用于生成桥接模块的 C++ 端。它包含在 Android 中,并作为 Soong 工具提供。
  • 按照惯例,如果您的 Rust 源文件是 lib.rs,则头文件将命名为 lib.rs.h,源文件将命名为 lib.rs.cc。不过,系统并不强制执行此命名惯例。