Skip to content

Commit d8e9a04

Browse files
committed
add CODE_GENERATOR option for cxx-build
This sets the GENERATED_HEADER_DIR environment variable when calling cargo and adds that path to the target's include paths. Cargo build scripts can read this to determine where to output generated C/C++ headers. Depends on dtolnay/cxx#1120 for cxx-build Fixes corrosion-rs#204
1 parent 23603e8 commit d8e9a04

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ corrosion_import_crate(MANIFEST_PATH <path/to/cargo.toml>
192192
[NO_DEFAULT_FEATURES]
193193
# Disable linking of standard libraries (required for no_std crates).
194194
[NO_STD]
195+
# Add headers generated by cxx-build or cxx-qt-build to include paths
196+
[CODE_GENERATOR]
195197
# Specify cargo build profile (e.g. release or a custom profile)
196198
[PROFILE <cargo-profile>]
197199
# Only import the specified crates from a workspace

cmake/Corrosion.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,11 @@ function(_add_cargo_build out_cargo_build_out_dir)
821821
if(COR_NO_STD)
822822
set(no_default_libraries_arg --no-default-libraries)
823823
endif()
824+
if(COR_CODE_GENERATOR)
825+
set(generated_header_dir "${CMAKE_CURRENT_BINARY_DIR}/generated-code")
826+
target_include_directories("${target_name}" INTERFACE "${generated_header_dir}")
827+
set(generated_header_dir_env "GENERATED_HEADER_DIR=${generated_header_dir}")
828+
endif()
824829

825830
set(global_rustflags_target_property "$<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_RUSTFLAGS>>")
826831
set(local_rustflags_target_property "$<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_LOCAL_RUSTFLAGS>>")
@@ -954,6 +959,7 @@ function(_add_cargo_build out_cargo_build_out_dir)
954959
"${cargo_target_linker}"
955960
"${corrosion_cc_rs_flags}"
956961
"${cargo_library_path}"
962+
"${generated_header_dir_env}"
957963
"CORROSION_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}"
958964
"CARGO_BUILD_RUSTC=${_CORROSION_RUSTC}"
959965
"${_CORROSION_CARGO}"
@@ -1026,7 +1032,7 @@ function(_add_cargo_build out_cargo_build_out_dir)
10261032
endfunction()
10271033

10281034
function(corrosion_import_crate)
1029-
set(OPTIONS ALL_FEATURES NO_DEFAULT_FEATURES NO_STD)
1035+
set(OPTIONS ALL_FEATURES NO_DEFAULT_FEATURES NO_STD CODE_GENERATOR)
10301036
set(ONE_VALUE_KEYWORDS MANIFEST_PATH PROFILE)
10311037
set(MULTI_VALUE_KEYWORDS CRATES FEATURES FLAGS)
10321038
cmake_parse_arguments(COR "${OPTIONS}" "${ONE_VALUE_KEYWORDS}" "${MULTI_VALUE_KEYWORDS}" ${ARGN})

0 commit comments

Comments
 (0)