Skip to content

Commit 8eb3f89

Browse files
committed
Generate ir files in build/rules
1 parent ca07e63 commit 8eb3f89

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ add_custom_target("check"
151151
DEPENDS check-libcc2rs check-unit
152152
)
153153

154+
set(RULES_IR_DIR "${CMAKE_BINARY_DIR}/rules")
155+
154156
file(GLOB rule_subdirs ${PROJECT_SOURCE_DIR}/rules/*)
155157
set(cpp_rules_ir_outputs)
156158
set(rust_rules_ir_outputs)
@@ -160,20 +162,23 @@ foreach(_rule_dir IN LISTS rule_subdirs)
160162
if(NOT _srcs)
161163
continue()
162164
endif()
163-
set(_out ${_rule_dir}/ir_src.json)
165+
get_filename_component(_rule_name ${_rule_dir} NAME)
166+
set(_out_dir ${RULES_IR_DIR}/${_rule_name})
167+
set(_out ${_out_dir}/ir_src.json)
164168
add_custom_command(
165169
OUTPUT ${_out}
166-
COMMAND $<TARGET_FILE:cpp-rule-preprocessor> --dir ${_rule_dir}
170+
COMMAND ${CMAKE_COMMAND} -E make_directory ${_out_dir}
171+
COMMAND $<TARGET_FILE:cpp-rule-preprocessor> --dir ${_rule_dir} --out ${_out}
167172
DEPENDS ${_srcs} ${PROJECT_SOURCE_DIR}/cpp2rust/cpp_rule_preprocessor.cpp
168173
VERBATIM
169174
)
170175
list(APPEND cpp_rules_ir_outputs ${_out})
171176
if(EXISTS ${_rule_dir}/tgt_unsafe.rs)
172-
list(APPEND rust_rules_ir_outputs ${_rule_dir}/ir_unsafe.json)
177+
list(APPEND rust_rules_ir_outputs ${_out_dir}/ir_unsafe.json)
173178
list(APPEND rust_rules_inputs ${_rule_dir}/tgt_unsafe.rs)
174179
endif()
175180
if(EXISTS ${_rule_dir}/tgt_refcount.rs)
176-
list(APPEND rust_rules_ir_outputs ${_rule_dir}/ir_refcount.json)
181+
list(APPEND rust_rules_ir_outputs ${_out_dir}/ir_refcount.json)
177182
list(APPEND rust_rules_inputs ${_rule_dir}/tgt_refcount.rs)
178183
endif()
179184
endforeach()
@@ -189,6 +194,7 @@ add_custom_command(
189194
COMMAND ${CMAKE_COMMAND} -E env
190195
CARGO_TARGET_DIR=${CMAKE_BINARY_DIR}/target_preprocessor
191196
cargo +${RUST_NIGHTLY_VERSION} run --release --manifest-path "${PROJECT_SOURCE_DIR}/rule-preprocessor/Cargo.toml"
197+
-- "${RULES_IR_DIR}"
192198
DEPENDS ${rust_rules_inputs} ${rule_preprocessor_sources} "${RUST_STAMP_FILE}"
193199
VERBATIM
194200
)
@@ -197,10 +203,9 @@ add_custom_target("preprocess-rust-rules" ALL
197203
DEPENDS ${rust_rules_ir_outputs})
198204

199205
add_custom_target("check-rules"
200-
COMMAND find rules "\\(" -name ir_unsafe.json -o -name ir_refcount.json -o -name ir_src.json "\\)" -delete
206+
COMMAND ${CMAKE_COMMAND} -E rm -rf "${RULES_IR_DIR}"
201207
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target preprocess-cpp-rules
202208
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target preprocess-rust-rules
203-
COMMAND git diff --exit-code -- rules/
204209
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
205210
)
206211

0 commit comments

Comments
 (0)