|
| 1 | +import textwrap |
| 2 | + |
1 | 3 | import pytest |
2 | 4 | import json |
3 | 5 | import commands |
4 | 6 | import pathlib |
5 | 7 | import tomllib |
6 | 8 |
|
| 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 | + |
7 | 35 |
|
8 | 36 | @pytest.fixture(params=[2018, 2021, 2024]) |
9 | 37 | def rust_edition(request): |
@@ -32,8 +60,8 @@ def update(file): |
32 | 60 |
|
33 | 61 |
|
34 | 62 | @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)) |
37 | 65 | ret = rust_sysroot.joinpath("lib", "rustlib", "src", "rust", "library") |
38 | 66 | assert ret.exists() |
39 | 67 | return str(ret) |
|
0 commit comments