|
| 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 the extractor is compatible 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 | + |
7 | 29 |
|
8 | 30 | @pytest.fixture(params=[2018, 2021, 2024]) |
9 | 31 | def rust_edition(request): |
@@ -33,7 +55,8 @@ def update(file): |
33 | 55 |
|
34 | 56 | @pytest.fixture(scope="session") |
35 | 57 | 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)) |
37 | 60 | ret = rust_sysroot.joinpath("lib", "rustlib", "src", "rust", "library") |
38 | 61 | assert ret.exists() |
39 | 62 | return str(ret) |
|
0 commit comments