diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d480451b..95c5e402 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -44,9 +44,6 @@ jobs: with: python-version: '3.x' - - name: Install Python dependencies - run: pip install tomli - - name: Configure run: | mkdir build && cd build diff --git a/CMakeLists.txt b/CMakeLists.txt index e0bbfe7b..e16dda8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,17 +64,12 @@ if (NOT RUSTC_LLVM_VERSION STREQUAL LLVM_PACKAGE_VERSION) endif() include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/rust-toolchain.cmake) - -# rule-preprocessor uses nightly -foreach(_dir libcc2rs rules) - write_rust_toolchain(${CMAKE_SOURCE_DIR}/${_dir}) -endforeach() - set(RUST_STAMP_FILE "${CMAKE_BINARY_DIR}/.rust-toolchain.stamp") add_custom_command( OUTPUT "${RUST_STAMP_FILE}" COMMAND rustup toolchain install ${RUST_STABLE_VERSION} + COMMAND rustup toolchain install ${RUST_NIGHTLY_VERSION} --component rustc-dev --component llvm-tools COMMAND ${CMAKE_COMMAND} -E touch "${RUST_STAMP_FILE}" DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/rust-toolchain.cmake" USES_TERMINAL @@ -95,18 +90,18 @@ set(PYTHON_SOURCES ${PROJECT_SOURCE_DIR}/tests/lit/lit/formats/Cpp2RustTest.py) add_custom_target("format" COMMAND ${CLANG_FORMAT} -i ${ALL_CXX_SOURCES} - COMMAND rustup run ${RUST_STABLE_VERSION} cargo fmt --manifest-path ${PROJECT_SOURCE_DIR}/rules/Cargo.toml - COMMAND rustup run ${RUST_STABLE_VERSION} cargo fmt --manifest-path ${PROJECT_SOURCE_DIR}/rule-preprocessor/Cargo.toml - COMMAND rustup run ${RUST_STABLE_VERSION} cargo fmt --manifest-path ${PROJECT_SOURCE_DIR}/libcc2rs/Cargo.toml - COMMAND rustup run ${RUST_STABLE_VERSION} cargo fmt --manifest-path ${PROJECT_SOURCE_DIR}/libcc2rs-macros/Cargo.toml - COMMAND ${CMAKE_COMMAND} -E chdir ${PROJECT_SOURCE_DIR}/rules - cargo clippy --fix --allow-dirty --allow-staged --all-targets --all-features -- -Dwarnings - COMMAND ${CMAKE_COMMAND} -E chdir ${PROJECT_SOURCE_DIR}/rule-preprocessor - cargo clippy --fix --allow-dirty --allow-staged --all-targets --all-features -- -Dwarnings - COMMAND ${CMAKE_COMMAND} -E chdir ${PROJECT_SOURCE_DIR}/libcc2rs - cargo clippy --fix --allow-dirty --allow-staged --all-targets --all-features -- -Dwarnings - COMMAND ${CMAKE_COMMAND} -E chdir ${PROJECT_SOURCE_DIR}/libcc2rs-macros - cargo clippy --fix --allow-dirty --allow-staged --all-targets --all-features -- -Dwarnings + COMMAND cargo +${RUST_STABLE_VERSION} fmt --manifest-path ${PROJECT_SOURCE_DIR}/rules/Cargo.toml + COMMAND cargo +${RUST_STABLE_VERSION} --manifest-path ${PROJECT_SOURCE_DIR}/rule-preprocessor/Cargo.toml + COMMAND cargo +${RUST_STABLE_VERSION} fmt --manifest-path ${PROJECT_SOURCE_DIR}/libcc2rs/Cargo.toml + COMMAND cargo +${RUST_STABLE_VERSION} fmt --manifest-path ${PROJECT_SOURCE_DIR}/libcc2rs-macros/Cargo.toml + COMMAND cargo +${RUST_STABLE_VERSION} clippy --fix --allow-dirty --allow-staged --all-targets --all-features + --manifest-path ${PROJECT_SOURCE_DIR}/rules/Cargo.toml -- -Dwarnings + COMMAND cargo +${RUST_STABLE_VERSION} clippy --fix --allow-dirty --allow-staged --all-targets --all-features + --manifest-path chdir ${PROJECT_SOURCE_DIR}/rule-preprocessor/Cargo.toml -- -Dwarnings + COMMAND cargo +${RUST_STABLE_VERSION} clippy --fix --allow-dirty --allow-staged --all-targets --all-features + --manifest-path $${PROJECT_SOURCE_DIR}/libcc2rs/Cargo.toml -- -Dwarnings + COMMAND cargo +${RUST_STABLE_VERSION} clippy --fix --allow-dirty --allow-staged --all-targets --all-features + --manifest-path ${PROJECT_SOURCE_DIR}/libcc2rs-macros/Cargo.toml -- -Dwarnings COMMAND ${RUFF} --silent check --fix ${PYTHON_SOURCES} COMMAND ${RUFF} --silent format ${PYTHON_SOURCES} DEPENDS "${RUST_STAMP_FILE}" @@ -119,7 +114,7 @@ if (NOT LIT_FLAGS) endif() add_custom_target("check-libcc2rs" - COMMAND cargo test + COMMAND cargo +${RUST_STABLE_VERSION} test WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/libcc2rs" DEPENDS "${RUST_STAMP_FILE}" USES_TERMINAL @@ -188,12 +183,10 @@ file(GLOB_RECURSE rule_preprocessor_sources add_custom_command( OUTPUT ${rust_rules_ir_outputs} - COMMAND cargo build - COMMAND ${CMAKE_COMMAND} -E chdir ${PROJECT_SOURCE_DIR}/rule-preprocessor - ${CMAKE_COMMAND} -E env - CARGO_TARGET_DIR=${PROJECT_SOURCE_DIR}/rule-preprocessor/target - cargo run - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/rules" + COMMAND cargo +${RUST_STABLE_VERSION} build --release --manifest-path "${PROJECT_SOURCE_DIR}/rules/Cargo.toml" + COMMAND ${CMAKE_COMMAND} -E env + CARGO_TARGET_DIR="${CMAKE_CURRENT_BINARY_DIR}/target_preprocessor" + cargo +${RUST_NIGHTLY_VERSION} run --manifest-path "${PROJECT_SOURCE_DIR}/rule-preprocessor/Cargo.toml" DEPENDS ${rust_rules_inputs} ${rule_preprocessor_sources} "${RUST_STAMP_FILE}" VERBATIM ) diff --git a/README.md b/README.md index 522a1260..5e51854b 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,7 @@ while satisfying Rust's borrow checker through checked run-time operations. On Ubuntu, install the required dependencies with: ```bash -sudo apt install libclang-22-dev clang++-22 ninja-build cmake python3-tomli -curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.95.0 +sudo apt install libclang-22-dev clang++-22 ninja-build cmake curl -LsSf https://astral.sh/ruff/install.sh | sh ``` diff --git a/cmake/rust-toolchain.cmake b/cmake/rust-toolchain.cmake index e6449eda..60a4cadf 100644 --- a/cmake/rust-toolchain.cmake +++ b/cmake/rust-toolchain.cmake @@ -1,12 +1,2 @@ set(RUST_STABLE_VERSION "1.95.0") - -function(write_rust_toolchain DIR) - set(_content "[toolchain]\nchannel = \"${RUST_STABLE_VERSION}\"\n") - set(_file ${DIR}/rust-toolchain.toml) - if (EXISTS ${_file}) - file(READ ${_file} _existing) - endif() - if (NOT "${_existing}" STREQUAL "${_content}") - file(WRITE ${_file} ${_content}) - endif() -endfunction() +set(RUST_NIGHTLY_VERSION "nightly-2026-05-13") diff --git a/libcc2rs/rust-toolchain.toml b/libcc2rs/rust-toolchain.toml deleted file mode 100644 index f25b5b14..00000000 --- a/libcc2rs/rust-toolchain.toml +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -channel = "1.95.0" diff --git a/rule-preprocessor/rust-toolchain.toml b/rule-preprocessor/rust-toolchain.toml deleted file mode 100644 index a2476a8e..00000000 --- a/rule-preprocessor/rust-toolchain.toml +++ /dev/null @@ -1,3 +0,0 @@ -[toolchain] -channel = "nightly-2026-03-25" -components = ["rustc-dev", "llvm-tools"] diff --git a/rules/rust-toolchain.toml b/rules/rust-toolchain.toml deleted file mode 100644 index f25b5b14..00000000 --- a/rules/rust-toolchain.toml +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -channel = "1.95.0" diff --git a/tests/lit/lit/formats/Cpp2RustTest.py b/tests/lit/lit/formats/Cpp2RustTest.py index 717ba3fd..c6375902 100644 --- a/tests/lit/lit/formats/Cpp2RustTest.py +++ b/tests/lit/lit/formats/Cpp2RustTest.py @@ -9,15 +9,18 @@ import re import shutil import random -import tomli def read_rust_version(): toolchain_path = os.path.join( - os.path.dirname(__file__), "../../../../libcc2rs/rust-toolchain.toml" + os.path.dirname(__file__), "../../../../cmake/rust-toolchain.cmake" ) - with open(toolchain_path, "rb") as f: - return tomli.load(f)["toolchain"]["channel"] + with open(toolchain_path, "r") as f: + for line in f: + m = re.match(r'set\(RUST_STABLE_VERSION\s+"([^"]+)', line) + if m: + return m.group(1) + raise Exception("could not find rust version in " + toolchain_path) def shared_target_dir(): @@ -170,15 +173,12 @@ def fail(str, code=fail_code): pkg_name = "test_" + re.sub(r"[^a-zA-Z0-9_]", "_", os.path.basename(tmp_dir)) # Check if we can compile the rust file - with open(tmp_dir + "/rust-toolchain.toml", "w") as f: - f.write(f'[toolchain]\nchannel = "{self.rust_version}"\n') with open(tmp_dir + "/Cargo.toml", "w") as f: f.write(f""" [package] name = "{pkg_name}" version = "0.1.0" edition = "2021" -rust-version = "{self.rust_version}" [[bin]] name = "{pkg_name}" @@ -189,7 +189,7 @@ def fail(str, code=fail_code): libcc2rs = {{ path = "../../../libcc2rs" }} """) - cmd = ["cargo", "build", "--release", "--quiet"] + cmd = ["cargo", "+" + self.rust_version, "build", "--release", "--quiet"] _, err, returncode = lit.util.executeCommand(cmd, tmp_dir, env=cargo_env()) if should_not_compile: if returncode != 0: