Skip to content

Commit

Permalink
Format all Markdown files with dprint
Browse files Browse the repository at this point in the history
This is the result of running `dprint fmt` after making two temporary
changes:

- removing `src/` from the list of excluded directories,
- removing the `rustfmt` configuration.

The effect of the first change is that we normalize the formatting of
all Markdown files. The effect of the second is that we avoid
reformatting code blocks in the Markdown files. I want to reformat the
Rust code in a follow-up step since some of the changes seem
unnecessary or undesirable.

Thanks to mdbook-i18n-helpers 0.2, the POT file is nearly unchanged
after this, meaning that all existing translations remain valid. A few
messages were changed because of stray whitespace characters:

     msgid ""
     "Slices always borrow from another object. In this example, `a` has to remain "
    -"'alive' (in scope) for at least as long as our slice. "
    +"'alive' (in scope) for at least as long as our slice."
     msgstr ""

I have not updated CI to require perfectly formatted files. I think
doing so might be annoying since it makes it much harder to submit
small fixes directly from the GitHub editor. So for now, I suggest
that we simply run `dprint` by hand every few weeks.

If dprint/check#11 is fixed so that `dprint` can annotate the lines
that need fixing directly, then I think we can consider more strict
formatting checks.
  • Loading branch information
mgeisler committed Dec 6, 2023
1 parent 857511a commit 1bcaf98
Show file tree
Hide file tree
Showing 259 changed files with 2,816 additions and 2,323 deletions.
29 changes: 12 additions & 17 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

<!-- Keep first page as index.md to avoid giving it two names. -->

[Welcome to Comprehensive Rust 🦀](index.md)

- [Running the Course](running-the-course.md)
- [Course Structure](running-the-course/course-structure.md)
- [Keyboard Shortcuts](running-the-course/keyboard-shortcuts.md)
Expand All @@ -10,8 +11,7 @@
- [Code Samples](cargo/code-samples.md)
- [Running Cargo Locally](cargo/running-locally.md)


----
---

# Day 1: Morning

Expand Down Expand Up @@ -63,7 +63,7 @@
- [Exercise: Elevator Events](user-defined-types/exercise.md)
- [Solution](user-defined-types/solution.md)

----
---

# Day 2: Morning

Expand Down Expand Up @@ -112,7 +112,7 @@
- [Exercise: ROT13](std-traits/exercise.md)
- [Solution](std-traits/solution.md)

----
---

# Day 3: Morning

Expand Down Expand Up @@ -202,7 +202,7 @@

# Android

----
---

- [Welcome](android.md)
- [Setup](android/setup.md)
Expand Down Expand Up @@ -237,11 +237,9 @@
- [With Java](android/interoperability/java.md)
- [Exercises](exercises/android/morning.md)



# Chromium

----
---

- [Welcome](chromium.md)
- [Setup](chromium/setup.md)
Expand All @@ -260,8 +258,8 @@
- [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)
- [Error handling: QR example](chromium/interoperability-with-cpp/error-handling-qr.md)
- [Error handling: PNG example](chromium/interoperability-with-cpp/error-handling-png.md)
- [Error handling: QR example](chromium/interoperability-with-cpp/error-handling-qr.md)
- [Error handling: PNG example](chromium/interoperability-with-cpp/error-handling-png.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)
Expand All @@ -279,10 +277,9 @@
- [Exercise](exercises/chromium/third-party.md)
- [Bringing it together - Exercise](exercises/chromium/bringing-it-together.md)


# Bare Metal: Morning

----
---

- [Welcome](bare-metal.md)
- [`no_std`](bare-metal/no_std.md)
Expand Down Expand Up @@ -331,10 +328,9 @@
- [RTC Driver](exercises/bare-metal/rtc.md)
- [Solutions](exercises/bare-metal/solutions-afternoon.md)


# Concurrency: Morning

----
---

