Skip to content

Commit

Permalink
Use local_rustflags where appropriate
Browse files Browse the repository at this point in the history
Using local rustflags passed via `cargo rustc` has the advantage,
that they are not set for dependencies.
This is mostly benenficial in workspaces, where different crates link
different C dependencies, but share common rust dependencies.
If the RUSTFLAGS environment variable is used this will cause rebuilds
of the common rust dependencies, since the RUSTFLAGS  differ.
When passing rustflags via cargo rustc, this does not happen, since they
only affects the main crate.
  • Loading branch information
jschwe committed Sep 7, 2022
1 parent 7d535ab commit c05235f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cmake/Corrosion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,13 @@ function(_add_cargo_build)
list(APPEND corrosion_cc_rs_flags "SDKROOT=${CMAKE_OSX_SYSROOT}")
endif()

corrosion_add_target_rustflags("${target_name}" "$<$<BOOL:${corrosion_link_args}>:-Clink-args=${corrosion_link_args}>")
corrosion_add_target_local_rustflags("${target_name}" "$<$<BOOL:${corrosion_link_args}>:-Clink-args=${corrosion_link_args}>")

# todo: this should probably also be guarded by if_not_host_build_condition.
if(COR_NO_STD)
corrosion_add_target_rustflags("${target_name}" "-Cdefault-linker-libraries=no")
corrosion_add_target_local_rustflags("${target_name}" "-Cdefault-linker-libraries=no")
else()
corrosion_add_target_rustflags("${target_name}" "-Cdefault-linker-libraries=yes")
corrosion_add_target_local_rustflags("${target_name}" "-Cdefault-linker-libraries=yes")
endif()

set(global_joined_rustflags "$<JOIN:${global_rustflags_target_property}, >")
Expand All @@ -379,7 +379,7 @@ function(_add_cargo_build)
# Skip adding the linker argument, if the linker is explicitly set, since the
# explicit_linker_property will not be set when this function runs.
# Passing this rustflag is necessary for clang.
corrosion_add_target_rustflags("${target_name}" "$<$<NOT:$<BOOL:${explicit_linker_property}>>:${rustflag_linker_arg}>")
corrosion_add_target_local_rustflags("${target_name}" "$<$<NOT:$<BOOL:${explicit_linker_property}>>:${rustflag_linker_arg}>")
endif()
else()
message(DEBUG "No linker preference for target ${target_name} could be detected.")
Expand Down Expand Up @@ -696,8 +696,8 @@ function(corrosion_link_libraries target_name)
$<TARGET_PROPERTY:${library},LINKER_LANGUAGE>
)

corrosion_add_target_rustflags(${target_name} "-L$<TARGET_LINKER_FILE_DIR:${library}>")
corrosion_add_target_rustflags(${target_name} "-l$<TARGET_LINKER_FILE_BASE_NAME:${library}>")
corrosion_add_target_local_rustflags(${target_name} "-L$<TARGET_LINKER_FILE_DIR:${library}>")
corrosion_add_target_local_rustflags(${target_name} "-l$<TARGET_LINKER_FILE_BASE_NAME:${library}>")
endforeach()
endfunction(corrosion_link_libraries)

Expand Down

0 comments on commit c05235f

Please sign in to comment.