添加第三方 Crate

Rust 库被称为 crate,可在 crates.io 中找到。Rust 的 crate 之间非常容易相互依赖。事实证明,他们确实如此!

属性C++ libraryRust crate
Build system很多保持一致:Cargo.toml
典型库的大小
传递依赖项很少很多

对于 Chromium 工程师来说,这种依赖关系具有以下利弊:

  • 所有 crate 都使用共同的构建系统,这样我们就可以自动将其收录到 Chromium 中…
  • …但是,crate 通常具有传递依赖项,因此可能需要引入多个库。

我们将讨论以下内容:

  • 如何将 crate 添加到 Chromium 源代码树中
  • 如何为其制定 gn 构建规则
  • 如何审核其源代码以确保足够的安全性。
All of the things in the table on this slide are generalizations, and counter-examples can be found. But in general it's important for students to understand that most Rust code depends on other Rust libraries, because it's easy to do so, and that this has both benefits and costs.