- [Welcome](concurrency.md)
- [Threads](concurrency/threads.md)
Expand Down Expand Up @@ -377,10 +373,9 @@
- [Broadcast Chat Application](exercises/concurrency/chat-app.md)
- [Solutions](exercises/concurrency/solutions-afternoon.md)


# Final Words

----
---

- [Thanks!](thanks.md)
- [Glossary](glossary.md)
Expand Down
23 changes: 14 additions & 9 deletions src/android.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
course: Android
session: Android
---

# Welcome to Rust in Android

Rust is supported for system software on Android. This means that
you can write new services, libraries, drivers or even firmware in Rust
(or improve existing code as needed).
Rust is supported for system software on Android. This means that you can write
new services, libraries, drivers or even firmware in Rust (or improve existing
code as needed).

> We will attempt to call Rust from one of your own projects today. So try to
> find a little corner of your code base where we can move some lines of code to
Expand All @@ -15,15 +16,19 @@ you can write new services, libraries, drivers or even firmware in Rust
<details>

The speaker may mention any of the following given the increased use of Rust
in Android:
The speaker may mention any of the following given the increased use of Rust in
Android:

- Service example: [DNS over HTTP](https://security.googleblog.com/2022/07/dns-over-http3-in-android.html)
- Service example:
[DNS over HTTP](https://security.googleblog.com/2022/07/dns-over-http3-in-android.html)

- Libraries: [Rutabaga Virtual Graphics Interface](https://crosvm.dev/book/appendix/rutabaga_gfx.html)
- Libraries:
[Rutabaga Virtual Graphics Interface](https://crosvm.dev/book/appendix/rutabaga_gfx.html)

- Kernel Drivers: [Binder](https://lore.kernel.org/rust-for-linux/[email protected]/)
- Kernel Drivers:
[Binder](https://lore.kernel.org/rust-for-linux/[email protected]/)

- Firmware: [pKVM firmware](https://security.googleblog.com/2023/10/bare-metal-rust-in-android.html)
- Firmware:
[pKVM firmware](https://security.googleblog.com/2023/10/bare-metal-rust-in-android.html)

</details>
10 changes: 6 additions & 4 deletions src/android/aidl.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# AIDL

The [Android Interface Definition Language
(AIDL)](https://developer.android.com/guide/components/aidl) is supported in Rust:
The
[Android Interface Definition Language
(AIDL)](https://developer.android.com/guide/components/aidl) is supported in
Rust:

* Rust code can call existing AIDL servers,
* You can create new AIDL servers in Rust.
- Rust code can call existing AIDL servers,
- You can create new AIDL servers in Rust.
4 changes: 2 additions & 2 deletions src/android/aidl/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

Finally, we can create a Rust client for our new service.

*birthday_service/src/client.rs*:
_birthday_service/src/client.rs_:

```rust,ignore
{{#include birthday_service/src/client.rs:main}}
```

*birthday_service/Android.bp*:
_birthday_service/Android.bp_:

```javascript
{{#include birthday_service/Android.bp:birthday_client}}
Expand Down
4 changes: 2 additions & 2 deletions src/android/aidl/implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

We can now implement the AIDL service:

*birthday_service/src/lib.rs*:
_birthday_service/src/lib.rs_:

```rust,ignore
{{#include birthday_service/src/lib.rs:IBirthdayService}}
```

*birthday_service/Android.bp*:
_birthday_service/Android.bp_:

```javascript
{{#include birthday_service/Android.bp:libbirthdayservice}}
Expand Down
4 changes: 2 additions & 2 deletions src/android/aidl/interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

You declare the API of your service using an AIDL interface:

*birthday_service/aidl/com/example/birthdayservice/IBirthdayService.aidl*:
_birthday_service/aidl/com/example/birthdayservice/IBirthdayService.aidl_:

```java
{{#include birthday_service/aidl/com/example/birthdayservice/IBirthdayService.aidl:IBirthdayService}}
```

*birthday_service/aidl/Android.bp*:
_birthday_service/aidl/Android.bp_:

```javascript
{{#include birthday_service/aidl/Android.bp}}
Expand Down
4 changes: 2 additions & 2 deletions src/android/aidl/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

Finally, we can create a server which exposes the service:

*birthday_service/src/server.rs*:
_birthday_service/src/server.rs_:

```rust,ignore
{{#include birthday_service/src/server.rs:main}}
```

*birthday_service/Android.bp*:
_birthday_service/Android.bp_:

```javascript
{{#include birthday_service/Android.bp:birthday_server}}
Expand Down
15 changes: 11 additions & 4 deletions src/android/build-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@ 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.
- For compliance and performance, Android must have crates in-tree. It must also
interop with C/C++/Java code. Soong fills that gap.

- Soong has many similarities to Bazel, which is the open-source variant of Blaze (used in google3).
- Soong has many similarities to Bazel, which is the open-source variant of
Blaze (used in google3).

- There is a plan to transition [Android](https://source.android.com/docs/setup/build/bazel/introduction), [ChromeOS](https://chromium.googlesource.com/chromiumos/bazel/), and [Fuchsia](https://source.android.com/docs/setup/build/bazel/introduction) to Bazel.
- There is a plan to transition
[Android](https://source.android.com/docs/setup/build/bazel/introduction),
[ChromeOS](https://chromium.googlesource.com/chromiumos/bazel/), and
[Fuchsia](https://source.android.com/docs/setup/build/bazel/introduction) to
Bazel.

- Learning Bazel-like build rules is useful for all Rust OS developers.

Expand Down
4 changes: 2 additions & 2 deletions src/android/build-rules/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ You use `rust_library` to create a new Rust library for Android.

Here we declare a dependency on two libraries:

* `libgreeting`, which we define below,
* `libtextwrap`, which is a crate already vendored in
- `libgreeting`, which we define below,
- `libtextwrap`, which is a crate already vendored in
[`external/rust/crates/`][crates].

[crates]: https://cs.android.com/android/platform/superproject/+/master:external/rust/crates/
Expand Down
4 changes: 2 additions & 2 deletions src/android/interoperability.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Rust has excellent support for interoperability with other languages. This means
that you can:

* Call Rust functions from other languages.
* Call functions written in other languages from Rust.
- Call Rust functions from other languages.
- Call functions written in other languages from Rust.

When you call functions in a foreign language we say that you're using a
_foreign function interface_, also known as FFI.
6 changes: 3 additions & 3 deletions src/android/interoperability/cpp/android-build-cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ cc_library_static {

<details>

* Point out that `libcxx_test_bridge_header` and `libcxx_test_bridge_code` are
- Point out that `libcxx_test_bridge_header` and `libcxx_test_bridge_code` are
the dependencies for the CXX-generated C++ bindings. We'll show how these are
setup on the next slide.
* Note that you also need to depend on the `cxx-bridge-header` library in order
- Note that you also need to depend on the `cxx-bridge-header` library in order
to pull in common CXX definitions.
* Full docs for using CXX in Android can be found in [the Android docs]. You may
- Full docs for using CXX in Android can be found in [the Android docs]. You may
want to share that link with the class so that students know where they can
find these instructions again in the future.

Expand Down
4 changes: 2 additions & 2 deletions src/android/interoperability/cpp/android-cpp-genrules.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ genrule {

<details>

* The `cxxbridge` tool is a standalone tool that generates the C++ side of the
- The `cxxbridge` tool is a standalone tool that generates the C++ side of the
bridge module. It is included in Android and available as a Soong tool.
* By convention, if your Rust source file is `lib.rs` your header file will be
- By convention, if your Rust source file is `lib.rs` your header file will be
named `lib.rs.h` and your source file will be named `lib.rs.cc`. This naming
convention isn't enforced, though.

Expand Down
8 changes: 4 additions & 4 deletions src/android/interoperability/cpp/bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ a Rust module annotated with the `#[cxx::bridge]` attribute macro.

<details>

* The bridge is generally declared in an `ffi` module within your crate.
* From the declarations made in the bridge module, CXX will generate matching
- The bridge is generally declared in an `ffi` module within your crate.
- From the declarations made in the bridge module, CXX will generate matching
Rust and C++ type/function definitions in order to expose those items to both
languages.
* To view the generated Rust code, use [cargo-expand] to view the expanded proc
- To view the generated Rust code, use [cargo-expand] to view the expanded proc
macro. For most of the examples you would use `cargo expand ::ffi` to expand
just the `ffi` module (though this doesn't apply for Android projects).
* To view the generated C++ code, look in `target/cxxbridge`.
- To view the generated C++ code, look in `target/cxxbridge`.

[cargo-expand]: https://github.com/dtolnay/cargo-expand

Expand Down
4 changes: 2 additions & 2 deletions src/android/interoperability/cpp/cpp-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ impl BlobstoreClient {

<details>

* The programmer does not need to promise that the signatures they have typed in
- The programmer does not need to promise that the signatures they have typed in
are accurate. CXX performs static assertions that the signatures exactly
correspond with what is declared in C++.
* `unsafe extern` blocks allow you to declare C++ functions that are safe to
- `unsafe extern` blocks allow you to declare C++ functions that are safe to
call from Rust.

</details>
4 changes: 2 additions & 2 deletions src/android/interoperability/cpp/cpp-exception.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

<details>

* C++ functions declared to return a `Result` will catch any thrown exception on
- C++ functions declared to return a `Result` will catch any thrown exception on
the C++ side and return it as an `Err` value to the calling Rust function.
* If an exception is thrown from an extern "C++" function that is not declared
- If an exception is thrown from an extern "C++" function that is not declared
by the CXX bridge to return `Result`, the program calls C++'s
`std::terminate`. The behavior is equivalent to the same exception being
thrown through a `noexcept` C++ function.
Expand Down
4 changes: 2 additions & 2 deletions src/android/interoperability/cpp/rust-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

<details>

* Items declared in the `extern "Rust"` reference items that are in scope in the
- Items declared in the `extern "Rust"` reference items that are in scope in the
parent module.
* The CXX code generator uses your `extern "Rust"` section(s) to produce a C++
- The CXX code generator uses your `extern "Rust"` section(s) to produce a C++
header file containing the corresponding C++ declarations. The generated
header has the same path as the Rust source file containing the bridge, except
with a .rs.h file extension.
Expand Down
6 changes: 3 additions & 3 deletions src/android/interoperability/cpp/rust-result.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

<details>

* Rust functions that return `Result` are translated to exceptions on the C++
- Rust functions that return `Result` are translated to exceptions on the C++
side.
* The exception thrown will always be of type `rust::Error`, which primarily
- The exception thrown will always be of type `rust::Error`, which primarily
exposes a way to get the error message string. The error message will come
from the error type's `Display` impl.
* A panic unwinding from Rust to C++ will always cause the process to
- A panic unwinding from Rust to C++ will always cause the process to
immediately terminate.

</details>
2 changes: 1 addition & 1 deletion src/android/interoperability/cpp/shared-enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Generated C++:
<details>
* On the Rust side, the code generated for shared enums is actually a struct
- On the Rust side, the code generated for shared enums is actually a struct
wrapping a numeric value. This is because it is not UB in C++ for an enum
class to hold a value different from all of the listed variants, and our Rust
representation needs to have the same behavior.
Expand Down
4 changes: 2 additions & 2 deletions src/android/interoperability/cpp/shared-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<details>

* Only C-like (unit) enums are supported.
* A limited number of traits are supported for `#[derive()]` on shared types.
- Only C-like (unit) enums are supported.
- A limited number of traits are supported for `#[derive()]` on shared types.
Corresponding functionality is also generated for the C++ code, e.g. if you
derive `Hash` also generates an implementation of `std::hash` for the
corresponding C++ type.
Expand Down
Loading

0 comments on commit 1bcaf98

Please sign in to comment.