Skip to content

Commit

Permalink
cbindgen: Allow generating multiple files on one Rust target
Browse files Browse the repository at this point in the history
User may want to generate both a C and a separate C++ header file
  • Loading branch information
jschwe committed Apr 23, 2024
1 parent f6178e6 commit fdd9f27
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cmake/Corrosion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1681,11 +1681,19 @@ function(corrosion_experimental_cbindgen)
)
endif()

add_custom_target(_corrosion_cbindgen_${rust_target}_bindings
DEPENDS "${generated_header}"
COMMENT "Generate cbindgen bindings for package ${rust_cargo_package}"
if(NOT TARGET "_corrosion_cbindgen_${rust_target}_bindings")
add_custom_target(_corrosion_cbindgen_${rust_target}_bindings
COMMENT "Generate cbindgen bindings for package ${rust_cargo_package}"
)
endif()
# Users might want to call cbindgen multiple times, e.g. to generate separate C++ and C header files.
string(MAKE_C_IDENTIFIER "${generated_header}" header_identifier )
add_custom_target("_corrosion_cbindgen_${rust_target}_bindings_${header_identifier}"
DEPENDS "${generated_header}"
COMMENT "Generate ${generated_header} for ${rust_target}"
)
add_dependencies(${rust_target} _corrosion_cbindgen_${rust_target}_bindings)
add_dependencies("_corrosion_cbindgen_${rust_target}_bindings" "_corrosion_cbindgen_${rust_target}_bindings_${header_identifier}")
add_dependencies(${rust_target} "_corrosion_cbindgen_${rust_target}_bindings")
endfunction()

# Parse the version of a Rust package from it's package manifest (Cargo.toml)
Expand Down

0 comments on commit fdd9f27

Please sign in to comment.