在 Chromium C++ 中导入 Rust 代码

只需将上述目标添加到某些 Chromium C++ 目标的 deps 中即可。

1. import("//build/rust/rust_static_library.gni")

3. rust_static_library("my_rust_lib") {
4. crate_root = "lib.rs"
5. sources = [ "lib.rs" ]
6. }

8. # or source_set, static_library etc.
9. component("preexisting_cpp") {
10. deps = [ ":my_rust_lib" ]
11. }

We’ll see that this relationship only works if the Rust code exposes plain C APIs which can be called from C++, or if we use a C++/Rust interop tool.