Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 0 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 18 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
Expand All @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
12 changes: 1 addition & 11 deletions cmake/rust-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 0 additions & 2 deletions libcc2rs/rust-toolchain.toml

This file was deleted.

3 changes: 0 additions & 3 deletions rule-preprocessor/rust-toolchain.toml

This file was deleted.

2 changes: 0 additions & 2 deletions rules/rust-toolchain.toml

This file was deleted.

16 changes: 8 additions & 8 deletions tests/lit/lit/formats/Cpp2RustTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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}"
Expand All @@ -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:
Expand Down
Loading