Toolchains
Motor OS has one compilation target, x86_64-unknown-motor, and
two toolchains for it. On Linux, a cross toolchain (Rust with Cargo, and Clang) builds
Motor OS itself and any program for it. On the developer image, a native toolchain
(rustc with a full sysroot, Clang/LLVM with a C and C++ sysroot, and Lorry as the build
driver) builds programs on Motor OS. Both come from the same forks of Rust, LLVM, and
mlibc, packaged by
motor-os-toolchain.
Components and lineage
| Component | Source | What Motor OS adds |
|---|---|---|
| Rust | moturus/rust, based on Rust 1.99.1 with LLVM 23.1.1 | The x86_64-unknown-motor target, a Tier-3 target upstream; the standard library's Motor OS layer, which calls the published moto-rt crate; compiler and runtime patches on the motor-os-1.99.1 branch, from which both the cross and native toolchains are built. |
| Cargo, Clippy, rustfmt | At the revisions the Rust fork specifies | Cargo runs on Linux only. Clippy's driver and rustfmt are also built natively for the developer image, where lorry clippy and Helix use them. The Motor rustfmt port resolves user configuration under /user and /user/cfg/rustfmt. |
| LLVM | moturus/llvm-project, LLVM 23 | A Motor OS target in Clang: the driver knows the link line, the defaults (emulated TLS, static PIE, lld, compiler-rt, libc++), and the sysroot layout. Built twice: for the Linux host, and natively for Motor OS. |
| mlibc | moturus/mlibc | The Motor OS sysdeps and a build configuration that reads its runtime files from /system/cfg/libc. The fork also owns sysdeps/motor/moto-rt-cabi, a C ABI over the published Motor runtime crates (see C/C++ on Motor OS). |
| Small crate forks | moturus/libc, moturus/stacker, moturus/rust_libloading, moturus/rust-ctrlc | Patched into the Rust fork's own dependency graph; Cargo fetches them, nothing is cloned by hand. |
| Lua, ripgrep, Helix, sed | Lua 5.4.8 from lua.org, unmodified; moturus/ripgrep; moturus/helix; moturus/sed (uutils sed) | External sources, not parts of the toolchain: built with the finished toolchain on every run of the build. Lua was the first real C program and ripgrep the first large Rust program; they ship as /devtools/bin/lua, /system/bin/rg, /devtools/helix/hx, and /devtools/bin/sed. |
| tar, zstd, Javy/Wasmi, Wasmtime | moturus/motor-os-tar, moturus/javy, moturus/wasmtime | External sources too. The archive tools ship in /system/bin; the WebAssembly tools ship in the developer and wasm images. Both builders use motor-os-tar's Linux tar for packaging or extraction. |
The target
The target specification in the Rust fork describes what every Motor OS program
looks like: a static position-independent executable, linked self-contained (no
dynamic linking, no system linker libraries), panic = unwind by default, entry point
motor_start, thread-locals provided by the runtime rather than ELF TLS, and
full RELRO. Clang's Motor target applies the same rules to C and C++: emulated TLS,
-static-pie, lld, and a link line that adds crt1.o, the runtime shim,
libc++abi, libunwind, libc, and the compiler builtins. A program built by either compiler
runs on any Motor OS image, because it carries everything it needs except the runtime
object that the OS maps into every process.
System binaries declare abort profiles explicitly. Applications can opt out of
unwinding with a Cargo profile's panic = "abort" or rustc's
-C panic=abort. In Rust programs containing C++, the Rust unwinder owns the
_Unwind_* ABI for both languages; pure C/C++ programs use LLVM libunwind.
See the runtime contract
for initialization and ELF layout requirements.
The cross toolchain on Linux
Rust
The Motor toolchain installs as one rustup toolchain named after the Motor target and
the Rust version it is based on, x86_64-unknown-motor-1.99.1 today. It
contains
rustc and rustdoc, its own Cargo, Clippy, rustfmt, rust-analyzer
with a matching host proc-macro server, the
standard library for the Linux host, the standard library for
x86_64-unknown-motor under lib/rustlib/x86_64-unknown-motor, and
the library sources; nothing is borrowed from another rustup channel. The repository's
rust-toolchain.toml names that toolchain, so everything in the repository is
built with
cargo build --target x86_64-unknown-motor [--release]
and nothing more: the standard library is prebuilt, so ordinary programs do not use
-Zbuild-std. Only the bare-metal pieces, the kernel and the boot stages, use
custom JSON targets and build core and alloc themselves from the
toolchain's library sources. The Makefile applies the same command to every component,
keeps each crate's Cargo output under build/obj/, and
copies stripped binaries into build/bin/debug or
build/bin/release for the imager; make -j$(nproc) builds the debug
tree and BUILD=release the release tree. See
Building Motor OS.
A pure-Rust program needs no linker configuration: rustc links it with its bundled
lld. A crate that compiles C code (curl, Lorry) points Cargo at the Motor Clang instead,
with CARGO_TARGET_X86_64_UNKNOWN_MOTOR_LINKER set to motor-clang
(from the toolchain's lib/rustlib/x86_64-unknown-motor/sysroot/bin) and
CC_x86_64_unknown_motor to the same compiler, so that the C parts are built
against the Motor sysroot.
Cross-compiling your own program
cargo new hello, and write the program against the standard library, as on any other platform.- If it uses Tokio, mio, rustls with ring, crossterm, or the ctrlc crate, add the Motor
OS forks to
[patch.crates-io]inCargo.toml, as the in-tree programs do; the table in Rust on Motor OS lists them. cargo build --release --target x86_64-unknown-motor. The repository'srust-toolchain.tomlapplies to projects inside the checkout (the recipe usesbuild/examples/); for a project elsewhere, copy that file next to itsCargo.toml. The result istarget/x86_64-unknown-motor/release/hello.- Copy it into a running VM with
scpand run it; see Hello Motor OS for the whole sequence.
C and C++
The host Clang is the LLVM fork's own build, in the toolchain's
lib/rustlib/x86_64-unknown-linux-gnu/bin with lld and the other LLVM tools.
The toolchain also carries, in lib/rustlib/x86_64-unknown-motor/sysroot, a
sysroot directory with mlibc's headers and the static libraries, and three small
wrappers in its bin:
| Wrapper | What it does |
|---|---|
motor-clang | Runs the host Clang with --target=x86_64-unknown-motor and the sysroot, letting the driver's Motor target add the runtime link line; motor-clang -O2 prog.c -o prog is a complete build. |
motor-clang++ | The same for C++, with libc++. |
motor-rust-cc | The linker Rust bootstrap uses for Motor: adds the runtime group (crt1.o, the shim, libc++, libc++abi, libunwind, libc, the builtins) to a rustc-driven link. |
A C program cross-compiled this way is the same static executable the native compiler produces, and runs on any image. What the C library and libc++ support is on the C/C++ on Motor OS page.
The native toolchain on the developer image
Nothing on the developer image compiles itself into existence: the native compilers are cross-built on Linux and staged into the image. Once there, they compile Motor OS programs on Motor OS, with no host involved.
rustc
/devtools/rust/bin/rustc is the Rust fork's compiler built with Motor OS as
the host (x.py build --stage 2 compiler --host x86_64-unknown-motor): a single
static executable of about 100 MB with its own LLVM inside. Its sysroot,
/devtools/rust/lib/rustlib/x86_64-unknown-motor/lib, is the complete set of
prebuilt crates: std, core, alloc,
proc_macro, test, panic_abort, panic_unwind,
unwind, unwinding, the compiler builtins,
moto_rt, and their dependencies, each as an .rlib with its
metadata. /devtools/bin/rustc, the command on PATH, is a two-line
script that runs it.
rustc -O /devtools/src/hello-world/hello.rs -o /user/tmp/hello && /user/tmp/hello
No linker option is needed: rustc's default linker driver is cc, which on
the image is /devtools/bin/cc, the native Clang, which links with lld. There is
no Cargo or rustdoc on the image. Packages with dependencies are built with Lorry,
below. Lorry runs Clippy through the image's clippy-driver, and runs
procedural macros as separate static executables because Motor OS has no dynamic
loading.
The native formatter is /devtools/rust/bin/rustfmt, exposed through
/devtools/bin/rustfmt. The language server lives at
/devtools/rust/bin/rust-analyzer, with matching library sources under
/devtools/rust/lib/rustlib/src/rust/library; it has no separate native
proc-macro server or shared librustc_driver. Helix uses the native server
and formatter; see Editors.
Clang/LLVM
/devtools/llvm/bin/llvm is one static executable of about 107 MB that
contains the whole LLVM toolchain as subcommands: clang, clang++,
lld (and its ld.lld flavor), ar, ranlib,
nm, objcopy, strip, objdump,
readelf, size, addr2line, cxxfilt,
dwp, and more, invoked as llvm clang ... or llvm ar ....
It was configured with Motor OS as its host and default target, lld as the default linker,
compiler-rt as the runtime library, libc++ as the C++ standard library, and
/devtools/llvm/cfg as its configuration directory, where
x86_64-unknown-motor.cfg points it at its resource directory,
/devtools/llvm/lib/clang/23. /devtools/bin/cc and
/devtools/bin/c++ are two-line scripts over it.
The sysroot is under /devtools/llvm: include holds mlibc's
headers, libc++'s c++/v1, and moto_rt.h; lib holds
crt1.o, libc.a, libc++.a, libc++abi.a,
libunwind.a, libmoto_rt_cabi.a, the compiler-rt builtins, and empty
libm, libpthread, libdl, librt,
libresolv, libutil, and libssp archives so that
-lm and friends in existing build systems link. The C library reads its
runtime files from /system/cfg/libc.
Lorry
Lorry is the Rust build driver on the image, and a smaller, stricter Cargo replacement
for security-sensitive environments: it takes the same Cargo.toml and
Cargo.lock and aims for byte-identical binaries, never invokes Cargo, admits
dependencies once and explicitly with lorry vendor, and then builds, runs, and
tests packages offline using
/devtools/bin/rustc and, for crates with C parts, /devtools/bin/cc
and llvm ar. It builds red, gears, and itself natively in the developer-image test.
It has its own page: Lorry: the package manager.
lorry new hello && cd hello
lorry vendor --accept-all # once, with network access
lorry build --release
lorry run
Also on the image
/devtools/bin/lua (Lua 5.4.8), /devtools/bin/sed (uutils sed), /system/bin/curl (the HTTPS
client Lorry fetches with), /devtools/bin/mdbg, the test suites under
/devtools/tests, and source snapshots under /devtools/src; see
Developer image.
Installing a native toolchain update
Copy motor-toolchain-x86_64-unknown-motor-1.99.1.tar.zst into
/user/ on the VM, then extract it into an empty directory and run its
installer from an ordinary Interactive session:
mkdir /user/toolchain
cd /user/toolchain
tar -x -f /user/motor-toolchain-x86_64-unknown-motor-1.99.1.tar.zst
motor-toolchain-x86_64-unknown-motor-1.99.1/install.sh
The installer replaces /devtools/llvm and /devtools/rust,
copies launchers and examples, and sets permissions so every role can execute the
programs. Interactive owns /devtools. Installation writes only there;
mlibc's configuration stays in the image's /system/cfg/libc, with no
/devtools/cfg/libc override. Lorry binds compiled dependencies to the
installed toolchain files' sizes and modification times, so the next native build
recompiles them.
How the pieces are produced
The toolchain is built outside this repository, by
motor-os-toolchain, whose
build-toolchain.sh produces everything above in a fixed order from the heads
of the branches its versions.sh names, in about an hour. The order matters
because each layer is built with the one before it:
- The Rust, mlibc, and motor-os-tar branches are fetched; LLVM and Cargo come in as the Rust checkout's submodules, so one LLVM tree serves every LLVM build.
- The host Clang and lld are built from that LLVM tree.
- One
x.pyrun from the Rust fork builds and installs the cross toolchain: rustc, rustdoc, Cargo, Clippy, rustfmt, both standard libraries, and the library sources. Every later step uses it. - The runtime shim (
moto-rt-cabi) is built from the mlibc source with the cross toolchain and its locked registry dependencies, then the compiler-rt builtins, then mlibc against the shim, then libunwind, libc++abi, and libc++ against mlibc. - The native LLVM multicall binary is built for Motor OS against that sysroot.
- Rust bootstrap produces native rustc, rustfmt, and clippy-driver from the same Rust revision, and rust-analyzer is built for Motor OS with matching library sources.
- Everything is packaged into two archives, written by motor-os-tar's
tar: the Linux-host toolchain, and the native toolchain's files for the images, each with aninstall.sh.
This repository's src/build-motor-os.sh then builds the external sources
with the installed toolchain (Lua is cross-compiled against the sysroot as a check that a
real C program links and runs; ripgrep, Helix, sed, tar, and zstd come from their forks)
and the images, which take the native toolchain's files from its archive. The procedure,
the directory layout, and the test suites are on the
Building Motor OS page.
Each toolchain build starts from an empty build tree, writes both archives and their
.sha256 files next to its checkout, and removes the build tree on success.
It normally reads nothing from a Motor OS checkout. The
runtime-crate guide
describes the published runtime dependencies and local overrides for unpublished work.
Each archive extracts into one directory with an install.sh and its
payload: toolchain/ in the Linux-host archive and images/ in the
native archive. The native overlays are libc, llvm,
rustc, and rust-analyzer; the standard and wasm images take the
libc configuration, and the developer image takes all four overlays.
Versioning
A toolchain is named like Rust's own, by the Motor target and the Rust version it is
based on: x86_64-unknown-motor-1.99.1. A second release of the same Rust
version, after a Motor-side change, is x86_64-unknown-motor-1.99.1-2, and a
local build is x86_64-unknown-motor-1.99.1-dev. The toolchain repository's
versions.sh is the recipe of a release: the Motor Rust, mlibc, and
motor-os-tar branches. rust-toolchain.toml pins only the version, not a source
commit or digest. The standard library links the moto-rt release that the
Rust fork selects; nothing compares it with the moto-rt in this repository,
and rt.vdso checks compatibility at run time.
- One toolchain, one name. rustc, rustdoc, Cargo, Clippy, rustfmt, the
library sources, both standard libraries, Clang, and the C/C++ sysroot live in one rustup
toolchain, built from one Rust revision, with no host nightly involved. The repository's
rust-toolchain.tomlnames it. - The same C wrappers.
motor-clang,motor-clang++, andmotor-rust-ccsit in the toolchain's sysroot and find everything they use relative to themselves, so an installed toolchain works wherever it is. - A stable baseline. The current toolchain is built from the exact
Rust 1.99.1 tag with the Motor patches rebased onto it; Cargo reports
1.99.1-dev. A published release never changes.
Changing the repository's toolchain
- Obtain both archives of the new version, or build local
-devarchives. - Put the native archive in
MOTORHand install the host archive. - Set the version in
rust-toolchain.toml. - Run
make clean, thensrc/build-motor-os.shto rebuild the external sources and images. - Run
src/tests/full-test.shthree times in debug and three times with--release, thensrc/tests/full-test-dev.sh --release, as required by the repository's core change gate. - Commit the selector with any changes the new toolchain required.
Replacing an archive under the same name also changes the toolchain: reinstall the host archive, clean, rebuild, and run the same validation gates.