Rust: pin integration test toolchain to 1.94.1

Write a `rust-toolchain.toml` into each integration test's working
directory so that tests use a consistent Rust version regardless of
what is pre-installed on the runner image.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Paolo Tranquilli
2026-04-28 11:25:02 +02:00
parent 2886127535
commit ba649835ed

View File

@@ -1,9 +1,34 @@
import textwrap
import pytest
import json
import commands
import pathlib
import tomllib
# Last known Rust version that doesn't cause integration test failures.
# TODO: remove this pinning once we figure out what's going wrong with newer versions.
_PINNED_TOOLCHAIN = "1.94.1"
@pytest.fixture(autouse=True)
def _pin_rust_toolchain(cwd):
"""Pin the Rust toolchain for integration tests.
Integration tests run from temporary directories, so they don't pick up
rust-toolchain.toml via rustup's file-based resolution. Writing the file
into the test's working directory ensures a consistent toolchain version
regardless of what is pre-installed on the runner image.
The toolchain must be pre-installed by the CI prepare action to avoid
concurrent rustup installs from parallel pytest-xdist workers.
"""
(cwd / "rust-toolchain.toml").write_text(textwrap.dedent(f"""\
[toolchain]
channel = "{_PINNED_TOOLCHAIN}"
components = ["rust-src"]
"""))
@pytest.fixture(params=[2018, 2021, 2024])
def rust_edition(request):
@@ -33,7 +58,7 @@ def cargo(cwd, rust_edition):
@pytest.fixture(scope="session")
def rust_sysroot_src() -> str:
rust_sysroot = pathlib.Path(commands.run("rustc --print sysroot", _capture=True))
rust_sysroot = pathlib.Path(commands.run(f"rustc +{_PINNED_TOOLCHAIN} --print sysroot", _capture=True))
ret = rust_sysroot.joinpath("lib", "rustlib", "src", "rust", "library")
assert ret.exists()
return str(ret)