it invokes Ninja, just like `fx build`. The clippy results are saved in json
files inside the build output directory before being printed.
#### Target paths
GN uses paths like the following to identify build targets:
```
//src/starnix/kernel:starnix_core
```
The initial `//` means the root of the checkout, and the remaining slashes are
directory names. The string after `:` is the _target name_ of a target defined
in the `BUILD.gn` file of that directory.
The target name can be omitted if it is the same as the directory name. In other
words, `//src/starnix/kernel` is the same as `//src/starnix/kernel:kernel`.
These target paths are used inside `BUILD.gn` files to reference dependencies,
and can also be used in `fx build`.
#### Modifying compiler flags
You can put custom compiler flags inside a GN `config` that is added to a
target. As a simple example:
```
config("everybody_loops") {
rustflags = [ "-Zeverybody-loops" ]
}
rustc_binary("example") {
crate_root = "src/bin.rs"
# ...existing keys here...
configs += [ ":everybody_loops" ]
}
```
This will add the flag `-Zeverybody-loops` to rustc when building the `example`
target. Note that you can also use [`public_configs`] for a config to be added
to every target that depends on that target.
If you want to add a flag to every Rust target in the build, you can add
rustflags to the [`//build/config:compiler`] config or to the OS-specific
configs referenced in that file. Note that `cflags` and `ldflags` are ignored on
Rust targets.
#### Running ninja and rustc commands directly
Going down one layer, `fx build` invokes `ninja`, which in turn eventually
invokes `rustc`. All build actions are run inside the out directory, which is
usually `out/default` inside the Fuchsia checkout.
You can get ninja to print the actual command it invokes by forcing that command
to fail, e.g. by adding a syntax error to one of the source files of the target.
Once you have the command, you can run it from inside the output directory.
After changing the toolchain itself, the build setting `rustc_version_string` in
`out/default/args.gn` needs to be changed so that `fx build` or `ninja` will
rebuild all the Rust targets. This can be done in a text editor and the contents
of the string do not matter, as long as it changes from one build to the next.
[build_fuchsia_from_rust_ci.sh] does this for you by hashing the toolchain
directory.
The Fuchsia website has more detailed documentation of the [build system].
#### Other tips and tricks
When using `build_fuchsia_from_rust_ci.sh` you can comment out the `fx set`
command after the initial run so it won't rerun GN each time. If you do this you
can also comment out the version_string line to save a couple seconds.
`export NINJA_PERSISTENT_MODE=1` to get faster ninja startup times after the
initial build.
## Fuchsia target support
To learn more about Fuchsia target support, see the Fuchsia chapter in [the
rustc book][platform-support].
code and a roughly equal amount of third-party code, as counted by tokei
(excluding comments and blanks).