Including unsafe Rust Code

默认情况下,禁止在 rust_static_library 中使用不安全的 Rust 代码,因为此类代码无法编译。如需使用不安全的 Rust 代码,请将 allow_unsafe = true 添加到 gn 目标中。(在本课程的稍后部分,我们将介绍在哪些情形下必须这样做。)

import("//build/rust/rust_static_library.gni") rust_static_library("my_rust_lib") { crate_root = "lib.rs" sources = [ "lib.rs", "hippopotamus.rs" ] allow_unsafe = true }