mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-04-21 23:45:42 +02:00
Replace hyphens (-
) with em-dashes (—
) (#1500)
The new Chromium class likes — like me! — to use dashes in the writing! However, I believe it should use an em-dash instead of the hyphen. Luckily this is easy: we have enabled “typographic quotes” in `mdbook`, which also handles the conversion of `---` to `—` in the generated HTML. So I normalized the single existing em-dash to a triple-dash to make it more consistent (and hopefully make it easier for translators to consistently enter these characters).
This commit is contained in:
parent
d39740f91d
commit
aebb0bc856
@ -55,7 +55,7 @@ Tuples:
|
|||||||
* Fields of a tuple can be accessed by the period and the index of the value, e.g. `t.0`, `t.1`.
|
* Fields of a tuple can be accessed by the period and the index of the value, e.g. `t.0`, `t.1`.
|
||||||
|
|
||||||
* The empty tuple `()` is also known as the "unit type". It is both a type, and
|
* The empty tuple `()` is also known as the "unit type". It is both a type, and
|
||||||
the only valid value of that type - that is to say both the type and its value
|
the only valid value of that type --- that is to say both the type and its value
|
||||||
are expressed as `()`. It is used to indicate, for example, that a function or
|
are expressed as `()`. It is used to indicate, for example, that a function or
|
||||||
expression has no return value, as we'll see in a future slide.
|
expression has no return value, as we'll see in a future slide.
|
||||||
* You can think of it as `void` that can be familiar to you from other
|
* You can think of it as `void` that can be familiar to you from other
|
||||||
|
@ -5,7 +5,7 @@ easy* for Rust crates to depend upon one another. So they do!
|
|||||||
|
|
||||||
| Property | C++ library | Rust crate |
|
| Property | C++ library | Rust crate |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| Build system | Lots | Consistent - `Cargo.toml` |
|
| Build system | Lots | Consistent: `Cargo.toml` |
|
||||||
| Typical library size | Large-ish | Small |
|
| Typical library size | Large-ish | Small |
|
||||||
| Transitive dependencies | Few | Lots |
|
| Transitive dependencies | Few | Lots |
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ cxx = "1"
|
|||||||
```
|
```
|
||||||
|
|
||||||
As with any other `Cargo.toml`, you can specify [more details about
|
As with any other `Cargo.toml`, you can specify [more details about
|
||||||
the dependencies][1] - most commonly, you'll want to specify the `features` that
|
the dependencies][1] --- most commonly, you'll want to specify the `features` that
|
||||||
you wish to enable in the crate.
|
you wish to enable in the crate.
|
||||||
|
|
||||||
When adding a crate to Chromium, you'll often need to provide some extra
|
When adding a crate to Chromium, you'll often need to provide some extra
|
||||||
|
@ -17,9 +17,11 @@ The "major semver version" is a [Rust "semver" version number][0].
|
|||||||
Take a close look, especially at the things generated in `third_party/rust`.
|
Take a close look, especially at the things generated in `third_party/rust`.
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
Talk a little about semver - and specifically the way that in Chromium
|
|
||||||
|
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
|
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>
|
</detail>
|
||||||
|
|
||||||
[0]: https://doc.rust-lang.org/cargo/reference/semver.html
|
[0]: https://doc.rust-lang.org/cargo/reference/semver.html
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Some crates use the [`cc`][2] crate to build and link C/C++ libraries.
|
Some crates use the [`cc`][2] crate to build and link C/C++ libraries.
|
||||||
Other crates parse C/C++ using [`bindgen`][3] within their build scripts.
|
Other crates parse C/C++ using [`bindgen`][3] within their build scripts.
|
||||||
These actions can't be supported in a Chromium context - our gn, ninja
|
These actions can't be supported in a Chromium context --- our gn, ninja
|
||||||
and LLVM build system is very specific in expressing relationships between
|
and LLVM build system is very specific in expressing relationships between
|
||||||
build actions.
|
build actions.
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ So, your options are:
|
|||||||
|
|
||||||
Patches should be kept in `third_party/rust/chromium_crates_io/patches/<crate>` -
|
Patches should be kept in `third_party/rust/chromium_crates_io/patches/<crate>` -
|
||||||
see for example the [patches against the cxx crate][4]. There is currently
|
see for example the [patches against the cxx crate][4]. There is currently
|
||||||
no automation - [simply create and apply patches manually][5] to remove the
|
no automation --- [simply create and apply patches manually][5] to remove the
|
||||||
problematic actions from the build script.
|
problematic actions from the build script.
|
||||||
|
|
||||||
If your patches modify the `Cargo.toml` file, rerun `gnrt gen`.
|
If your patches modify the `Cargo.toml` file, rerun `gnrt gen`.
|
||||||
|
@ -24,7 +24,7 @@ Meanwhile, for each new crate addition, we are checking for the following:
|
|||||||
that might have been maliciously inserted. (You can't realistically aim
|
that might have been maliciously inserted. (You can't realistically aim
|
||||||
for 100% perfection here: there's often just too much code.)
|
for 100% perfection here: there's often just too much code.)
|
||||||
|
|
||||||
These are just guidelines - work with reviewers from `security@chromium.org`
|
These are just guidelines --- work with reviewers from `security@chromium.org`
|
||||||
to work out the right way to become confident of the crate.
|
to work out the right way to become confident of the crate.
|
||||||
|
|
||||||
[0]: https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/rust.md#Third_party-review
|
[0]: https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/rust.md#Third_party-review
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Build rules
|
# Build rules
|
||||||
|
|
||||||
Rust code is usually built using `cargo`. Chromium builds with `gn` and `ninja`
|
Rust code is usually built using `cargo`. Chromium builds with `gn` and `ninja`
|
||||||
for efficiency - its static rules allow maximum parallelism. Rust is no exception.
|
for efficiency --- its static rules allow maximum parallelism. Rust is no exception.
|
||||||
|
|
||||||
## Adding Rust code to Chromium
|
## Adding Rust code to Chromium
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ depend upon third party code.
|
|||||||
<details>
|
<details>
|
||||||
You must specify _both_ the crate root, _and_ a full list of sources.
|
You must specify _both_ the crate root, _and_ a full list of sources.
|
||||||
The `crate_root` is the file given to the Rust compiler representing the root
|
The `crate_root` is the file given to the Rust compiler representing the root
|
||||||
file of the compilation unit - typically `lib.rs`. `sources` is a complete
|
file of the compilation unit --- typically `lib.rs`. `sources` is a complete
|
||||||
list of all source files which `ninja` needs in order to determine when rebuilds
|
list of all source files which `ninja` needs in order to determine when rebuilds
|
||||||
are necessary.
|
are necessary.
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Including `unsafe` Rust code
|
# Including `unsafe` Rust code
|
||||||
|
|
||||||
Unsafe Rust code is forbidden in `rust_static_library` by default - it won't
|
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
|
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.)
|
gn target. (Later in the course we'll see circumstances where this is necessary.)
|
||||||
|
|
||||||
|
@ -35,8 +35,9 @@ Discuss in small groups the policies within your own team and organization,
|
|||||||
and come to a group agreement about what's an acceptable level of risk.
|
and come to a group agreement about what's an acceptable level of risk.
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
|
|
||||||
Explain that it might seem strange to write tools in Rust, but this is
|
Explain that it might seem strange to write tools in Rust, but this is
|
||||||
increasingly popular across the industry - Rust tools are quicker and work
|
increasingly popular across the industry --- Rust tools are quicker and work
|
||||||
more reliably.
|
more reliably.
|
||||||
|
|
||||||
Assuming folks taking the course are physically together, ask them to discuss
|
Assuming folks taking the course are physically together, ask them to discuss
|
||||||
@ -44,6 +45,7 @@ in small groups of 3-4 people. Then, ask each table whether they've come
|
|||||||
to a consensus on the level of risk.
|
to a consensus on the level of risk.
|
||||||
|
|
||||||
Later in the course, we'll be running an actual `cargo`-based tool, `gnrt`.
|
Later in the course, we'll be running an actual `cargo`-based tool, `gnrt`.
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
[0]: https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/rust.md#Using-cargo
|
[0]: https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/rust.md#Using-cargo
|
||||||
|
@ -17,9 +17,11 @@ See the [CXX tutorial][1] for a full example of using this.
|
|||||||
|
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
|
|
||||||
Talk through the diagram. Explain that behind the scenes, this is doing
|
Talk through the diagram. Explain that behind the scenes, this is doing
|
||||||
just the same as you previously did - but by programmatically ensuring that
|
just the same as you previously did --- but by programmatically ensuring that
|
||||||
the C++ and Rust sides match, cxx can ensure there aren't obvious errors
|
the C++ and Rust sides match, cxx can ensure there aren't obvious errors
|
||||||
with object lifetimes, string lengths, etc. It reduces lots of fiddly
|
with object lifetimes, string lengths, etc. It reduces lots of fiddly
|
||||||
boilerplate and the resulting code feels more "natural".
|
boilerplate and the resulting code feels more "natural".
|
||||||
|
|
||||||
</details>
|
</details>
|
@ -8,7 +8,7 @@ cxx fundamentally suits cases where:
|
|||||||
* 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.
|
`std::unique_ptr`, `std::string`, `&[u8]` etc.
|
||||||
|
|
||||||
It has many limitations - for example lack of support for Rust's `Option` type.
|
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
|
These limitations constrain us to using Rust in Chromium only for well isolated
|
||||||
"leaf nodes" rather than for arbitrary Rust-C++ interop. When considering
|
"leaf nodes" rather than for arbitrary Rust-C++ interop. When considering
|
||||||
|
@ -20,10 +20,11 @@ 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
|
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>
|
<details>
|
||||||
Students may ask - why do we still need `allow_unsafe = true`?
|
|
||||||
|
Students may ask --- why do we still need `allow_unsafe = true`?
|
||||||
|
|
||||||
The broad answer is that no C/C++ code is "safe" by the normal Rust standards.
|
The broad answer is that no C/C++ code is "safe" by the normal Rust standards.
|
||||||
Calling back and forth to C/C++ from Rust may do arbitrary things to memory, and
|
Calling back and forth to C/C++ from Rust may do arbitrary things to memory, and
|
||||||
@ -32,9 +33,10 @@ compromise the safety of Rust's own data layouts. Presence of _too many_
|
|||||||
such a keyword, and is [controversial][1], but strictly, bringing any foreign
|
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.
|
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
|
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.
|
we did manually in the previous section.
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
[0]: https://source.chromium.org/chromium/chromium/src/+/main:base/containers/span_rust.h;l=21
|
[0]: https://source.chromium.org/chromium/chromium/src/+/main:base/containers/span_rust.h;l=21
|
||||||
|
@ -14,7 +14,7 @@ out/Debug/chrome # or on Mac, out/Debug/Chromium.app/Contents/MacOS/Chromium
|
|||||||
is the default!)
|
is the default!)
|
||||||
|
|
||||||
See [How to build Chromium](https://www.chromium.org/developers/how-tos/get-the-code/)
|
See [How to build Chromium](https://www.chromium.org/developers/how-tos/get-the-code/)
|
||||||
if you aren't already at that point. Be warned - setting up to build Chromium
|
if you aren't already at that point. Be warned: setting up to build Chromium
|
||||||
takes time.
|
takes time.
|
||||||
|
|
||||||
It's also recommended that you have Visual Studio code installed.
|
It's also recommended that you have Visual Studio code installed.
|
||||||
|
@ -28,12 +28,12 @@ implementation.
|
|||||||
|
|
||||||
<details>
|
<details>
|
||||||
|
|
||||||
* `Mutex` in Rust looks like a collection with just one element - the protected data.
|
* `Mutex` in Rust looks like a collection with just one element --- the protected data.
|
||||||
* It is not possible to forget to acquire the mutex before accessing the protected data.
|
* It is not possible to forget to acquire the mutex before accessing the protected data.
|
||||||
* You can get an `&mut T` from an `&Mutex<T>` by taking the lock. The `MutexGuard` ensures that the
|
* You can get an `&mut T` from an `&Mutex<T>` by taking the lock. The `MutexGuard` ensures that the
|
||||||
`&mut T` doesn't outlive the lock being held.
|
`&mut T` doesn't outlive the lock being held.
|
||||||
* `Mutex<T>` implements both `Send` and `Sync` iff (if and only if) `T` implements `Send`.
|
* `Mutex<T>` implements both `Send` and `Sync` iff (if and only if) `T` implements `Send`.
|
||||||
* A read-write lock counterpart - `RwLock`.
|
* A read-write lock counterpart: `RwLock`.
|
||||||
* Why does `lock()` return a `Result`?
|
* Why does `lock()` return a `Result`?
|
||||||
* If the thread that held the `Mutex` panicked, the `Mutex` becomes "poisoned" to signal that
|
* If the thread that held the `Mutex` panicked, the `Mutex` becomes "poisoned" to signal that
|
||||||
the data it protected might be in an inconsistent state. Calling `lock()` on a poisoned mutex
|
the data it protected might be in an inconsistent state. Calling `lock()` on a poisoned mutex
|
||||||
|
@ -29,7 +29,7 @@ fn main() {
|
|||||||
|
|
||||||
Key points:
|
Key points:
|
||||||
|
|
||||||
* Notice that the thread is stopped before it reaches 10 — the main thread is
|
* Notice that the thread is stopped before it reaches 10 --- the main thread is
|
||||||
not waiting.
|
not waiting.
|
||||||
|
|
||||||
* Use `let handle = thread::spawn(...)` and later `handle.join()` to wait for
|
* Use `let handle = thread::spawn(...)` and later `handle.join()` to wait for
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Bringing it together - Exercise
|
# Bringing it together --- Exercise
|
||||||
|
|
||||||
In this exercise, you're going to add a whole new Chromium feature, bringing
|
In this exercise, you're going to add a whole new Chromium feature, bringing
|
||||||
together everything you already learned.
|
together everything you already learned.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Dining Philosophers - Async
|
# Dining Philosophers --- Async
|
||||||
|
|
||||||
See [dining philosophers](dining-philosophers.md) for a description of the
|
See [dining philosophers](dining-philosophers.md) for a description of the
|
||||||
problem.
|
problem.
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Concurrency Afternoon Exercise
|
# Concurrency Afternoon Exercise
|
||||||
|
|
||||||
## Dining Philosophers - Async
|
## Dining Philosophers --- Async
|
||||||
|
|
||||||
([back to exercise](dining-philosophers-async.md))
|
([back to exercise](dining-philosophers-async.md))
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ Rust as part of the Chromium browser. It includes using Rust in Chromium's
|
|||||||
`gn` build system, bringing in third-party libraries ("crates") and C++
|
`gn` build system, bringing in third-party libraries ("crates") and C++
|
||||||
interoperability.
|
interoperability.
|
||||||
|
|
||||||
You will need to be able to build Chromium - a debug, component build is
|
You will need to be able to build Chromium --- a debug, component build is
|
||||||
[recommended](../chromium/setup.md) for speed but any build will work.
|
[recommended](../chromium/setup.md) for speed but any build will work.
|
||||||
Ensure that you can run the Chromium browser that you've built.
|
Ensure that you can run the Chromium browser that you've built.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user