Skip to content

Commit bdc7c3f

Browse files
committed
cmake: fix rust toolchain dependency
1 parent 29c6b16 commit bdc7c3f

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,16 @@ foreach(_dir libcc2rs rules)
7070
write_rust_toolchain(${CMAKE_SOURCE_DIR}/${_dir})
7171
endforeach()
7272

73-
add_custom_target("install-rust-toolchain"
74-
COMMAND rustup toolchain install ${RUST_STABLE_VERSION}
75-
USES_TERMINAL
76-
)
73+
set(RUST_STAMP_FILE "${CMAKE_BINARY_DIR}/.rust-toolchain.stamp")
74+
75+
add_custom_command(
76+
OUTPUT "${RUST_STAMP_FILE}"
77+
COMMAND rustup toolchain install ${RUST_STABLE_VERSION}
78+
COMMAND ${CMAKE_COMMAND} -E touch "${RUST_STAMP_FILE}"
79+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/rust-toolchain.cmake"
80+
USES_TERMINAL
81+
VERBATIM
82+
)
7783

7884
add_subdirectory(cpp2rust)
7985
add_subdirectory(libcc2rs)
@@ -90,7 +96,7 @@ add_custom_target("format"
9096
COMMAND rustup run ${RUST_STABLE_VERSION} cargo fmt --manifest-path ${PROJECT_SOURCE_DIR}/rule-preprocessor/Cargo.toml
9197
COMMAND rustup run ${RUST_STABLE_VERSION} cargo fmt --manifest-path ${PROJECT_SOURCE_DIR}/libcc2rs/Cargo.toml
9298
COMMAND rustup run ${RUST_STABLE_VERSION} cargo fmt --manifest-path ${PROJECT_SOURCE_DIR}/libcc2rs-macros/Cargo.toml
93-
DEPENDS "install-rust-toolchain"
99+
DEPENDS "${RUST_STAMP_FILE}"
94100
COMMENT "Running clang-format and cargo fmt on all source files"
95101
VERBATIM
96102
)
@@ -102,7 +108,7 @@ endif()
102108
add_custom_target("check-libcc2rs"
103109
COMMAND cargo test
104110
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/libcc2rs"
105-
DEPENDS install-rust-toolchain
111+
DEPENDS "${RUST_STAMP_FILE}"
106112
USES_TERMINAL
107113
)
108114

@@ -172,12 +178,12 @@ add_custom_command(
172178
CARGO_TARGET_DIR=${PROJECT_SOURCE_DIR}/rule-preprocessor/target
173179
cargo run
174180
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/rules"
175-
DEPENDS ${rust_rules_inputs} ${rule_preprocessor_sources}
181+
DEPENDS ${rust_rules_inputs} ${rule_preprocessor_sources} "${RUST_STAMP_FILE}"
176182
VERBATIM
177183
)
178184

179185
add_custom_target("preprocess-rust-rules" ALL
180-
DEPENDS ${rust_rules_ir_outputs} install-rust-toolchain)
186+
DEPENDS ${rust_rules_ir_outputs})
181187

182188
add_custom_target("check-rules"
183189
COMMAND find ${PROJECT_SOURCE_DIR}/rules -name "ir_unsafe.json" -delete

libcc2rs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ add_custom_command(
1717
)
1818

1919
add_custom_target(libcc2rs ALL
20-
DEPENDS ${RUST_BUILD_DIR}/release/liblibcc2rs.rlib install-rust-toolchain
20+
DEPENDS ${RUST_BUILD_DIR}/release/liblibcc2rs.rlib "${RUST_STAMP_FILE}"
2121
)

0 commit comments

Comments
 (0)