1 # `aarch64-unknown-fuchsia` and `x86_64-unknown-fuchsia`
5 [Fuchsia] is a modern open source operating system that's simple, secure,
6 updatable, and performant.
12 - Tyler Mandry ([@tmandry](https://github.com/tmandry))
13 - David Koloski ([@djkoloski](https://github.com/djkoloski))
14 - Julia Ryan ([@P1n3appl3](https://github.com/P1n3appl3))
15 - Erick Tryzelaar ([@erickt](https://github.com/erickt))
17 As the team evolves over time, the specific members listed here may differ from
18 the members reported by the API. The API should be considered to be
19 authoritative if this occurs. Instead of pinging individual members, use
20 `@rustbot ping fuchsia` to contact the team on GitHub.
24 1. [Requirements](#requirements)
25 1. [Walkthrough structure](#walkthrough-structure)
26 1. [Compiling a Rust binary targeting Fuchsia](#compiling-a-rust-binary-targeting-fuchsia)
27 1. [Targeting Fuchsia with rustup and cargo](#targeting-fuchsia-with-rustup-and-cargo)
28 1. [Targeting Fuchsia with a compiler built from source](#targeting-fuchsia-with-a-compiler-built-from-source)
29 1. [Creating a Fuchsia package](#creating-a-fuchsia-package)
30 1. [Creating a Fuchsia component](#creating-a-fuchsia-component)
31 1. [Building a Fuchsia package](#building-a-fuchsia-package)
32 1. [Publishing a Fuchsia package](#publishing-a-fuchsia-package)
33 1. [Creating a Fuchsia package repository](#creating-a-fuchsia-package-repository)
34 1. [Publishing Fuchsia package to repository](#publishing-fuchsia-package-to-repository)
35 1. [Running a Fuchsia component on an emulator](#running-a-fuchsia-component-on-an-emulator)
36 1. [Starting the Fuchsia emulator](#starting-the-fuchsia-emulator)
37 1. [Watching emulator logs](#watching-emulator-logs)
38 1. [Serving a Fuchsia package](#serving-a-fuchsia-package)
39 1. [Running a Fuchsia component](#running-a-fuchsia-component)
40 1. [`.gitignore` extensions](#gitignore-extensions)
41 1. [Testing](#testing)
42 1. [Running unit tests](#running-unit-tests)
43 1. [Running the compiler test suite](#running-the-compiler-test-suite)
44 1. [Debugging](#debugging)
46 1. [Attaching `zxdb`](#attaching-zxdb)
47 1. [Using `zxdb`](#using-zxdb)
48 1. [Displaying source code in `zxdb`](#displaying-source-code-in-zxdb)
52 This target is cross-compiled from a host environment. You will need a recent
53 copy of the [Fuchsia SDK], which provides the tools, libraries, and binaries
54 required to build and link programs for Fuchsia.
56 Development may also be done from the [source tree].
58 Fuchsia targets support `std` and follow the `sysv64` calling convention on
59 x86_64. Fuchsia binaries use the ELF file format.
61 ## Walkthrough structure
63 This walkthrough will cover:
65 1. Compiling a Rust binary targeting Fuchsia.
66 1. Building a Fuchsia package.
67 1. Publishing and running a Fuchsia package to a Fuchsia emulator.
69 For the purposes of this walkthrough, we will only target `x86_64-unknown-fuchsia`.
71 ## Compiling a Rust binary targeting Fuchsia
73 Today, there are two main ways to build a Rust binary targeting Fuchsia
74 using the Fuchsia SDK:
75 1. Allow [rustup] to handle the installation of Fuchsia targets for you.
76 1. Build a toolchain locally that can target Fuchsia.
78 ### Targeting Fuchsia with rustup and cargo
80 The easiest way to build a Rust binary targeting Fuchsia is by allowing [rustup]
81 to handle the installation of Fuchsia targets for you. This can be done by issuing
82 the following commands:
85 rustup target add x86_64-unknown-fuchsia
86 rustup target add aarch64-unknown-fuchsia
89 After installing our Fuchsia targets, we can now compile a Rust binary that targets
92 To create our Rust project, we can use [`cargo`][cargo] as follows:
94 **From base working directory**
96 cargo new hello_fuchsia
99 The rest of this walkthrough will take place from `hello_fuchsia`, so we can
100 change into that directory now:
106 *Note: From this point onwards, all commands will be issued from the `hello_fuchsia/`
107 directory, and all `hello_fuchsia/` prefixes will be removed from references for sake of brevity.*
109 We can edit our `src/main.rs` to include a test as follows:
114 println!("Hello Fuchsia!");
119 assert_eq!(2 + 2, 4);
123 In addition to the standard workspace created, we will want to create a
124 `.cargo/config.toml` file to link necessary libraries
127 **`.cargo/config.toml`**
129 [target.x86_64-unknown-fuchsia]
132 "-Lnative=<SDK_PATH>/arch/x64/lib",
133 "-Lnative=<SDK_PATH>/arch/x64/sysroot/lib"
137 *Note: Make sure to fill out `<SDK_PATH>` with the path to the downloaded [Fuchsia SDK].*
139 These options configure the following:
141 * `-Lnative=${SDK_PATH}/arch/${ARCH}/lib`: Link against Fuchsia libraries from
143 * `-Lnative=${SDK_PATH}/arch/${ARCH}/sysroot/lib`: Link against Fuchsia sysroot
144 libraries from the SDK
146 In total, our new project will look like:
148 **Current directory structure**
158 Finally, we can build our rust binary as:
161 cargo build --target x86_64-unknown-fuchsia
164 Now we have a Rust binary at `target/x86_64-unknown-fuchsia/debug/hello_fuchsia`,
165 targeting our desired Fuchsia target.
167 **Current directory structure**
173 ┃ ┗━ x86_64-unknown-fuchsia/
181 ### Targeting Fuchsia with a compiler built from source
183 An alternative to the first workflow is to target Fuchsia by using
184 `rustc` built from source.
186 Before building Rust for Fuchsia, you'll need a clang toolchain that supports
187 Fuchsia as well. A recent version (14+) of clang should be sufficient to compile
190 x86-64 and AArch64 Fuchsia targets can be enabled using the following
191 configuration in `config.toml`:
195 target = ["<host_platform>", "aarch64-unknown-fuchsia", "x86_64-unknown-fuchsia"]
201 download-ci-llvm = false
203 [target.x86_64-unknown-fuchsia]
207 [target.aarch64-unknown-fuchsia]
212 Though not strictly required, you may also want to use `clang` for your host
216 [target.<host_platform>]
221 By default, the Rust compiler installs itself to `/usr/local` on most UNIX
222 systems. You may want to install it to another location (e.g. a local `install`
223 directory) by setting a custom prefix in `config.toml`:
227 # Make sure to use the absolute path to your install directory
228 prefix = "<RUST_SRC_PATH>/install"
231 Next, the following environment variables must be configured. For example, using
232 a script we name `config-env.sh`:
235 # Configure this environment variable to be the path to the downloaded SDK
236 export SDK_PATH="<SDK path goes here>"
238 export CFLAGS_aarch64_unknown_fuchsia="--target=aarch64-unknown-fuchsia --sysroot=${SDK_PATH}/arch/arm64/sysroot -I${SDK_PATH}/pkg/fdio/include"
239 export CXXFLAGS_aarch64_unknown_fuchsia="--target=aarch64-unknown-fuchsia --sysroot=${SDK_PATH}/arch/arm64/sysroot -I${SDK_PATH}/pkg/fdio/include"
240 export LDFLAGS_aarch64_unknown_fuchsia="--target=aarch64-unknown-fuchsia --sysroot=${SDK_PATH}/arch/arm64/sysroot -L${SDK_PATH}/arch/arm64/lib"
241 export CARGO_TARGET_AARCH64_UNKNOWN_FUCHSIA_RUSTFLAGS="-C link-arg=--sysroot=${SDK_PATH}/arch/arm64/sysroot -Lnative=${SDK_PATH}/arch/arm64/sysroot/lib -Lnative=${SDK_PATH}/arch/arm64/lib"
242 export CFLAGS_x86_64_unknown_fuchsia="--target=x86_64-unknown-fuchsia --sysroot=${SDK_PATH}/arch/x64/sysroot -I${SDK_PATH}/pkg/fdio/include"
243 export CXXFLAGS_x86_64_unknown_fuchsia="--target=x86_64-unknown-fuchsia --sysroot=${SDK_PATH}/arch/x64/sysroot -I${SDK_PATH}/pkg/fdio/include"
244 export LDFLAGS_x86_64_unknown_fuchsia="--target=x86_64-unknown-fuchsia --sysroot=${SDK_PATH}/arch/x64/sysroot -L${SDK_PATH}/arch/x64/lib"
245 export CARGO_TARGET_X86_64_UNKNOWN_FUCHSIA_RUSTFLAGS="-C link-arg=--sysroot=${SDK_PATH}/arch/x64/sysroot -Lnative=${SDK_PATH}/arch/x64/sysroot/lib -Lnative=${SDK_PATH}/arch/x64/lib"
248 Finally, the Rust compiler can be built and installed:
251 (source config-env.sh && ./x.py install)
254 Once `rustc` is installed, we can create a new working directory to work from,
255 `hello_fuchsia` along with `hello_fuchsia/src`:
263 *Note: From this point onwards, all commands will be issued from the `hello_fuchsia/`
264 directory, and all `hello_fuchsia/` prefixes will be removed from references for sake of brevity.*
266 There, we can create a new file named `src/hello_fuchsia.rs`:
268 **`src/hello_fuchsia.rs`**
271 println!("Hello Fuchsia!");
276 assert_eq!(2 + 2, 4);
280 **Current directory structure**
287 Using your freshly installed `rustc`, you can compile a binary for Fuchsia using
288 the following options:
290 * `--target x86_64-unknown-fuchsia`/`--target aarch64-unknown-fuchsia`: Targets the Fuchsia
291 platform of your choice
292 * `-Lnative ${SDK_PATH}/arch/${ARCH}/lib`: Link against Fuchsia libraries from
294 * `-Lnative ${SDK_PATH}/arch/${ARCH}/sysroot/lib`: Link against Fuchsia sysroot
295 libraries from the SDK
297 Putting it all together:
300 # Configure these for the Fuchsia target of your choice
301 TARGET_ARCH="<x86_64-unknown-fuchsia|aarch64-unknown-fuchsia>"
305 --target ${TARGET_ARCH} \
306 -Lnative=${SDK_PATH}/arch/${ARCH}/lib \
307 -Lnative=${SDK_PATH}/arch/${ARCH}/sysroot/lib \
308 --out-dir bin src/hello_fuchsia.rs
311 **Current directory structure**
315 ┃ ┗━ hello_fuchsia.rs
320 ## Creating a Fuchsia package
322 Before moving on, double check your directory structure:
324 **Current directory structure**
327 ┣━ src/ (if using rustc)
328 ┃ ┗━ hello_fuchsia.rs ...
330 ┃ ┗━ hello_fuchsia ...
331 ┣━ src/ (if using cargo)
334 ┗━ x86_64-unknown-fuchsia/ ...
339 With our Rust binary built, we can move to creating a Fuchsia package.
340 On Fuchsia, a package is the unit of distribution for software. We'll need to
341 create a new package directory where we will place files like our finished
342 binary and any data it may need.
344 To start, make the `pkg`, and `pkg/meta` directories:
351 **Current directory structure**
358 Now, create the following files inside:
360 **`pkg/meta/package`**
363 "name": "hello_fuchsia",
368 The `package` file describes our package's name and version number. Every
369 package must contain one.
371 **`pkg/hello_fuchsia.manifest` if using cargo**
373 bin/hello_fuchsia=target/x86_64-unknown-fuchsia/debug/hello_fuchsia
374 lib/ld.so.1=<SDK_PATH>/arch/x64/sysroot/dist/lib/ld.so.1
375 lib/libfdio.so=<SDK_PATH>/arch/x64/dist/libfdio.so
376 meta/package=pkg/meta/package
377 meta/hello_fuchsia.cm=pkg/meta/hello_fuchsia.cm
380 **`pkg/hello_fuchsia.manifest` if using rustc**
382 bin/hello_fuchsia=bin/hello_fuchsia
383 lib/ld.so.1=<SDK_PATH>/arch/x64/sysroot/dist/lib/ld.so.1
384 lib/libfdio.so=<SDK_PATH>/arch/x64/dist/libfdio.so
385 meta/package=pkg/meta/package
386 meta/hello_fuchsia.cm=pkg/meta/hello_fuchsia.cm
389 *Note: Relative manifest paths are resolved starting from the working directory
390 of `ffx`. Make sure to fill out `<SDK_PATH>` with the path to the downloaded
393 The `.manifest` file will be used to describe the contents of the package by
394 relating their location when installed to their location on the file system. The
395 `bin/hello_fuchsia=` entry will be different depending on how your Rust binary
396 was built, so choose accordingly.
398 **Current directory structure**
404 ┗━ hello_fuchsia.manifest
407 ### Creating a Fuchsia component
409 On Fuchsia, components require a component manifest written in Fuchsia's markup
410 language called CML. The Fuchsia devsite contains an [overview of CML] and a
411 [reference for the file format]. Here's a basic one that can run our single binary:
413 **`pkg/hello_fuchsia.cml`**
416 include: [ "syslog/client.shard.cml" ],
419 binary: "bin/hello_fuchsia",
424 **Current directory structure**
430 ┣━ hello_fuchsia.manifest
434 Now we can compile that CML into a component manifest:
437 ${SDK_PATH}/tools/${ARCH}/cmc compile \
438 pkg/hello_fuchsia.cml \
439 --includepath ${SDK_PATH}/pkg \
440 -o pkg/meta/hello_fuchsia.cm
443 *Note: `--includepath` tells the compiler where to look for `include`s from our CML.
444 In our case, we're only using `syslog/client.shard.cml`.*
446 **Current directory structure**
452 ┃ ┗━ hello_fuchsia.cm
453 ┣━ hello_fuchsia.manifest
457 ### Building a Fuchsia package
459 Next, we'll build a package manifest as defined by our manifest:
462 ${SDK_PATH}/tools/${ARCH}/ffx package build \
463 --api-level $(${SDK_PATH}/tools/${ARCH}/ffx --machine json version | jq .tool_version.api_level) \
464 --out pkg/hello_fuchsia_manifest \
465 pkg/hello_fuchsia.manifest
468 This will produce `pkg/hello_fuchsia_manifest/` which is a package manifest we can
469 publish directly to a repository.
471 **Current directory structure**
477 ┃ ┗━ hello_fuchsia.cm
478 ┣━ hello_fuchsia_manifest/
480 ┣━ hello_fuchsia.manifest
482 ┗━ hello_fuchsia_package_manifest
485 We are now ready to publish the package.
487 ## Publishing a Fuchsia package
489 With our package and component manifests setup,
490 we can now publish our package. The first step will
491 be to create a Fuchsia package repository to publish
494 ### Creating a Fuchsia package repository
496 We can set up our repository with:
499 ${SDK_PATH}/tools/${ARCH}/ffx repository create pkg/repo
502 **Current directory structure**
508 ┃ ┗━ hello_fuchsia.cm
509 ┣━ hello_fuchsia_manifest/
513 ┣━ hello_fuchsia.manifest
515 ┗━ hello_fuchsia_package_manifest
518 ## Publishing Fuchsia package to repository
520 We can publish our new package to that repository with:
523 ${SDK_PATH}/tools/${ARCH}/ffx repository publish \
524 --package pkg/hello_fuchsia_package_manifest \
528 Then we can add the repository to `ffx`'s package server as `hello-fuchsia` using:
531 ${SDK_PATH}/tools/${ARCH}/ffx repository add-from-pm \
532 --repository hello-fuchsia \
536 ## Running a Fuchsia component on an emulator
538 At this point, we are ready to run our Fuchsia
539 component. For reference, our final directory
540 structure will look like:
542 **Final directory structure**
545 ┣━ src/ (if using rustc)
546 ┃ ┗━ hello_fuchsia.rs ...
548 ┃ ┗━ hello_fuchsia ...
549 ┣━ src/ (if using cargo)
552 ┃ ┗━ x86_64-unknown-fuchsia/ ...
554 ┃ ┗━ hello_fuchsia ...
558 ┃ ┗━ hello_fuchsia.cm
559 ┣━ hello_fuchsia_manifest/
563 ┣━ hello_fuchsia.manifest
565 ┗━ hello_fuchsia_package_manifest
568 ### Starting the Fuchsia emulator
570 Start a Fuchsia emulator in a new terminal using:
573 ${SDK_PATH}/tools/${ARCH}/ffx product-bundle get workstation_eng.qemu-${ARCH}
574 ${SDK_PATH}/tools/${ARCH}/ffx emu start workstation_eng.qemu-${ARCH} --headless
577 ### Watching emulator logs
579 Once the emulator is running, open a separate terminal to watch the emulator logs:
581 **In separate terminal**
583 ${SDK_PATH}/tools/${ARCH}/ffx log \
587 ### Serving a Fuchsia package
589 Now, start a package repository server to serve our
590 package to the emulator:
593 ${SDK_PATH}/tools/${ARCH}/ffx repository server start
596 Once the repository server is up and running, register it with the target Fuchsia system running in the emulator:
599 ${SDK_PATH}/tools/${ARCH}/ffx target repository register \
600 --repository hello-fuchsia
603 ### Running a Fuchsia component
605 Finally, run the component:
608 ${SDK_PATH}/tools/${ARCH}/ffx component run \
609 /core/ffx-laboratory:hello_fuchsia \
610 fuchsia-pkg://hello-fuchsia/hello_fuchsia_manifest#meta/hello_fuchsia.cm
613 On reruns of the component, the `--recreate` argument may also need to be
617 ${SDK_PATH}/tools/${ARCH}/ffx component run \
619 /core/ffx-laboratory:hello_fuchsia \
620 fuchsia-pkg://hello-fuchsia/hello_fuchsia_manifest#meta/hello_fuchsia.cm
623 ## `.gitignore` extensions
625 Optionally, we can create/extend our `.gitignore` file to ignore files and
626 directories that are not helpful to track:
630 pkg/meta/hello_fuchsia.cm
631 pkg/hello_fuchsia_manifest
632 pkg/hello_fuchsia_package_manifest
637 ### Running unit tests
639 Tests can be run in the same way as a regular binary.
641 * If using `cargo`, you can simply pass `test --no-run`
642 to the `cargo` invocation and then repackage and rerun the Fuchsia package. From our previous example,
643 this would look like `cargo test --target x86_64-unknown-fuchsia --no-run`, and moving the executable
644 binary path found from the line `Executable unittests src/main.rs (target/x86_64-unknown-fuchsia/debug/deps/hello_fuchsia-<HASH>)`
645 into `pkg/hello_fuchsia.manifest`.
647 * If using the compiled `rustc`, you can simply pass `--test`
648 to the `rustc` invocation and then repackage and rerun the Fuchsia package.
650 The test harness will run the applicable unit tests.
652 Often when testing, you may want to pass additional command line arguments to
653 your binary. Additional arguments can be set in the component manifest:
655 **`pkg/hello_fuchsia.cml`**
658 include: [ "syslog/client.shard.cml" ],
661 binary: "bin/hello_fuchsia",
667 This will pass the argument `it_works` to the binary, filtering the tests to
668 only those tests that match the pattern. There are many more configuration
669 options available in CML including environment variables. More documentation is
670 available on the [Fuchsia devsite].
672 ### Running the compiler test suite
674 The commands in this section assume that they are being run from inside your
675 local Rust source checkout:
681 To run the Rust test suite on an emulated Fuchsia device, you'll also need to
682 download a copy of the Fuchsia SDK. The current minimum supported SDK version is
683 [20.20240412.3.1][minimum_supported_sdk_version].
685 [minimum_supported_sdk_version]: https://chrome-infra-packages.appspot.com/p/fuchsia/sdk/core/linux-amd64/+/version:20.20240412.3.1
687 Fuchsia's test runner interacts with the Fuchsia emulator and is located at
688 `src/ci/docker/scripts/fuchsia-test-runner.py`. First, add the following
689 variables to your existing `config-env.sh`:
692 # TEST_TOOLCHAIN_TMP_DIR can point anywhere, but it:
693 # - must be less than 108 characters, otherwise qemu can't handle the path
694 # - must be consistent across calls to this file (don't use `mktemp -d` here)
695 export TEST_TOOLCHAIN_TMP_DIR="/tmp/rust-tmp"
697 # Keep existing contents of `config-env.sh` from earlier, including SDK_PATH
700 We can then use the script to start our test environment with:
704 source config-env.sh && \
705 src/ci/docker/scripts/fuchsia-test-runner.py start \
706 --rust-build ${RUST_SRC_PATH}/build \
708 --target {x86_64-unknown-fuchsia|aarch64-unknown-fuchsia} \
713 Where `${RUST_SRC_PATH}/build` is the `build-dir` set in `config.toml`.
715 Once our environment is started, we can run our tests using `x.py` as usual. The
716 test runner script will run the compiled tests on an emulated Fuchsia device. To
717 run the full `tests/ui` test suite:
721 source config-env.sh && \
723 --config config.toml \
726 --target x86_64-unknown-fuchsia \
728 --test-args --target-rustcflags \
729 --test-args -Lnative=${SDK_PATH}/arch/{x64|arm64}/sysroot/lib \
730 --test-args --target-rustcflags \
731 --test-args -Lnative=${SDK_PATH}/arch/{x64|arm64}/lib \
732 --test-args --target-rustcflags \
733 --test-args -Clink-arg=--undefined-version \
734 --test-args --remote-test-client \
735 --test-args src/ci/docker/scripts/fuchsia-test-runner.py \
739 By default, `x.py` compiles test binaries with `panic=unwind`. If you built your
740 Rust toolchain with `-Cpanic=abort`, you need to tell `x.py` to compile test
741 binaries with `panic=abort` as well:
744 --test-args --target-rustcflags \
745 --test-args -Cpanic=abort \
746 --test-args --target-rustcflags \
747 --test-args -Zpanic_abort_tests \
750 When finished testing, the test runner can be used to stop the test environment:
753 src/ci/docker/scripts/fuchsia-test-runner.py stop
760 Debugging components running on a Fuchsia emulator can be done using the
761 console-mode debugger: [zxdb]. We will demonstrate attaching necessary symbol
762 paths to debug our `hello-fuchsia` component.
766 In a separate terminal, issue the following command from our `hello_fuchsia`
767 directory to launch `zxdb`:
769 **In separate terminal**
771 ${SDK_PATH}/tools/${ARCH}/ffx debug connect -- \
772 --symbol-path target/x86_64-unknown-fuchsia/debug
775 * `--symbol-path` gets required symbol paths, which are
776 necessary for stepping through your program.
778 The "[displaying source code in `zxdb`](#displaying-source-code-in-zxdb)"
779 section describes how you can display Rust and/or Fuchsia source code in your
784 Once launched, you will be presented with the window:
787 Connecting (use "disconnect" to cancel)...
788 Connected successfully.
789 👉 To get started, try "status" or "help".
793 To attach to our program, we can run:
796 [zxdb] attach hello_fuchsia
801 Waiting for process matching "hello_fuchsia".
802 Type "filter" to see the current filters.
805 Next, we can create a breakpoint at main using "b main":
813 Created Breakpoint 1 @ main
816 Finally, we can re-run the "hello_fuchsia" component from our original
820 ${SDK_PATH}/tools/${ARCH}/ffx component run \
822 fuchsia-pkg://hello-fuchsia/hello_fuchsia_manifest#meta/hello_fuchsia.cm
825 Once our component is running, our `zxdb` window will stop execution
826 in our main as desired:
830 Breakpoint 1 now matching 1 addrs for main
831 🛑 on bp 1 hello_fuchsia::main() • main.rs:2
833 ▶ 2 println!("Hello Fuchsia!");
839 `zxdb` has similar commands to other debuggers like [gdb].
840 To list the available commands, run "help" in the
841 `zxdb` window or visit [the zxdb documentation].
851 Type "help <command>" for command-specific help.
853 Other help topics (see "help <topic>")
857 ### Displaying source code in `zxdb`
859 By default, the debugger will not be able to display
860 source code while debugging. For our user code, we displayed
861 source code by pointing our debugger to our debug binary via
862 the `--symbol-path` arg. To display library source code in
863 the debugger, you must provide paths to the source using
864 `--build-dir`. For example, to display the Rust and Fuchsia
868 ${SDK_PATH}/tools/${ARCH}/ffx debug connect -- \
869 --symbol-path target/x86_64-unknown-fuchsia/debug \
870 --build-dir ${RUST_SRC_PATH}/rust \
871 --build-dir ${FUCHSIA_SRC_PATH}/fuchsia/out/default
874 * `--build-dir` links against source code paths, which
875 are not strictly necessary for debugging, but is a nice-to-have
876 for displaying source code in `zxdb`.
878 Linking to a Fuchsia checkout can help with debugging Fuchsia libraries,
881 ### Debugging the compiler test suite
883 Debugging the compiler test suite requires some special configuration:
885 First, we have to properly configure zxdb so it will be able to find debug
886 symbols and source information for our test. The test runner can do this for us
890 src/ci/docker/scripts/fuchsia-test-runner.py debug \
891 --rust-src ${RUST_SRC_PATH} \
892 --fuchsia-src ${FUCHSIA_SRC_PATH} \
896 where `${TEST}` is relative to Rust's `tests` directory (e.g. `ui/abi/...`).
898 This will start a zxdb session that is properly configured for the specific test
899 being run. All three arguments are optional, so you can omit `--fuchsia-src` if
900 you don't have it downloaded. Now is a good time to set any desired breakpoints,
903 Next, we have to tell `x.py` not to optimize or strip debug symbols from our
904 test suite binaries. We can do this by passing some new arguments to `rustc`
905 through our `x.py` invocation. The full invocation is:
909 source config-env.sh && \
911 --config config.toml \
914 --target x86_64-unknown-fuchsia \
916 --test-args --target-rustcflags \
917 --test-args -Lnative=${SDK_PATH}/arch/{x64|arm64}/sysroot/lib \
918 --test-args --target-rustcflags \
919 --test-args -Lnative=${SDK_PATH}/arch/{x64|arm64}/lib \
920 --test-args --target-rustcflags \
921 --test-args -Clink-arg=--undefined-version \
922 --test-args --target-rustcflags \
923 --test-args -Cdebuginfo=2 \
924 --test-args --target-rustcflags \
925 --test-args -Copt-level=0 \
926 --test-args --target-rustcflags \
927 --test-args -Cstrip=none \
928 --test-args --remote-test-client \
929 --test-args src/ci/docker/scripts/fuchsia-test-runner.py \
933 *If you built your Rust toolchain with `panic=abort`, make sure to include the
934 previous flags so your test binaries are also compiled with `panic=abort`.*
936 Upon running this command, the test suite binary will be run and zxdb will
937 attach and load any relevant debug symbols.
939 [Fuchsia team]: https://team-api.infra.rust-lang.org/v1/teams/fuchsia.json
940 [Fuchsia]: https://fuchsia.dev/
941 [source tree]: https://fuchsia.dev/fuchsia-src/get-started/learn/build
942 [rustup]: https://rustup.rs/
943 [cargo]: ../../cargo/index.html
944 [Fuchsia SDK]: https://chrome-infra-packages.appspot.com/p/fuchsia/sdk/core
945 [overview of CML]: https://fuchsia.dev/fuchsia-src/concepts/components/v2/component_manifests
946 [reference for the file format]: https://fuchsia.dev/reference/cml
947 [Fuchsia devsite]: https://fuchsia.dev/reference/cml
948 [not currently supported]: https://fxbug.dev/105393
949 [zxdb]: https://fuchsia.dev/fuchsia-src/development/debugger
950 [gdb]: https://www.sourceware.org/gdb/
951 [the zxdb documentation]: https://fuchsia.dev/fuchsia-src/development/debugger
952 [fdio]: https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/lib/fdio/