Skip to content

Commit 8bcb473

Browse files
authored
Rollup merge of #104465 - djkoloski:improve_fuchsia_testing_docs, r=tmandry
Document more settings for building rustc for Fuchsia This documents that you need to link for Fuchsia with `lld` and provides configuration settings for both `clang` and `lld`. It also adjusts the documentation for running the test suite to recommend installing to a prefix. r? ``@tmandry``
2 parents 60b8fc4 + 9ed2977 commit 8bcb473

File tree

2 files changed

+60
-23
lines changed

2 files changed

+60
-23
lines changed

src/ci/docker/scripts/fuchsia-test-runner.py

100644100755
File mode changed.

src/doc/rustc/src/platform-support/fuchsia.md

+60-23
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,45 @@ Fuchsia as well. A recent version (14+) of clang should be sufficient to compile
189189
Rust for Fuchsia.
190190

191191
x86-64 and AArch64 Fuchsia targets can be enabled using the following
192-
configuration.
193-
194-
In `config.toml`, add:
192+
configuration in `config.toml`:
195193

196194
```toml
197195
[build]
198196
target = ["<host_platform>", "aarch64-fuchsia", "x86_64-fuchsia"]
197+
198+
[rust]
199+
lld = true
200+
201+
[target.x86_64-fuchsia]
202+
cc = "clang"
203+
cxx = "clang++"
204+
205+
[target.aarch64-fuchsia]
206+
cc = "clang"
207+
cxx = "clang++"
208+
```
209+
210+
Though not strictly required, you may also want to use `clang` for your host
211+
target as well:
212+
213+
```toml
214+
[target.<host_platform>]
215+
cc = "clang"
216+
cxx = "clang++"
217+
```
218+
219+
By default, the Rust compiler installs itself to `/usr/local` on most UNIX
220+
systems. You may want to install it to another location (e.g. a local `install`
221+
directory) by setting a custom prefix in `config.toml`:
222+
223+
```toml
224+
[install]
225+
# Make sure to use the absolute path to your install directory
226+
prefix = "<RUST_SRC_PATH>/install"
199227
```
200228

201-
Additionally, the following environment variables must be configured (for
202-
example, using a script like `config-env.sh`):
229+
Next, the following environment variables must be configured. For example, using
230+
a script we name `config-env.sh`:
203231

204232
```sh
205233
# Configure this environment variable to be the path to the downloaded SDK
@@ -215,8 +243,11 @@ export LDFLAGS_x86_64_fuchsia="--target=x86_64-fuchsia --sysroot=${SDK_PATH}/arc
215243
export CARGO_TARGET_X86_64_FUCHSIA_RUSTFLAGS="-C link-arg=--sysroot=${SDK_PATH}/arch/x64/sysroot -Lnative=${SDK_PATH}/arch/x64/sysroot/lib -Lnative=${SDK_PATH}/arch/x64/lib"
216244
```
217245

218-
These can be run together in a shell environment by executing
219-
`(source config-env.sh && ./x.py install)`.
246+
Finally, the Rust compiler can be built and installed:
247+
248+
```sh
249+
(source config-env.sh && ./x.py install)
250+
```
220251

221252
Once `rustc` is installed, we can create a new working directory to work from,
222253
`hello_fuchsia` along with `hello_fuchsia/src`:
@@ -641,31 +672,38 @@ available on the [Fuchsia devsite].
641672

642673
### Running the compiler test suite
643674

644-
Pre-requisites for running the Rust test suite on Fuchsia are:
645-
1. Checkout of Rust source.
646-
1. Setup of `config-env.sh` and `config.toml` from "[Targeting Fuchsia with a compiler built from source](#targeting-fuchsia-with-a-compiler-built-from-source)".
647-
1. Download of the Fuchsia SDK. Minimum supported SDK version is [9.20220726.1.1](https://chrome-infra-packages.appspot.com/p/fuchsia/sdk/core/linux-amd64/+/version:9.20220726.1.1)
675+
The commands in this section assume that they are being run from inside your
676+
local Rust source checkout:
677+
678+
```sh
679+
cd ${RUST_SRC_PATH}
680+
```
681+
682+
To run the Rust test suite on an emulated Fuchsia device, you must install the
683+
Rust compiler locally. See "[Targeting Fuchsia with a compiler built from source](#targeting-fuchsia-with-a-compiler-built-from-source)"
684+
for the steps to build locally.
648685

649-
Interfacing with the Fuchsia emulator is handled by our test runner script located
650-
at `${RUST_SRC_PATH}/src/ci/docker/scripts/fuchsia-test-runner.py`.
686+
You'll also need to download a copy of the Fuchsia SDK. The current minimum
687+
supported SDK version is [9.20220726.1.1](https://chrome-infra-packages.appspot.com/p/fuchsia/sdk/core/linux-amd64/+/version:9.20220726.1.1).
651688

652-
We start by activating our Fuchsia test environment. From a terminal:
689+
Fuchsia's test runner interacts with the Fuchsia emulator and is located at
690+
`src/ci/docker/scripts/fuchsia-test-runner.py`. We can use it to start our
691+
test environment with:
653692

654-
**Issue command from ${RUST_SRC_PATH}**
655693
```sh
656694
src/ci/docker/scripts/fuchsia-test-runner.py start
657-
--rust .
695+
--rust ${RUST_SRC_PATH}/install
658696
--sdk ${SDK_PATH}
659697
--target-arch {x64,arm64}
660698
```
661699

662-
Next, for ease of commands, we copy `config-env.sh` and `config.toml` into our Rust source
663-
code path, `${RUST_SRC_PATH}`.
700+
Where `${RUST_SRC_PATH}/install` is the `prefix` set in `config.toml` and
701+
`${SDK_PATH}` is the path to the downloaded and unzipped SDK.
664702

665-
From there, we utilize `x.py` to run our tests, using the test runner script to
666-
run the tests on our emulator. To run the full `src/test/ui` test suite:
703+
Once our environment is started, we can run our tests using `x.py` as usual. The
704+
test runner script will run the compiled tests on an emulated Fuchsia device. To
705+
run the full `src/test/ui` test suite:
667706

668-
**Run from ${RUST_SRC_PATH}**
669707
```sh
670708
( \
671709
source config-env.sh && \
@@ -695,9 +733,8 @@ run the tests on our emulator. To run the full `src/test/ui` test suite:
695733
*Note: The test suite cannot be run in parallel at the moment, so `x.py`
696734
must be run with `--jobs 1` to ensure only one test runs at a time.*
697735

698-
When finished, stop the test environment:
736+
When finished, the test runner can be used to stop the test environment:
699737

700-
**Issue command from ${RUST_SRC_PATH}**
701738
```sh
702739
src/ci/docker/scripts/fuchsia-test-runner.py stop
703740
```

0 commit comments

Comments
 (0)