Skip to content

Commit cae421c

Browse files
committed
Rename rustflags variable to make global scope clear
The currently available way of setting Rustflags is by setting the `RUSTFLAGS` environment variable, which affects all crates in the dependency graph. This may be undesirable in some circumstances, so a future commit will the option to specify RUSTFLAGS via `cargo rustc`, which only affects the current crate and not dependencies. This commit prepares by refactoring some names to make the distinction easier.
1 parent ff5deff commit cae421c

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

cmake/Corrosion.cmake

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,7 @@ function(_add_cargo_build)
252252
set(no_default_libraries_arg --no-default-libraries)
253253
endif()
254254

255-
set(rustflags_target_property "$<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_RUSTFLAGS>>")
256-
# `rustflags_target_property` may contain multiple arguments and double quotes, so we _should_ single quote it to
257-
# preserve any double quotes and keep it as one argument value. However single quotes don't work on windows, so we
258-
# can only add double quotes here. Any double quotes _in_ the rustflags must be escaped like `\\\"`.
255+
set(global_rustflags_target_property "$<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},INTERFACE_CORROSION_RUSTFLAGS>>")
259256

260257
set(features_target_property "$<GENEX_EVAL:$<TARGET_PROPERTY:${target_name},${_CORR_PROP_FEATURES}>>")
261258
set(features_genex "$<$<BOOL:${features_target_property}>:--features=$<JOIN:${features_target_property},$<COMMA>>>")
@@ -358,8 +355,8 @@ function(_add_cargo_build)
358355
corrosion_add_target_rustflags("${target_name}" "-Cdefault-linker-libraries=yes")
359356
endif()
360357

361-
set(joined_rustflags "$<JOIN:${rustflags_target_property}, >")
362-
set(rustflags_genex "$<$<BOOL:${rustflags_target_property}>:RUSTFLAGS=${joined_rustflags}>")
358+
set(global_joined_rustflags "$<JOIN:${global_rustflags_target_property}, >")
359+
set(global_rustflags_genex "$<$<BOOL:${global_rustflags_target_property}>:RUSTFLAGS=${global_joined_rustflags}>")
363360

364361
# Used to set a linker for a specific target-triple.
365362
set(cargo_target_linker_var "CARGO_TARGET_${_CORROSION_RUST_CARGO_TARGET_UPPER}_LINKER")
@@ -397,7 +394,7 @@ function(_add_cargo_build)
397394
COMMAND
398395
${CMAKE_COMMAND} -E env
399396
"${build_env_variable_genex}"
400-
"${rustflags_genex}"
397+
"${global_rustflags_genex}"
401398
"${cargo_target_linker}"
402399
"${corrosion_cc_rs_flags}"
403400
"${cargo_library_path}"

0 commit comments

Comments
 (0)