Including unsafe Rust Code

Unsafe Rust code is forbidden in rust_static_library by default —- it won’t compile. If you need unsafe Rust code, add allow_unsafe = true to the gn target. (Later in the course we’ll see circumstances where this is necessary.)

  1. import("//build/rust/rust_static_library.gni")
  2. rust_static_library("my_rust_lib") {
  3. crate_root = "lib.rs"
  4. sources = [
  5. "lib.rs",
  6. "hippopotamus.rs"
  7. ]
  8. allow_unsafe = true
  9. }