Skip to content

Commit ad23242

Browse files
redsun82Copilot
andcommitted
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>
1 parent 2886127 commit ad23242

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

rust/ql/integration-tests/conftest.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
1+
import textwrap
2+
13
import pytest
24
import json
35
import commands
46
import pathlib
57
import tomllib
68

9+
# Last known Rust version that doesn't cause integration test failures.
10+
# TODO: remove this pinning once we figure out what's going wrong with newer versions.
11+
_PINNED_TOOLCHAIN = "1.94.1"
12+
13+
14+
@pytest.fixture(scope="session")
15+
def _ensure_pinned_toolchain():
16+
"""Pre-install the pinned toolchain once before parallel workers start."""
17+
commands.run(f"rustup toolchain install {_PINNED_TOOLCHAIN} --component rust-src")
18+
19+
20+
@pytest.fixture(autouse=True)
21+
def _pin_rust_toolchain(cwd, _ensure_pinned_toolchain):
22+
"""Pin the Rust toolchain for integration tests.
23+
24+
Integration tests run from temporary directories, so they don't pick up
25+
rust-toolchain.toml via rustup's file-based resolution. Writing the file
26+
into the test's working directory ensures a consistent toolchain version
27+
regardless of what is pre-installed on the runner image.
28+
"""
29+
(cwd / "rust-toolchain.toml").write_text(textwrap.dedent(f"""\
30+
[toolchain]
31+
channel = "{_PINNED_TOOLCHAIN}"
32+
components = ["rust-src"]
33+
"""))
34+
735

836
@pytest.fixture(params=[2018, 2021, 2024])
937
def rust_edition(request):
@@ -32,8 +60,8 @@ def update(file):
3260

3361

3462
@pytest.fixture(scope="session")
35-
def rust_sysroot_src() -> str:
36-
rust_sysroot = pathlib.Path(commands.run("rustc --print sysroot", _capture=True))
63+
def rust_sysroot_src(_ensure_pinned_toolchain) -> str:
64+
rust_sysroot = pathlib.Path(commands.run(f"rustc +{_PINNED_TOOLCHAIN} --print sysroot", _capture=True))
3765
ret = rust_sysroot.joinpath("lib", "rustlib", "src", "rust", "library")
3866
assert ret.exists()
3967
return str(ret)

0 commit comments

Comments
 (0)