
Rustd – Drop-in rustc replacement for faster builds
rustd is a Rust compiler daemon. One process per user stays running, keeps rust-analyzer's
以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。
rustd is a Rust compiler daemon. One process per user stays running, keeps rust-analyzer's analysis of your workspaces in memory and, when given a directory, compiled functions in a store on disk, and answers builds from that state. After an edit it compiles the functions that changed, with Cranelift or LLVM, and either links them in front of what rustc built or splices them into the executable that is already there.
cargo and rustc start from the file system on every build: they parse, resolve, type-check and generate code for a whole crate again when one function in it changed, and a second checkout of the same repository starts from nothing. rustd keeps that work. Git worktrees of one repository share one database, and a function compiled once is found again by the hash of what it was compiled from, in any workspace on the machine or, through an S3 bucket, on another machine.
It is meant for people and coding agents who build the same code many times, often in several worktrees at once.
This is a prototype, published for the first time. Nobody outside the project has used it. Read this section before relying on it.
On macOS arm64, Linux x86-64 and Linux AArch64:
curl -fsSL https://dioxuslabs.github.io/rustd/install.sh | sh
On Windows x86-64, in PowerShell:
irm https://dioxuslabs.github.io/rustd/install.ps1 | iex
The script downloads the latest release, checks it against the release's SHA-256 sums and puts rustd, cargo-rustd and rustd-rustc in ~/.cargo/bin. RUSTD_VERSION=nightly takes the newest build of main instead. You still need Rust 1.99.0 with rust-src:
rustup toolchain install 1.99.0 --component rust-src
The released binaries have the Cranelift backend only. The LLVM backend links LLVM 20 from the machine it runs on, so it is built from source.
You need Rust 1.99.0 with the rust-src component. LLVM 20 is optional and adds the LLVM backend.
rustup toolchain install 1.99.0 --component rust-src git clone --recursive https://github.com/DioxusLabs/rustd cd rustd cargo +1.99.0 build -p rustd --release
vendor/rust-analyzer is a submodule: rust-analyzer with rustd's changes to it, kept on the rust-analyzer branch of this repository. If you cloned without --recursive, run git submodule update --init. With LLVM 20 installed (on Debian and Ubuntu, llvm-20-dev and libpolly-20-dev from apt.llvm.org):
LLVM_SYS_201_PREFIX=/usr/lib/llvm-20 cargo +1.99.0 build -p rustd --release --features llvm
The build leaves rustd, cargo-rustd and rustd-rustc in target/release. Put all three in one directory on your PATH; each runs the others from next to itself.
cp target/release/{rustd,cargo-rustd,rustd-rustc} ~/.cargo/bin/
Quick start
cargo rustd
In any cargo project, with 1.99.0 as the toolchain:
cargo rustd build cargo rustd run -- --some-flag cargo rustd test cargo rustd check
The first build of a workspace is cargo's own, with rustd recording what rustc was asked to do. It also starts the daemon, which loads the workspace in the background. Until it has, builds go to cargo and a line on stderr says so:
rustd: the daemon is still loading the workspace (951ms so far); building with cargo
After that an edit is compiled by the daemon and no cargo process runs. cargo rustd status shows what the daemon holds and how many builds it served or handed to cargo, by reason. cargo rustd stop ends it; it also exits by itself after 30 minutes without a request. cargo rustd check is cargo check.
Compiled functions are kept on disk in ~/.cache/rustd/store (8 GiB at most; RUSTD_CACHE=off turns it off), so a new daemon starts from what the last one built. See docs/cache.md for the store and the S3 remote.
Run rustd enable once. It adds one key to ~/.cargo/config.toml (build.rustc-workspace-wrapper, pointing at rustd-rustc), and from then on ordinary cargo build, cargo run, cargo test and cargo check in any workspace go through the daemon. rustd disable puts the file back as it was. rustd status says whether it is on and how many programs the daemon linked or left to rustc, by reason.
$ rustd enable $ cargo run # the daemon's, once it has loaded the workspace $ rustd disable
rustd, cargo-rustd and rustd-rustc have to be installed in the same directory. A wrapper you already use, such as sccache, keeps running. When the daemon cannot serve a build, rustc does, and one line on stderr says why. This mode is for agents and scripts that call cargo themselves; it has been run on Linux and on macOS arm64. On edits it is currently slower than cargo rustd, and on some projects slower than cargo alone; see docs/cargo.md.
Seconds for cargo rustd against plain cargo on the same edit, one run each, Linux x86-64, 8 CPUs, Cranelift. The edit adds a line to a function. From harness/cargo_rustd.py; the full table, the commit and the other steps are in docs/results.md.
The same step on macOS arm64 (8-CPU Apple M4 virtual machine), one run each, from harness/cargo_rustd.py --small:
ripgrep's edit build varied between runs there (0.52 / 0.73 and 1.08 / 1.30 in two other Cranelift runs); see docs/cargo.md.
The first build is not faster than cargo's, because it is cargo's. A build of source that does not compile goes to cargo and costs 0.1 to 0.5 s more than cargo alone. On nushell the daemon needs 36 to 51 s to load again after a manifest or build script changes, and builds are cargo's for that long.
Correctness is measured by building the same program with rustc and with rustd and comparing what they do. On the last CI run that covered all four native platforms, every function of the test corpus was compiled by rustd under both backends and no type layout differed from rustc's (822 functions on Linux x86-64, 825 on Linux AArch64, 830 on Windows, 828 on macOS). Of rustc's own tests/ui run-pass tests, 2686 of 2690 behave the same under Cranelift; 1114 were left out, for reasons listed in the results.
Linux x86-64 Linux AArch64 Windows x86-64 MSVC macOS arm64 wasm32
Cranelift yes yes yes yes no (own lowering)
LLVM yes yes yes yes no
Full link yes yes yes yes older branch only
Splice yes yes yes yes, not with chained fixups older branch only
Debug info yes yes lines only unverified no
cargo rustd yes unverified not run yes, three projects no
Disk store yes yes yes yes unverified
S3 remote yes, not real AWS unverified unverified unverified unverified
"yes" means a harness passes there and a report says where it ran. The wasm32 column was measured on an earlier branch with a nightly toolchain and has not been run since. docs/support.md has the source of every cell and the same for language and build-model features.
These are refused with a reason, and rustc or cargo builds them instead:
Not there at all: diagnostics, optimised output comparable to --release, types and variables in Windows debug info, and targets other than the ones in the table.
rustd's front end is rust-analyzer: its parser, name resolution, type inference, MIR, monomorphisation, layout and const evaluation, and its cargo workspace loading. rustd adds a code generator on top of rust-analyzer's MIR and the daemon around it. rust-analyzer is included as a submodule. It points at the rust-analyzer branch of this repository, which is upstream rust-analyzer at the commit rustd forked from with rustd's changes committed on top. None of this would exist without the rust-analyzer team's work. rustd is not part of the rust-analyzer project and is not endorsed by it; please do not report rustd problems there.
Type layout is computed with rustc's own rustc_abi crate, copied unchanged from the 1.99.0 tag into vendor/rustc_abi.
MIT or Apache-2.0, at your option, the same as rust-analyzer and rustc. See LICENSE-MIT and LICENSE-APACHE.
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。