Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion rust/ql/integration-tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
import textwrap

import pytest
import json
import commands
import pathlib
import tomllib

# Last known Rust version that doesn't cause integration test failures.
# TODO: remove this pinning once we figure out what's going wrong with newer versions.
_PINNED_TOOLCHAIN = "1.94.1"


@pytest.fixture(autouse=True)
def _pin_rust_toolchain(cwd):
"""Pin the Rust toolchain for integration tests.

Integration tests run from temporary directories, so they don't pick up
rust-toolchain.toml via rustup's file-based resolution. Writing the file
into the test's working directory ensures a consistent toolchain version
regardless of what is pre-installed on the runner image.

The toolchain must be pre-installed by the CI prepare action to avoid
concurrent rustup installs from parallel pytest-xdist workers.
"""
(cwd / "rust-toolchain.toml").write_text(textwrap.dedent(f"""\
[toolchain]
channel = "{_PINNED_TOOLCHAIN}"
components = ["rust-src"]
"""))


@pytest.fixture(params=[2018, 2021, 2024])
def rust_edition(request):
Expand Down Expand Up @@ -33,7 +58,7 @@ def update(file):

@pytest.fixture(scope="session")
def rust_sysroot_src() -> str:
rust_sysroot = pathlib.Path(commands.run("rustc --print sysroot", _capture=True))
rust_sysroot = pathlib.Path(commands.run(f"rustc +{_PINNED_TOOLCHAIN} --print sysroot", _capture=True))
ret = rust_sysroot.joinpath("lib", "rustlib", "src", "rust", "library")
assert ret.exists()
return str(ret)
Expand Down
Loading