Skip to content

Commit cb9e5b0

Browse files
committed
Merge branch 'master' into 6-escape-rust-keywords
2 parents a46748a + cd937fa commit cb9e5b0

267 files changed

Lines changed: 5184 additions & 1447 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CMakeLists.txt‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,17 @@ add_custom_command(
219219
)
220220

221221
file(GLOB rule_subdirs CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/rules/*)
222+
file(GLOB rule_common_headers CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/rules/common/*.h)
223+
file(GLOB rule_indexer_sources CONFIGURE_DEPENDS
224+
${PROJECT_SOURCE_DIR}/cpp2rust/rule_preprocessing/*
225+
${PROJECT_SOURCE_DIR}/cpp2rust/converter/rules/rules_loader.*)
226+
set(_common_headers)
227+
foreach(_header IN LISTS rule_common_headers)
228+
list(APPEND _common_headers --common-header=${_header})
229+
endforeach()
222230
set(cpp_rules_ir_outputs)
231+
set(cpp_rules_index_inputs)
232+
set(cpp_rules_index_outputs ${CMAKE_BINARY_DIR}/rules_index/c.json ${CMAKE_BINARY_DIR}/rules_index/cpp.json)
223233
set(rust_rules_ir_outputs)
224234
foreach(_rule_dir IN LISTS rule_subdirs)
225235
file(GLOB _cpp_srcs ${_rule_dir}/src.c ${_rule_dir}/src.cpp)
@@ -229,7 +239,7 @@ foreach(_rule_dir IN LISTS rule_subdirs)
229239
get_filename_component(_rule_name ${_rule_dir} NAME)
230240
set(_out_dir ${RULES_IR_DIR}/${_rule_name})
231241
set(_cpp_out ${_out_dir}/ir_src.json)
232-
set(_cxxflags --cxxflags=-isystem${_rule_dir})
242+
set(_cxxflags)
233243
set(_cxxflags_file)
234244
if(EXISTS ${_rule_dir}/cxxflags)
235245
set(_cxxflags_file ${_rule_dir}/cxxflags)
@@ -242,11 +252,15 @@ foreach(_rule_dir IN LISTS rule_subdirs)
242252
OUTPUT ${_cpp_out}
243253
COMMAND ${CMAKE_COMMAND} -E make_directory ${_out_dir}
244254
COMMAND $<TARGET_FILE:cpp-rule-preprocessor> --dir ${_rule_dir} --out ${_cpp_out} ${_cxxflags}
245-
DEPENDS ${_cpp_srcs} ${_cxxflags_file} ${PROJECT_SOURCE_DIR}/cpp2rust/cpp_rule_preprocessor.cpp ${RUSTLS_HEADER} ${BROTLI_HEADERS}
255+
DEPENDS ${_cpp_srcs} ${_cxxflags_file} ${rule_common_headers} ${PROJECT_SOURCE_DIR}/cpp2rust/rule_preprocessing/cpp_rule_preprocessor.cpp ${RUSTLS_HEADER} ${BROTLI_HEADERS}
246256
VERBATIM
247257
)
248258
list(APPEND cpp_rules_ir_outputs ${_cpp_out})
249259

260+
if(NOT _rule_name STREQUAL "builtin_types")
261+
list(APPEND cpp_rules_index_inputs ${_cpp_srcs} ${_cxxflags_file})
262+
endif()
263+
250264
set(_rust_srcs)
251265
set(_rust_out)
252266
if(EXISTS ${_rule_dir}/tgt_unsafe.rs)
@@ -277,6 +291,15 @@ endforeach()
277291

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

294+
add_custom_command(
295+
OUTPUT ${cpp_rules_index_outputs}
296+
COMMAND $<TARGET_FILE:cpp-rule-indexer> --exclude builtin_types ${_common_headers}
297+
DEPENDS ${cpp_rules_index_inputs} ${rule_common_headers} ${rule_indexer_sources} ${RUSTLS_HEADER} ${BROTLI_HEADERS}
298+
VERBATIM
299+
)
300+
301+
add_custom_target("index-cpp-rules" ALL DEPENDS ${cpp_rules_index_outputs})
302+
280303
add_custom_target("preprocess-rust-rules" ALL
281304
DEPENDS ${rust_rules_ir_outputs})
282305

‎cpp2rust/CMakeLists.txt‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
file(GLOB_RECURSE CORE_SOURCES "*.cpp")
2+
file(GLOB RULE_PREPROCESSING_SOURCES "rule_preprocessing/*.cpp")
23
list(REMOVE_ITEM CORE_SOURCES
34
"${CMAKE_CURRENT_SOURCE_DIR}/cpp2rust.cpp"
4-
"${CMAKE_CURRENT_SOURCE_DIR}/cpp_rule_preprocessor.cpp"
5+
${RULE_PREPROCESSING_SOURCES}
56
)
67

78
add_library(cpp2rust_core STATIC ${CORE_SOURCES})
@@ -17,6 +18,8 @@ target_compile_definitions(cpp2rust_core PUBLIC "-DCLANG_C_COMPILER=\"${CMAKE_C_
1718
target_compile_definitions(cpp2rust_core PUBLIC "-DCLANG_CXX_COMPILER=\"${CMAKE_CXX_COMPILER}\"")
1819
target_compile_definitions(cpp2rust_core PUBLIC "-DCLANG_RESOURCE_DIR=\"${LLVM_LIBRARY_DIR}/clang/${LLVM_VERSION_MAJOR}\"")
1920
target_compile_definitions(cpp2rust_core PUBLIC "-DCOMPAT_INCLUDE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/compat\"")
21+
target_compile_definitions(cpp2rust_core PUBLIC "-DRULES_SRC_DIR=\"${PROJECT_SOURCE_DIR}/rules\"")
22+
target_compile_definitions(cpp2rust_core PUBLIC "-DRULES_INDEX_DIR=\"${CMAKE_BINARY_DIR}/rules_index\"")
2023
target_compile_definitions(cpp2rust_core PUBLIC "-DRUST_STABLE_VERSION=\"${RUST_STABLE_VERSION}\"")
2124

2225
if (APPLE)
@@ -34,5 +37,10 @@ target_link_libraries(cpp2rust_core PUBLIC ${llvm_libs})
3437
add_clang_executable(cpp2rust PARTIAL_SOURCES_INTENDED cpp2rust.cpp)
3538
target_link_libraries(cpp2rust PRIVATE cpp2rust_core)
3639

37-
add_clang_executable(cpp-rule-preprocessor PARTIAL_SOURCES_INTENDED cpp_rule_preprocessor.cpp)
40+
add_clang_executable(cpp-rule-preprocessor PARTIAL_SOURCES_INTENDED
41+
rule_preprocessing/cpp_rule_preprocessor.cpp)
3842
target_link_libraries(cpp-rule-preprocessor PRIVATE cpp2rust_core)
43+
44+
add_clang_executable(cpp-rule-indexer PARTIAL_SOURCES_INTENDED
45+
rule_preprocessing/cpp_rule_indexer.cpp)
46+
target_link_libraries(cpp-rule-indexer PRIVATE cpp2rust_core)

‎cpp2rust/ast_consumer.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33

44
#include "ast_consumer.h"
55

6+
#include <llvm/Support/ErrorHandling.h>
7+
68
#include "converter/converter.h"
79

810
namespace cpp2rust {
911
void ASTConsumer::HandleTranslationUnit(clang::ASTContext &ctx) {
12+
if (CI_.getDiagnostics().hasErrorOccurred()) {
13+
llvm::report_fatal_error(
14+
"the translation unit and its loaded rules do not compile");
15+
}
1016
auto converter = CreateConverter(rs_code_, ctx, model_, rules_dir_);
1117
converter->SetSema(CI_.getSema());
1218
if (first_) {

0 commit comments

Comments
 (0)