mirror of
https://github.com/google/comprehensive-rust.git
synced 2024-12-15 06:20:32 +02:00
Fix spelling of CXX and Cargo (mostly in the Chromium part). (#1549)
This commit is contained in:
parent
53baee82e3
commit
584c957d69
@ -245,7 +245,7 @@
|
||||
|
||||
- [Welcome](chromium.md)
|
||||
- [Setup](chromium/setup.md)
|
||||
- [Using cargo for experimental tools](chromium/cargo.md)
|
||||
- [Comparing Chromium and Cargo ecosystems](chromium/cargo.md)
|
||||
- [Policy](chromium/policy.md)
|
||||
- [Build Rules](chromium/build-rules.md)
|
||||
- [Unsafe code](chromium/build-rules/unsafe.md)
|
||||
@ -254,9 +254,9 @@
|
||||
- [Exercise](exercises/chromium/build-rules.md)
|
||||
- [Interoperability with C++](chromium/interoperability-with-cpp.md)
|
||||
- [Example bindings](chromium/interoperability-with-cpp/example-bindings.md)
|
||||
- [Limitations of cxx](chromium/interoperability-with-cpp/limitations-of-cxx.md)
|
||||
- [cxx error handling](chromium/interoperability-with-cpp/error-handling.md)
|
||||
- [Using cxx in Chromium](chromium/interoperability-with-cpp/using-cxx-in-chromium.md)
|
||||
- [Limitations of CXX](chromium/interoperability-with-cpp/limitations-of-cxx.md)
|
||||
- [CXX error handling](chromium/interoperability-with-cpp/error-handling.md)
|
||||
- [Using CXX in Chromium](chromium/interoperability-with-cpp/using-cxx-in-chromium.md)
|
||||
- [Exercise](exercises/chromium/interoperability-with-cpp.md)
|
||||
- [Adding third party crates](chromium/adding-third-party-crates.md)
|
||||
- [Configuring Cargo.toml](chromium/adding-third-party-crates/configuring-cargo-toml.md)
|
||||
|
@ -19,7 +19,7 @@ We will look at `rust_binary` and `rust_library` next.
|
||||
|
||||
Additional items speaker may mention:
|
||||
|
||||
- cargo is not optimized for multi-language repos, and also downloads packages from the internet.
|
||||
- Cargo is not optimized for multi-language repos, and also downloads packages from the internet.
|
||||
|
||||
- For compliance and performance, Android must have crates in-tree. It must also interop with C/C++/Java code. Soong fills that gap.
|
||||
|
||||
|
@ -20,7 +20,7 @@ Take a close look, especially at the things generated in `third_party/rust`.
|
||||
|
||||
Talk a little about semver --- and specifically the way that in Chromium
|
||||
it's to allow multiple incompatible versions of a crate, which is discouraged
|
||||
but sometimes necessary in the cargo ecosystem.
|
||||
but sometimes necessary in the Cargo ecosystem.
|
||||
|
||||
</detail>
|
||||
|
||||
|
@ -12,7 +12,7 @@ So, your options are:
|
||||
* Apply a patch to the crate.
|
||||
|
||||
Patches should be kept in `third_party/rust/chromium_crates_io/patches/<crate>` -
|
||||
see for example the [patches against the cxx crate][3] - and will be applied
|
||||
see for example the [patches against the `cxx` crate][3] - and will be applied
|
||||
automatically by `gnrt` each time it upgrades the crate.
|
||||
|
||||
[1]: https://crates.io/crates/cc
|
||||
|
@ -32,7 +32,7 @@ crate is a compilation unit. A `static_library` is the smallest unit.)
|
||||
|
||||
Students might be wondering why we need a gn template, rather than using
|
||||
[gn's built-in support for Rust static libraries][0].
|
||||
The answer is that this template provides support for cxx interop, Rust features,
|
||||
The answer is that this template provides support for CXX interop, Rust features,
|
||||
and unit tests, some of which we'll use later.
|
||||
|
||||
</details>
|
||||
|
@ -1,10 +1,10 @@
|
||||
# Interoperability with C++
|
||||
|
||||
The Rust community offers multiple options for C++/Rust interop, with new tools
|
||||
being developed all the time. At the moment, Chromium uses a tool called "cxx".
|
||||
being developed all the time. At the moment, Chromium uses a tool called CXX.
|
||||
|
||||
You describe your whole language boundary in an interface definition language
|
||||
(which looks a lot like Rust) and then cxx tools generate declarations for
|
||||
(which looks a lot like Rust) and then CXX tools generate declarations for
|
||||
functions and types in both Rust and C++.
|
||||
|
||||
<img src="../android/interoperability/cpp/overview.svg" alt="Overview diagram of cxx, showing that the same interface definition is used to create both C++ and Rust side code which then communicate via a lowest common denominator C API">
|
||||
|
@ -1,6 +1,6 @@
|
||||
# cxx error handling
|
||||
# CXX error handling
|
||||
|
||||
cxx's support for `Result<T,E>` relies on C++ exceptions, so we can't use that
|
||||
CXX's support for `Result<T,E>` relies on C++ exceptions, so we can't use that
|
||||
in Chromium. Alternatives:
|
||||
|
||||
* Where success can be represented as a simple Boolean, as done in our [QR code generator][1]:
|
||||
@ -35,7 +35,7 @@ in Chromium. Alternatives:
|
||||
```
|
||||
|
||||
|
||||
The best way to learn cxx is by doing, so, another exercise!
|
||||
The best way to learn CXX is by doing, so, another exercise!
|
||||
|
||||
[0]: https://cxx.rs/binding/result.html
|
||||
[1]: https://source.chromium.org/chromium/chromium/src/+/main:components/qr_code_generator/qr_code_generator_ffi_glue.rs;l=10
|
@ -1,6 +1,6 @@
|
||||
# Example bindings
|
||||
|
||||
cxx requires that the whole C++/Rust boundary is declared in `cxx::bridge`
|
||||
CXX requires that the whole C++/Rust boundary is declared in `cxx::bridge`
|
||||
"modules" inside `.rs` source code.
|
||||
|
||||
```rust,ignore
|
||||
|
@ -1,18 +1,18 @@
|
||||
## Limitations of cxx
|
||||
## Limitations of CXX
|
||||
|
||||
By far the most useful page when using cxx is the [type reference][1].
|
||||
By far the most useful page when using CXX is the [type reference][1].
|
||||
|
||||
cxx fundamentally suits cases where:
|
||||
CXX fundamentally suits cases where:
|
||||
|
||||
* Your Rust-C++ interface is sufficiently simple that you can declare all of it.
|
||||
* You're using only the types natively supported by cxx already, for example
|
||||
* You're using only the types natively supported by CXX already, for example
|
||||
`std::unique_ptr`, `std::string`, `&[u8]` etc.
|
||||
|
||||
It has many limitations --- for example lack of support for Rust's `Option` type.
|
||||
|
||||
These limitations constrain us to using Rust in Chromium only for well isolated
|
||||
"leaf nodes" rather than for arbitrary Rust-C++ interop. When considering
|
||||
a use-case for Rust in Chromium, a good starting point is to draft the cxx
|
||||
a use-case for Rust in Chromium, a good starting point is to draft the CXX
|
||||
bindings for the language boundary to see if it appears simple enough.
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ In addition, right now, Rust code in one component cannot depend on Rust
|
||||
code in another, due to linking details in our component build. That's another
|
||||
reason to restrict Rust to use in leaf nodes.
|
||||
|
||||
You should also discuss some of the other sticky points with cxx, for example:
|
||||
You should also discuss some of the other sticky points with CXX, for example:
|
||||
|
||||
* Its error handling is based around C++ exceptions (given on the next slide)
|
||||
* Function pointers are awkward to use.
|
||||
|
@ -20,7 +20,7 @@ C++ headers will be generated at a sensible location, so you can just
|
||||
```
|
||||
|
||||
You will find some utility functions in `//base` to convert to/from Chromium
|
||||
C++ types to cxx Rust types --- for example [`SpanToRustSlice`][0].
|
||||
C++ types to CXX Rust types --- for example [`SpanToRustSlice`][0].
|
||||
|
||||
<details>
|
||||
|
||||
@ -34,7 +34,7 @@ such a keyword, and is [controversial][1], but strictly, bringing any foreign
|
||||
code into a Rust binary can cause unexpected behavior from Rust's perspective.
|
||||
|
||||
The narrow answer lies in the diagram at the top of this page --- behind the
|
||||
scenes, cxx generates Rust `unsafe` and `extern "C"` functions just like
|
||||
scenes, CXX generates Rust `unsafe` and `extern "C"` functions just like
|
||||
we did manually in the previous section.
|
||||
|
||||
</details>
|
||||
|
@ -39,12 +39,12 @@ Students will likely need some hints here. Hints include:
|
||||
on the C++ side using `base::UTF16ToUTF8` and back again.
|
||||
* If students decide to do the conversion on the Rust side, they'll need to
|
||||
consider [`String::from_utf16`][1], consider error handling, and
|
||||
consider which [cxx supported types can transfer a lot of u16s][2].
|
||||
consider which [CXX supported types can transfer a lot of u16s][2].
|
||||
* Students may design the C++/Rust boundary in several different ways,
|
||||
e.g. taking and returning strings by value, or taking a mutable reference
|
||||
to a string. If a mutable reference is used, cxx will likely
|
||||
to a string. If a mutable reference is used, CXX will likely
|
||||
tell the student that they need to use [`Pin`][3]. You may need to explain
|
||||
what `Pin` does, and then explain why `cxx` needs it for mutable references
|
||||
what `Pin` does, and then explain why CXX needs it for mutable references
|
||||
to C++ data: the answer is that C++ data can't be moved around like Rust
|
||||
data, because it may contain self-referential pointers.
|
||||
* The C++ target containing `ResourceBundle::MaybeMangleLocalizedString`
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
## Part two
|
||||
|
||||
It's a good idea to play with cxx a little. It helps you think about how flexible
|
||||
It's a good idea to play with CXX a little. It helps you think about how flexible
|
||||
Rust in Chromium actually is.
|
||||
|
||||
Some things to try:
|
||||
@ -40,18 +40,18 @@ Some things to try:
|
||||
|
||||
## Part three
|
||||
|
||||
Now you understand the strengths and limitations of cxx interop, think of
|
||||
Now you understand the strengths and limitations of CXX interop, think of
|
||||
a couple of use-cases for Rust in Chromium where the interface would be
|
||||
sufficiently simple. Sketch how you might define that interface.
|
||||
|
||||
## Where to find help
|
||||
|
||||
* The [cxx binding reference][1]
|
||||
* The [`cxx` binding reference][1]
|
||||
* The [`rust_static_library` gn template][2]
|
||||
|
||||
<details>
|
||||
As students explore Part Two, they're bound to have lots of questions about how
|
||||
to achieve these things, and also how cxx works behind the scenes.
|
||||
to achieve these things, and also how CXX works behind the scenes.
|
||||
|
||||
Some of the questions you may encounter:
|
||||
* I'm seeing a problem initializing a variable of type X with type Y, where
|
||||
@ -60,8 +60,8 @@ Some of the questions you may encounter:
|
||||
`cxx::bridge`.
|
||||
* I seem to be able to freely convert C++ references into Rust references.
|
||||
Doesn't that risk UB?
|
||||
For cxx's _opaque_ types, no, because they are zero-sized. For cxx trivial types
|
||||
yes, it's _possible_ to cause UB, although cxx's design makes it quite
|
||||
For CXX's _opaque_ types, no, because they are zero-sized. For CXX trivial types
|
||||
yes, it's _possible_ to cause UB, although CXX's design makes it quite
|
||||
difficult to craft such an example.
|
||||
</details>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user