Skip to content

LWLP-4934: Pin cargo/rustc wrappers to the image Rust toolchain - #174

Open
Jonathan Gangi (JAVGan) wants to merge 2 commits into
mainfrom
fix/LWLP-4934-rustup-toolchain-override
Open

Jonathan Gangi (JAVGan) wants to merge 2 commits into
mainfrom
fix/LWLP-4934-rustup-toolchain-override

Conversation

@JAVGan

@JAVGan Jonathan Gangi (JAVGan) commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Jira: LWLP-4934

Problem

uv_build ships a rust-toolchain.toml pinning its own Rust channel (1.97.1 for 0.11.33). When maturin runs cargo in that tree, rustup tries to install the exact pinned toolchain at build time. Under the forced network isolation from #165/netguard this can never succeed: with the #140 group-writable RUSTUP_HOME workaround in place, rustup gets past the permission error and then fails on DNS for static.rust-lang.org (see the findings on LWLP-4934). It is also not hermetic. Upgrading Rust alone does not help, because pins are matched exactly (tested, see the closed #168).

Change

  • build_scripts/build-rust.sh: the cargo and rustc wrappers now export RUSTUP_TOOLCHAIN=${RUSTUP_TOOLCHAIN:-<RUST_VERSION>}. The env var takes precedence over rust-toolchain.toml, so rustup uses the installed toolchain and never tries to download another. A caller can still set RUSTUP_TOOLCHAIN or use cargo +<toolchain> for another already-installed toolchain. The rustup wrapper is unchanged.
  • build_scripts/rust-pin-check.sh (installed as /usr/local/libexec/lightwell-rust-pin-check, called by both wrappers when the caller has not set RUSTUP_TOOLCHAIN): Rust is backward compatible, so the image toolchain must be the same as or newer than a pin. The nearest rust-toolchain.toml (or legacy rust-toolchain) at or above the working directory is checked, like rustup does. A pin newer than RUST_VERSION fails with a message naming the file, the pin and the image version. stable and partial versions (1.97) are accepted; beta, nightly and unparsable channels fail closed because they cannot be compared.
  • tests/unit/test_rust_pin_check.py: 25 cases for the comparison, file lookup (parent directories, nearest wins, legacy file, quoting) and error exit codes.
  • tests/check_runtime.py: image-build probe that older, equal, partial and stable pins use the image toolchain (cargo/rustc --version unchanged) and that a pin one patch or one minor newer, nightly and beta all fail with the rust-pin-check message.
  • The build-rust: make rustup's install paths group-writable for crate-pinned toolchains #140 chmod block is left in place; removing it is a separate decision.

Trade-off

Crates build with the image's Rust instead of the version upstream pinned (when that is older). That is a provenance decision, taken in discussion on LWLP-4934 to avoid maintaining a list of pre-installed toolchains. A newer pin is refused rather than built with an older compiler.

Verification (end to end, in lightwell-python-tenant)

Images were built from this change (base from 183f487; the CLI image additionally had a test-only Containerfile.cli pin to that base, since removed from this branch).

  • CLI image build: the extended probe ran and passed (OK: rust-toolchain.toml pins: older or equal use the image, newer fail), so in the real image older/equal/partial/stable pins use the image toolchain and newer/nightly/beta pins fail.
  • PipelineRun python-build-kx999: python-socketio 5.16.2, target SCRATCH, builds ref cumulative/5.16.2/pipeline-19272782, wheel server disabled so uv_build is built from source. Succeeded (clone, source-to-sdist, fromager-build-wheels, clamav-scan all passed). uv_build 0.11.33 (pinned 1.97.1, older than the image's 1.98.1) and maturin 1.16.0 were compiled from source, with no rust-pin-check failure, no syncing channel, and no static.rust-lang.org references in the log.
  • The same run on the previous commit (a0220c6, no guard) also succeeded (python-build-xqkzq). On images without the override it failed: Rust bump only hit rustup/tmp: Permission denied; build-rust: make rustup's install paths group-writable for crate-pinned toolchains #140 workaround only hit dns error fetching channel-rust-1.97.1.toml.sha256 under netguard.
  • Not exercised end to end: a real package that pins a toolchain newer than the image. That case is covered by the unit tests and the image-build probe.

A run with the wheel server enabled passes on any image, because all dependencies (including uv_build) come pre-built from the validated index, so it does not exercise this path.

🤖 Generated with Claude Code

Crates and build backends can ship a rust-toolchain.toml (uv_build's sdist
pins 1.97.1), which makes rustup install that exact toolchain at build time.
Wheel builds run with network isolation, so the download can never succeed
(rustup fails on DNS for static.rust-lang.org), and it is not hermetic.

Export RUSTUP_TOOLCHAIN in the cargo and rustc wrappers, defaulting to the
installed RUST_VERSION. The env var takes precedence over rust-toolchain.toml,
so rustup uses the image toolchain. Callers can still set RUSTUP_TOOLCHAIN or
use cargo +<toolchain> to pick another installed toolchain. The rustup wrapper
is unchanged so toolchain management commands keep working.

Add an image-build probe that a rust-toolchain.toml pin to an uninstalled
version does not change what cargo and rustc report.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Jonathan Gangi <jgangi@redhat.com>
…lchain

The cargo/rustc wrappers now use the image toolchain regardless of a crate's
rust-toolchain pin. Rust is backward compatible, so that is fine for a pin that
is the same as or older than the image, but a newer pin would silently build
with an older compiler than the crate asks for.

Add rust-pin-check.sh, called by both wrappers when RUSTUP_TOOLCHAIN is not set
by the caller. It finds the nearest rust-toolchain.toml (or legacy
rust-toolchain) at or above the working directory, as rustup does, and exits
non-zero when the pinned version is newer than the image's RUST_VERSION. stable
and partial versions (1.97) are handled; beta, nightly and unparsable channels
fail closed.

Unit tests cover the comparison and file lookup. The image-build probe now also
checks that an older/equal/stable pin uses the image toolchain and that a newer,
nightly or beta pin fails.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Jonathan Gangi <jgangi@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant