diff --git a/rust/ql/integration-tests/conftest.py b/rust/ql/integration-tests/conftest.py index 578a81a849a9..4825e01d424f 100644 --- a/rust/ql/integration-tests/conftest.py +++ b/rust/ql/integration-tests/conftest.py @@ -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 update(file): @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)