Skip to content

Commit 3ecc201

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 3ecc201

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

rust/ql/integration-tests/conftest.py

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

9+
_PINNED_TOOLCHAIN = "1.94.1"
10+
11+
12+
@pytest.fixture(autouse=True)
13+
def _pin_rust_toolchain(cwd):
14+
"""Pin the Rust toolchain for integration tests.
15+
16+
Integration tests run from temporary directories, so they don't pick up
17+
rust-toolchain.toml via rustup's file-based resolution. Writing the file
18+
into the test's working directory ensures a consistent toolchain version
19+
regardless of what is pre-installed on the runner image.
20+
"""
21+
(cwd / "rust-toolchain.toml").write_text(textwrap.dedent(f"""\
22+
[toolchain]
23+
channel = "{_PINNED_TOOLCHAIN}"
24+
components = ["rust-src"]
25+
"""))
26+
727

828
@pytest.fixture(params=[2018, 2021, 2024])
929
def rust_edition(request):
@@ -33,7 +53,8 @@ def update(file):
3353

3454
@pytest.fixture(scope="session")
3555
def rust_sysroot_src() -> str:
36-
rust_sysroot = pathlib.Path(commands.run("rustc --print sysroot", _capture=True))
56+
commands.run(f"rustup component add rust-src --toolchain {_PINNED_TOOLCHAIN}")
57+
rust_sysroot = pathlib.Path(commands.run(f"rustc +{_PINNED_TOOLCHAIN} --print sysroot", _capture=True))
3758
ret = rust_sysroot.joinpath("lib", "rustlib", "src", "rust", "library")
3859
assert ret.exists()
3960
return str(ret)

0 commit comments

Comments
 (0)