diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 000000000..823d33a38 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,12 @@ +# Linux builds link with mold through scripts/link-mold.sh, which stops the build with an +# install hint when mold is missing. The wrapper is set as the linker rather than through +# `rustflags`, because an environment RUSTFLAGS (`-D warnings`, the `-C target-cpu` tiers +# set by `just build`) replaces config rustflags and would silently drop the linker choice. +# Cargo resolves this relative path against the repository root. Cargo reads this file only +# when it runs inside the repository (cwd, not --manifest-path, decides), so run it from here; +# `just`, build-deb.sh and the harnesses do. macOS keeps Apple's linker. +[target.x86_64-unknown-linux-gnu] +linker = "scripts/link-mold.sh" + +[target.aarch64-unknown-linux-gnu] +linker = "scripts/link-mold.sh" diff --git a/.gitignore b/.gitignore index aff904ac9..b7351cb8d 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,7 @@ docker/config !/.gitignore !/.gitattributes !/.vale.ini +!/.cargo/ !.github/ !.github/** diff --git a/linux/pkg/deb-rustyget/build-deb.sh b/linux/pkg/deb-rustyget/build-deb.sh index bef22ff70..8975de244 100755 --- a/linux/pkg/deb-rustyget/build-deb.sh +++ b/linux/pkg/deb-rustyget/build-deb.sh @@ -1,6 +1,6 @@ #!/bin/sh # Build the side-by-side `rustyget` .deb on a Debian/Ubuntu host of the target arch. -# Needs: build-essential pkg-config libssl-dev python3 just dpkg-dev, rustup. +# Needs: build-essential pkg-config libssl-dev mold python3 just dpkg-dev, rustup. # Usage: linux/pkg/deb-rustyget/build-deb.sh [jobs] -> build/deb/rustyget__.deb set -eu diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 6e0426cf1..dac1a1f71 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -68,5 +68,10 @@ codegen-units = 1 panic = "abort" debug = 1 +# Debug and test builds (the test profile inherits this) keep file:line in panics, +# backtraces and gdb/lldb `bt`, but no variable debug info: 4-9 s less per +# `cargo build --tests` on the build farm (benchmark LB-1). For a debugger session +# with variables, build with CARGO_PROFILE_DEV_DEBUG=true. [profile.dev] panic = "abort" +debug = "line-tables-only" diff --git a/scripts/link-mold.sh b/scripts/link-mold.sh new file mode 100755 index 000000000..eccde25da --- /dev/null +++ b/scripts/link-mold.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# Cargo's linker for Linux builds (see .cargo/config.toml): the system C compiler +# driver, told to link with mold. mold links the test binaries and the daemon several +# times faster than GNU ld, and faster than the rust-lld Rust uses on x86_64 by default. +# +# A missing mold is an error, never a silent fallback to another linker, so a build +# host without it is noticed and fixed instead of quietly building slower. +if ! command -v ld.mold >/dev/null 2>&1; then + echo "error: RustyGet links Linux builds with mold, which is not installed." >&2 + echo " Debian/Ubuntu: sudo apt install mold Fedora: sudo dnf install mold" >&2 + echo " Arch: sudo pacman -S mold (see site/content/install.md)" >&2 + exit 1 +fi +# -fuse-ld comes last so it overrides the -fuse-ld=lld rustc passes on x86_64. +exec "${RUSTYGET_LINK_CC:-cc}" "$@" -fuse-ld=mold diff --git a/site/content/install.md b/site/content/install.md index 48a5e268d..83cd1ffb5 100644 --- a/site/content/install.md +++ b/site/content/install.md @@ -14,6 +14,7 @@ lede = "RustyGet runs on Linux and macOS, and builds from source with Just and R |---|---|---| | `just` | any current | Command runner used for building, testing, and packaging (`justfile`). | | C compiler and linker | any current GCC or Clang | Rust links with it, and the `zstd` crate builds the C zstd library with it. No C++ is compiled. | +| `mold` | any current (Linux only) | The linker for Linux builds, set in `.cargo/config.toml`. A Linux build without `mold` stops with an install hint. macOS uses Apple's linker. | | Rust | 1.99.0 | Pinned in `rust/rust-toolchain.toml`. With rustup, the right toolchain installs itself on the first build. | | OpenSSL | any current | For encrypted news-server and HTTPS connections | @@ -24,7 +25,7 @@ RustyGet needs no `par2`, `unrar`, or `7z` program: par2 repair and archive extr Debian 13 and Ubuntu 24.04: ```bash -sudo apt install just build-essential pkg-config libssl-dev +sudo apt install just build-essential pkg-config libssl-dev mold ``` macOS with Homebrew: