@@ -230,8 +230,8 @@ set(CPP2RUST_CXX_STANDARDS 11 17 20 23)
230230set (c_rules_index_parts)
231231set (cpp_rules_index_parts)
232232set (rules_index_parts_dir ${CMAKE_BINARY_DIR } /rules_index/parts)
233- set (rust_rules_srcs )
234- set (rust_rules_index_outputs ${ CMAKE_BINARY_DIR } /rules_index/index_unsafe.json ${ CMAKE_BINARY_DIR } /rules_index/index_refcount.json )
233+ set (RULES_IR_DIR " ${ CMAKE_BINARY_DIR } /rules" )
234+ set (rust_rules_ir_outputs )
235235foreach (_rule_dir IN LISTS rule_subdirs)
236236 file (GLOB _cpp_srcs ${_rule_dir} /src.c ${_rule_dir} /src.cpp )
237237 if (NOT _cpp_srcs)
@@ -261,25 +261,35 @@ foreach(_rule_dir IN LISTS rule_subdirs)
261261 list (APPEND cpp_rules_index_parts ${_part} )
262262 endforeach ()
263263
264- foreach (_model IN ITEMS unsafe refcount)
265- if (EXISTS ${_rule_dir} /tgt_${_model} .rs)
266- list (APPEND rust_rules_srcs ${_rule_dir} /tgt_${_model} .rs)
267- endif ()
268- endforeach ()
264+ set (_out_dir ${RULES_IR_DIR} /${_rule_name} )
265+ set (_rust_srcs)
266+ set (_rust_out)
267+ if (EXISTS ${_rule_dir} /tgt_unsafe.rs)
268+ list (APPEND _rust_out ${_out_dir} /ir_unsafe.json)
269+ list (APPEND _rust_srcs ${_rule_dir} /tgt_unsafe.rs)
270+ endif ()
271+ if (EXISTS ${_rule_dir} /tgt_refcount.rs)
272+ list (APPEND _rust_out ${_out_dir} /ir_refcount.json)
273+ list (APPEND _rust_srcs ${_rule_dir} /tgt_refcount.rs)
274+ endif ()
275+ if (NOT _rust_srcs)
276+ continue ()
277+ endif ()
278+ add_custom_command (
279+ OUTPUT ${_rust_out}
280+ COMMAND ${CMAKE_COMMAND } -E make_directory ${_out_dir}
281+ COMMAND ${CARGO_ENV_RULE_PREPROCESSOR}
282+ RULE_PREPROCESSOR_ARTIFACTS=${PREPROCESSOR_ARTIFACTS}
283+ RUSTUP_TOOLCHAIN=${RUST_NIGHTLY_VERSION}
284+ LD_LIBRARY_PATH=${NIGHTLY_SYSROOT}/lib
285+ DYLD_LIBRARY_PATH=${NIGHTLY_SYSROOT}/lib
286+ ${PREPROCESSOR_BIN} ${_out_dir} ${_rule_dir}
287+ DEPENDS ${_rust_srcs} ${PREPROCESSOR_BIN} ${PREPROCESSOR_ARTIFACTS} ${RULES_LIB}
288+ VERBATIM
289+ )
290+ list (APPEND rust_rules_ir_outputs ${_rust_out} )
269291endforeach ()
270292
271- add_custom_command (
272- OUTPUT ${rust_rules_index_outputs}
273- COMMAND ${CARGO_ENV_RULE_PREPROCESSOR}
274- RULE_PREPROCESSOR_ARTIFACTS=${PREPROCESSOR_ARTIFACTS}
275- RUSTUP_TOOLCHAIN=${RUST_NIGHTLY_VERSION}
276- LD_LIBRARY_PATH=${NIGHTLY_SYSROOT}/lib
277- DYLD_LIBRARY_PATH=${NIGHTLY_SYSROOT}/lib
278- ${PREPROCESSOR_BIN} ${CMAKE_BINARY_DIR } /rules_index ${PROJECT_SOURCE_DIR } /rules
279- DEPENDS ${rust_rules_srcs} ${PREPROCESSOR_BIN} ${PREPROCESSOR_ARTIFACTS} ${RULES_LIB}
280- VERBATIM
281- )
282-
283293add_custom_command (
284294 OUTPUT ${CMAKE_BINARY_DIR } /rules_index/c.json
285295 COMMAND $<TARGET_FILE :cpp -rule -indexer > -o ${CMAKE_BINARY_DIR } /rules_index/c.json ${c_rules_index_parts}
@@ -296,8 +306,16 @@ add_custom_command(
296306
297307add_custom_target ("index-cpp-rules" ALL DEPENDS ${CMAKE_BINARY_DIR } /rules_index/c.json ${CMAKE_BINARY_DIR } /rules_index/cpp.json )
298308
309+ set (rust_rules_index_outputs ${CMAKE_BINARY_DIR } /rules_index/index_unsafe.json ${CMAKE_BINARY_DIR } /rules_index/index_refcount.json)
310+ add_custom_command (
311+ OUTPUT ${rust_rules_index_outputs}
312+ COMMAND ${PREPROCESSOR_BIN} --merge ${CMAKE_BINARY_DIR } /rules_index ${RULES_IR_DIR}
313+ DEPENDS ${rust_rules_ir_outputs} ${PREPROCESSOR_BIN}
314+ VERBATIM
315+ )
316+
299317add_custom_target ("preprocess-rust-rules" ALL
300- DEPENDS ${rust_rules_index_outputs} )
318+ DEPENDS ${rust_rules_ir_outputs} ${ rust_rules_index_outputs} )
301319
302320set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES
303321 "${CMAKE_BINARY_DIR } /libcc2rs-target"
0 commit comments