在 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。不過,系統不會強制執行這項命名慣例。