mirror of
https://github.com/github/codeql.git
synced 2026-05-14 11:19:27 +02:00
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>
This commit is contained in:
@@ -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):
|
||||
@@ -33,7 +58,7 @@ def cargo(cwd, rust_edition):
|
||||
|
||||
@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)
|
||||
|
||||
Reference in New Issue
Block a user