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
8 changes: 4 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ jobs:
run: ninja
working-directory: build

- name: Run unit tests
run: ninja check
working-directory: build

- name: Check rules
run: ninja check-rules
working-directory: build

- name: Run unit tests
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change is weird. ninja should regen the files.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I will make the change to regen the files on ninja

However, I think it's better to run check-rules before unit tests because it's cheaper and catches the rules errors early

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we run preprocess-{rust,cpp}-rules in ALL, check-rules does not need to delete then re-run preprocess-{rust,cpp}-rules, it can only do git diff

run: ninja check
working-directory: build

- name: Check benchmarks (don't run)
run: ninja check-benchmarks
working-directory: build
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ tmp
*.LOCAL.*
*.REMOTE.*

# Integration tests
tests/cpp2rust-tests/
# Generated by cpp-rule-preprocessor at build time.
rules/*/ir_src.json
57 changes: 48 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,57 @@ add_custom_target("check"
DEPENDS check-libcc2rs check-unit
)

file(GLOB rule_src_files ${PROJECT_SOURCE_DIR}/rules/*/src.cpp)
set(cpp_rules_ir_outputs)
set(rust_rules_ir_outputs)
set(rust_rules_inputs)
foreach(_src IN LISTS rule_src_files)
get_filename_component(_rule_dir ${_src} DIRECTORY)
set(_out ${_rule_dir}/ir_src.json)
add_custom_command(
OUTPUT ${_out}
COMMAND $<TARGET_FILE:cpp-rule-preprocessor> --file ${_src}
DEPENDS ${_src} cpp-rule-preprocessor
VERBATIM
)
list(APPEND cpp_rules_ir_outputs ${_out})
if(EXISTS ${_rule_dir}/tgt_unsafe.rs)
list(APPEND rust_rules_ir_outputs ${_rule_dir}/ir_unsafe.json)
list(APPEND rust_rules_inputs ${_rule_dir}/tgt_unsafe.rs)
endif()
if(EXISTS ${_rule_dir}/tgt_refcount.rs)
list(APPEND rust_rules_ir_outputs ${_rule_dir}/ir_refcount.json)
list(APPEND rust_rules_inputs ${_rule_dir}/tgt_refcount.rs)
endif()
endforeach()

add_custom_target("preprocess-cpp-rules" ALL DEPENDS ${cpp_rules_ir_outputs})

file(GLOB_RECURSE rule_preprocessor_sources
${PROJECT_SOURCE_DIR}/rule-preprocessor/src/*.rs)

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"
DEPENDS ${rust_rules_inputs} ${rule_preprocessor_sources}
VERBATIM
)

add_custom_target("preprocess-rust-rules" ALL
DEPENDS ${rust_rules_ir_outputs} install-rust-toolchain)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't seem like it needs the rust toolchain here.


add_custom_target("check-rules"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move the delete here and call preprocess & then diff.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. check-rules now contains deltee + call preprocess rust/cpp + diff

COMMAND find ${PROJECT_SOURCE_DIR}/rules -name "ir*.json" -delete
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
COMMAND find ${PROJECT_SOURCE_DIR}/rules -name "ir_unsafe.json" -delete
COMMAND find ${PROJECT_SOURCE_DIR}/rules -name "ir_refcount.json" -delete
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target preprocess-cpp-rules
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target preprocess-rust-rules
COMMAND ${CMAKE_COMMAND} -E chdir ${PROJECT_SOURCE_DIR}
git diff --exit-code -- rules/
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/rules"
DEPENDS install-rust-toolchain
USES_TERMINAL
)

add_custom_target("check-all"
Expand Down
35 changes: 23 additions & 12 deletions cpp2rust/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
file(GLOB_RECURSE SOURCES "*.cpp")
add_clang_executable(cpp2rust ${SOURCES})
file(GLOB_RECURSE CORE_SOURCES "*.cpp")
list(REMOVE_ITEM CORE_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/cpp2rust.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/cpp_rule_preprocessor.cpp"
)

add_library(cpp2rust_core STATIC ${CORE_SOURCES})

target_link_libraries(cpp2rust PRIVATE
target_link_libraries(cpp2rust_core PUBLIC
clangAST
clangASTMatchers
clangBasic
Expand All @@ -10,22 +15,28 @@ target_link_libraries(cpp2rust PRIVATE
clangSerialization
clangTooling
)
target_include_directories(cpp2rust PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(cpp2rust PUBLIC SYSTEM ${CLANG_INCLUDE_DIRS} ${LLVM_INCLUDE_DIRS})
target_compile_definitions(cpp2rust PUBLIC ${LLVM_DEFINITIONS})
target_compile_definitions(cpp2rust PUBLIC "-DCLANG_C_COMPILER=\"${CMAKE_C_COMPILER}\"")
target_compile_definitions(cpp2rust PUBLIC "-DCLANG_CXX_COMPILER=\"${CMAKE_CXX_COMPILER}\"")
target_compile_definitions(cpp2rust PUBLIC "-DCLANG_RESOURCE_DIR=\"${LLVM_LIBRARY_DIR}/clang/${LLVM_VERSION_MAJOR}\"")
target_compile_definitions(cpp2rust PUBLIC "-DCOMPAT_INCLUDE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/compat\"")
target_include_directories(cpp2rust_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(cpp2rust_core SYSTEM PUBLIC ${CLANG_INCLUDE_DIRS} ${LLVM_INCLUDE_DIRS})
target_compile_definitions(cpp2rust_core PUBLIC ${LLVM_DEFINITIONS})
target_compile_definitions(cpp2rust_core PUBLIC "-DCLANG_C_COMPILER=\"${CMAKE_C_COMPILER}\"")
target_compile_definitions(cpp2rust_core PUBLIC "-DCLANG_CXX_COMPILER=\"${CMAKE_CXX_COMPILER}\"")
target_compile_definitions(cpp2rust_core PUBLIC "-DCLANG_RESOURCE_DIR=\"${LLVM_LIBRARY_DIR}/clang/${LLVM_VERSION_MAJOR}\"")
target_compile_definitions(cpp2rust_core PUBLIC "-DCOMPAT_INCLUDE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/compat\"")

if (APPLE)
execute_process(
COMMAND xcrun --show-sdk-path
OUTPUT_VARIABLE MACOS_SDK_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
target_compile_definitions(cpp2rust PUBLIC "-DMACOS_SDK_PATH=\"${MACOS_SDK_PATH}\"")
target_compile_definitions(cpp2rust_core PUBLIC "-DMACOS_SDK_PATH=\"${MACOS_SDK_PATH}\"")
endif()

llvm_map_components_to_libnames(llvm_libs support)
target_link_libraries(cpp2rust PRIVATE ${llvm_libs})
target_link_libraries(cpp2rust_core PUBLIC ${llvm_libs})

add_clang_executable(cpp2rust PARTIAL_SOURCES_INTENDED cpp2rust.cpp)
target_link_libraries(cpp2rust PRIVATE cpp2rust_core)

add_clang_executable(cpp-rule-preprocessor PARTIAL_SOURCES_INTENDED cpp_rule_preprocessor.cpp)
target_link_libraries(cpp-rule-preprocessor PRIVATE cpp2rust_core)
Loading
Loading