Skip to content

Commit e0e279a

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 e0e279a

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

rust/ql/integration-tests/conftest.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
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(autouse=True)
15+
def _pin_rust_toolchain(cwd):
16+
"""Pin the Rust toolchain for integration tests.
17+
18+
Integration tests run from temporary directories, so they don't pick up
19+
rust-toolchain.toml via rustup's file-based resolution. Writing the file
20+
into the test's working directory ensures a consistent toolchain version
21+
regardless of what is pre-installed on the runner image.
22+
"""
23+
(cwd / "rust-toolchain.toml").write_text(textwrap.dedent(f"""\
24+
[toolchain]
25+
channel = "{_PINNED_TOOLCHAIN}"
26+
components = ["rust-src"]
27+
"""))
28+
729

830
@pytest.fixture(params=[2018, 2021, 2024])
931
def rust_edition(request):
@@ -33,7 +55,8 @@ def update(file):
3355

3456
@pytest.fixture(scope="session")
3557
def rust_sysroot_src() -> str:
36-
rust_sysroot = pathlib.Path(commands.run("rustc --print sysroot", _capture=True))
58+
commands.run(f"rustup component add rust-src --toolchain {_PINNED_TOOLCHAIN}")
59+
rust_sysroot = pathlib.Path(commands.run(f"rustc +{_PINNED_TOOLCHAIN} --print sysroot", _capture=True))
3760
ret = rust_sysroot.joinpath("lib", "rustlib", "src", "rust", "library")
3861
assert ret.exists()
3962
return str(ret)

0 commit comments

Comments
 (0)