From 15845b4ef786cd3baa33a3e41f5ad1e80716c645 Mon Sep 17 00:00:00 2001 From: xbmc4lyfe <273732874+xbmc4lyfe@users.noreply.github.com> Date: Thu, 26 Nov 2026 20:00:23 -0800 Subject: [PATCH 1/2] Link Linux builds with mold; line tables only for debug builds Linux x86_64 and aarch64 builds now link through scripts/link-mold.sh. It is set as the Cargo linker in .cargo/config.toml, so an environment RUSTFLAGS (-D warnings, the target-cpu tiers) can't drop it. A build host without mold stops with an install hint instead of silently falling back to another linker. Debug and test builds use debug = "line-tables-only": panics and backtraces keep file:line, and the full variable debug info is dropped. Benchmark LB-1 (warm sccache, 32 jobs, median of 3): on arm64 the clean test build went from 64.3 s to 55.5 s with mold and to 51.0 s with line tables, and the relink from 62.0 s to 47.2 s. x86_64 already linked with rust-lld, so mold alone changes nothing there (40.0 s vs 42.2 s, within noise); line tables bring it to 33.5 s. The release (LTO) build time is unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM --- .cargo/config.toml | 10 ++++++++++ .gitignore | 1 + linux/pkg/deb-rustyget/build-deb.sh | 2 +- rust/Cargo.toml | 5 +++++ scripts/link-mold.sh | 15 +++++++++++++++ site/content/install.md | 3 ++- 6 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 .cargo/config.toml create mode 100755 scripts/link-mold.sh diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 000000000..e496682fe --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,10 @@ +# 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. 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..c6008e809 --- /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 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: From d9b04edaca13b173e1401bcbee1d406a5da55850 Mon Sep 17 00:00:00 2001 From: xbmc4lyfe <273732874+xbmc4lyfe@users.noreply.github.com> Date: Thu, 26 Nov 2026 20:19:33 -0800 Subject: [PATCH 2/2] link-mold.sh checks for ld.mold; say cargo must run inside the repo -fuse-ld=mold makes the compiler driver look for ld.mold, so check that name. Cargo finds .cargo/config.toml from its working directory only. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LG44gYUGuwLMB2hw7HQGbM --- .cargo/config.toml | 4 +++- scripts/link-mold.sh | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index e496682fe..823d33a38 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -2,7 +2,9 @@ # 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. macOS keeps Apple's linker. +# 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" diff --git a/scripts/link-mold.sh b/scripts/link-mold.sh index c6008e809..eccde25da 100755 --- a/scripts/link-mold.sh +++ b/scripts/link-mold.sh @@ -5,7 +5,7 @@ # # 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 mold >/dev/null 2>&1; then +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