Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions cmake/Corrosion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -325,20 +325,20 @@ function(_corrosion_copy_byproduct_deferred target_name output_dir_prop_names ca
list(TRANSFORM src_file_names PREPEND "${cargo_build_dir}/")
list(TRANSFORM file_names PREPEND "${output_dir}/" OUTPUT_VARIABLE dst_file_names)
message(DEBUG "Adding command to copy byproducts `${file_names}` to ${dst_file_names}")
add_custom_command(TARGET _cargo-build_${target_name}
POST_BUILD
# output_dir may contain a Generator expression.
add_custom_command(
DEPENDS ${src_file_names}
OUTPUT ${dst_file_names}
COMMAND ${CMAKE_COMMAND} -E make_directory "${output_dir}"
COMMAND
${CMAKE_COMMAND} -E copy_if_different
# tested to work with both multiple files and paths with spaces
${src_file_names}
"${output_dir}"
BYPRODUCTS ${dst_file_names}
COMMENT "Copying byproducts `${file_names}` to ${output_dir}"
VERBATIM
COMMAND_EXPAND_LISTS
)
target_sources(cargo-build_${target_name} PRIVATE ${dst_file_names})
endfunction()

# Copy the artifacts generated by cargo to the appropriate destination.
Expand Down Expand Up @@ -701,10 +701,11 @@ function(_add_cargo_build out_cargo_build_out_dir)
set(no_default_features_arg "$<$<BOOL:${no_default_features_target_property}>:--no-default-features>")

set(build_env_variable_genex "$<GENEX_EVAL:$<TARGET_PROPERTY:${target_name},${_CORR_PROP_ENV_VARS}>>")
set(hostbuild_override "$<BOOL:$<TARGET_PROPERTY:${target_name},${_CORR_PROP_HOST_BUILD}>>")
# set(hostbuild_override "$<BOOL:$<TARGET_PROPERTY:${target_name},${_CORR_PROP_HOST_BUILD}>>")
set(hostbuild_override "0")
set(if_not_host_build_condition "$<NOT:${hostbuild_override}>")

set(corrosion_link_args "$<${if_not_host_build_condition}:${corrosion_link_args}>")
# set(corrosion_link_args "$<${if_not_host_build_condition}:${corrosion_link_args}>")
# We always set `--target`, so that cargo always places artifacts into a directory with the
# target triple.
set(cargo_target_option "--target=$<IF:${hostbuild_override},${_CORROSION_RUST_CARGO_HOST_TARGET},${_CORROSION_RUST_CARGO_TARGET}>")
Expand All @@ -719,7 +720,7 @@ function(_add_cargo_build out_cargo_build_out_dir)
set(explicit_linker_property "$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_LINKER>")
set(explicit_linker_defined "$<BOOL:${explicit_linker_property}>")

set(cargo_profile_target_property "$<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_CARGO_PROFILE>>")
# set(cargo_profile_target_property "$<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_CARGO_PROFILE>>")

# Option to override the rustc/cargo binary to something other than the global default
set(rustc_override "$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_RUSTC>")
Expand All @@ -743,7 +744,8 @@ function(_add_cargo_build out_cargo_build_out_dir)
endif()
endif()

set(cargo_profile_set "$<BOOL:${cargo_profile_target_property}>")
# set(cargo_profile_set "$<BOOL:${cargo_profile_target_property}>")
set(cargo_profile_set "0")
# In the default case just specify --release or nothing to stay compatible with
# older rust versions.
set(default_profile_option "$<$<NOT:$<OR:$<CONFIG:Debug>,$<CONFIG:>>>:--release>")
Expand Down Expand Up @@ -874,9 +876,10 @@ function(_add_cargo_build out_cargo_build_out_dir)
message(DEBUG "TARGET ${target_name} produces byproducts ${build_byproducts}")
message(DEBUG "corrosion_cc_rs_flags: ${corrosion_cc_rs_flags}")

add_custom_target(
_cargo-build_${target_name}
# Build crate
# message(FATAL_ERROR by="${cargo_build_dir}/${build_byproducts}")
add_custom_command(
OUTPUT "${cargo_build_dir}/${build_byproducts}"
DEPFILE "${cargo_build_dir}/${build_byproducts}.d"
COMMAND
${CMAKE_COMMAND} -E env
"${build_env_variable_genex}"
Expand Down Expand Up @@ -904,13 +907,6 @@ function(_add_cargo_build out_cargo_build_out_dir)
# Any arguments to cargo must be placed before this line
${local_rustflags_delimiter}
${local_rustflags_genex}

# Note: `BYPRODUCTS` may not contain **target specific** generator expressions.
# This means we cannot use `${cargo_build_dir}`, since it currently uses `$<TARGET_PROPERTY>`
# to determine the correct target directory, depending on if the hostbuild target property is
# set or not.
# BYPRODUCTS "${cargo_build_dir}/${build_byproducts}"

# Set WORKING_DIRECTORY to the directory containing the manifest, so that configuration files
# such as `.cargo/config.toml` or `toolchain.toml` are applied as expected. Cargo searches for
# configuration files by walking upward from the current directory.
Expand All @@ -920,6 +916,11 @@ function(_add_cargo_build out_cargo_build_out_dir)
VERBATIM
)

add_custom_target(
_cargo-build_${target_name}
DEPENDS "${cargo_build_dir}/${build_byproducts}"
)

# User exposed custom target, that depends on the internal target.
# Corrosion post build steps are added on the internal target, which
# ensures that they run before any user defined post build steps on this
Expand Down
Loading