"Why is the Rust compiler so slow?" 26 Jun 2025 at 00:34:13 +01:00 I spent a month repeatedly building my website in Docker, and now have horrors to share. I've got a problem. My website (the one you're reading right now) is mainly served by a single Rust binary. For far too long now, every time I wanted to make a change, I would: Build a new statically linked binary (with --target=x86_64-unknown-linux-musl) Copy it to my server Restart the website This is... not ideal. So instead, I'd like to switch to deploying my website with containers (be it Docker, Kubernetes, or otherwise), matching the vast majority of software deployed any time in the last decade. The only issue is that fast Rust builds with Docker are not simple. Basics: Rust in Docker Rust in Docker, the simple way To get your Rust program in a container, the typical approach you might find would be something like: FROM rust:1.87-alpine3.22 AS builder RUN apk add musl-dev WORKDIR /workdir COPY . . RUN cargo build --package web-http-server --target=x86_64-unknown-linux-musl FROM alpine:3.20 COPY --from=builder /workdir/target/x86_64-unknown-linux-musl/release/web-http-server /usr/bin/web-http-server ENTRYPOINT ["/usr/bin/web-http-server"] Unfortunately, this will rebuild everything from scratch whenever there's any change. In my case, building from scratch takes about 4 minutes (including 10s to download the crates every time). $ cargo build --release --target=x86_64-unknown-linux-musl --package web-http-server Updating crates.io index Downloading crates ... Downloaded anstream v0.6.18 Downloaded http-body v1.0.1 ... many more lines ... Compiling web-http-server v0.1.0 (/workdir/web-http-server) Finished `release` profile [optimized + debuginfo] target(s) in 3m 51s Sure, it could be worse. But I've grown accustomed to speedy local builds, thanks to incremental compilation — I don't want to wait that long on every tiny change! Rust in Docker, with better caching Thankfully, there's a tool to help with this!...
First seen: 2025-06-26 20:24
Last seen: 2025-06-27 01:25