Skip to content

Commit

Permalink
Breaking: Replace dashes with underscores in lib names
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwe committed May 10, 2024
1 parent 5bfa8ac commit f85b242
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 23 deletions.
6 changes: 5 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### Breaking Changes

- Dashes (`-`) in names of imported CMake **library** targets are now replaced with underscores (`_`).
See [issue #501] for details. Users on older Corrosion versions will experience the same
change when using Rust 1.79 or newer. `bin` targets are not affected by this change.
- The master branch of corrosion now requires CMake 3.22. See also the
[v0.4.0 Release notes](#040-lts-2023-06-01) for more details.
- Removed native tooling and the corresponding option `CORROSION_NATIVE_TOOLING`.
Expand All @@ -25,6 +28,7 @@
to cbindgen via the `TARGET` environment variable. The `hostbuild` property is considered. [#507]
- Detect msvc linker flags coming from `--print=native-static-libs` and put them into `INTERFACE_LINK_OPTIONS` instead of `INTERFACE_LINK_LIBRARIES` [#511]

[issue #501]: https://github.com/corrosion-rs/corrosion/issues/501
[#459]: https://github.com/corrosion-rs/corrosion/pull/459
[#456]: https://github.com/corrosion-rs/corrosion/pull/456
[#455]: https://github.com/corrosion-rs/corrosion/pull/455
Expand Down Expand Up @@ -58,7 +62,7 @@

### Fixes

- The C/C++ compiler passed from corrosion to `cc-rs` can now be overriden by users setting
- The C/C++ compiler passed from corrosion to `cc-rs` can now be overridden by users setting
`CC_<target>` (e.g. `CC_x86_64-unknown-linux-gnu=/path/to/my-compiler`) environment variables ([#475]).

[#475]: https://github.com/corrosion-rs/corrosion/pull/475
Expand Down
7 changes: 7 additions & 0 deletions cmake/CorrosionGenerator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ function(_generator_add_package_targets)
endif()

if("staticlib" IN_LIST kinds OR "cdylib" IN_LIST kinds)
# Explicitly set library names have always been forbidden from using dashes (by cargo).
# Starting with Rust 1.79, names inherited from the package name will have dashes replaced
# by underscores too. Corrosion will thus replace dashes with underscores, to make the target
# name consistent independent of the Rust version. `bin` target names are not affected.
# See https://github.com/corrosion-rs/corrosion/issues/501 for more details.
string(REPLACE "\-" "_" target_name "${target_name}")

set(archive_byproducts "")
set(shared_lib_byproduct "")
set(pdb_byproduct "")
Expand Down
8 changes: 4 additions & 4 deletions test/cargo_flags/cargo_flags/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ include(../../test_header.cmake)
corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml FLAGS --features one)

add_executable(flags-exe main.cpp)
target_link_libraries(flags-exe PUBLIC flags-lib)
corrosion_set_cargo_flags(flags-lib --features two)
corrosion_set_cargo_flags(flags-lib $<TARGET_PROPERTY:flags-lib,more_flags>)
target_link_libraries(flags-exe PUBLIC flags_lib)
corrosion_set_cargo_flags(flags_lib --features two)
corrosion_set_cargo_flags(flags_lib $<TARGET_PROPERTY:flags_lib,more_flags>)

set_property(
TARGET flags-lib
TARGET flags_lib
APPEND
PROPERTY more_flags --features three
)
4 changes: 2 additions & 2 deletions test/cbindgen/rust2cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ project(test_project VERSION 0.1.0)
include(../../test_header.cmake)

corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml)
corrosion_experimental_cbindgen(TARGET rust-lib HEADER_NAME "rust-lib.h")
corrosion_experimental_cbindgen(TARGET rust_lib HEADER_NAME "rust-lib.h")

add_executable(cpp-exe main.cpp)
set_property(TARGET cpp-exe PROPERTY CXX_STANDARD 11)
target_link_libraries(cpp-exe PUBLIC rust-lib)
target_link_libraries(cpp-exe PUBLIC rust_lib)
2 changes: 1 addition & 1 deletion test/custom_profiles/basic_profiles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ endif()
corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml PROFILE ${CARGO_PROFILE})

add_executable(${CARGO_PROFILE}_bin main.cpp)
target_link_libraries(${CARGO_PROFILE}_bin PUBLIC cargo-profiles-lib)
target_link_libraries(${CARGO_PROFILE}_bin PUBLIC cargo_profiles_lib)
4 changes: 2 additions & 2 deletions test/custom_profiles/custom_profiles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(custom_profile $<IF:$<CONFIG:Debug>,dev-without-dbg,${_release_profile}>)
if(CORROSION_TEST_USE_TARGET_SPECIFIC_OVERRIDE)
# Select "wrong" profile here on purpose.
corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml PROFILE dev)
set_target_properties(custom-profiles-lib
set_target_properties(custom_profiles_lib
PROPERTIES
INTERFACE_CORROSION_CARGO_PROFILE "${custom_profile}"
)
Expand All @@ -17,4 +17,4 @@ else()
endif()

add_executable(custom-profile-exe main.cpp)
target_link_libraries(custom-profile-exe PUBLIC custom-profiles-lib)
target_link_libraries(custom-profile-exe PUBLIC custom_profiles_lib)
4 changes: 2 additions & 2 deletions test/cxxbridge/cxxbridge_rust2cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED 1)

corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml)
corrosion_add_cxxbridge(cxxbridge-cpp CRATE cxxbridge-crate MANIFEST_PATH rust FILES lib.rs foo/mod.rs)
corrosion_add_cxxbridge(cxxbridge-cpp CRATE cxxbridge_crate MANIFEST_PATH rust FILES lib.rs foo/mod.rs)

add_executable(cxxbridge-exe main.cpp)
target_link_libraries(cxxbridge-exe PUBLIC cxxbridge-cpp)

if(MSVC)
# Note: This is required because we use `cxx` which uses `cc` to compile and link C++ code.
corrosion_set_env_vars(cxxbridge-crate "CFLAGS=-MDd" "CXXFLAGS=-MDd")
corrosion_set_env_vars(cxxbridge_crate "CFLAGS=-MDd" "CXXFLAGS=-MDd")
endif()
4 changes: 2 additions & 2 deletions test/envvar/envvar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include(../../test_header.cmake)

corrosion_import_crate(MANIFEST_PATH Cargo.toml)

corrosion_set_env_vars(rust-lib-requiring-envvar
corrosion_set_env_vars(rust_lib_requiring_envvar
"ANOTHER_VARIABLE=ANOTHER_VALUE"
"$<TARGET_PROPERTY:program_requiring_rust_lib_with_envvar,INDIRECT_VAR_TEST>"
"COR_CARGO_VERSION_MAJOR=${Rust_CARGO_VERSION_MAJOR}"
Expand All @@ -20,4 +20,4 @@ set_property(
"REQUIRED_VARIABLE=EXPECTED_VALUE"
)

target_link_libraries(program_requiring_rust_lib_with_envvar PUBLIC rust-lib-requiring-envvar)
target_link_libraries(program_requiring_rust_lib_with_envvar PUBLIC rust_lib_requiring_envvar)
4 changes: 2 additions & 2 deletions test/features/features/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ include(../../test_header.cmake)
corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml FEATURES thirdfeature ALL_FEATURES)

add_executable(features-cpp-exe main.cpp)
target_link_libraries(features-cpp-exe PUBLIC rust-feature-lib)
target_link_libraries(features-cpp-exe PUBLIC rust_feature_lib)

corrosion_set_features(rust-feature-lib
corrosion_set_features(rust_feature_lib
ALL_FEATURES OFF
NO_DEFAULT_FEATURES
FEATURES
Expand Down
4 changes: 2 additions & 2 deletions test/rust2cpp/rust2cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ include(../../test_header.cmake)
corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml)

add_executable(cpp-exe main.cpp)
target_link_libraries(cpp-exe PUBLIC rust-lib)
target_link_libraries(cpp-exe PUBLIC rust_lib)

add_executable(cpp-exe-shared main.cpp)
target_link_libraries(cpp-exe-shared
PUBLIC rust-lib-shared)
PUBLIC rust_lib-shared)
10 changes: 5 additions & 5 deletions test/rustflags/rustflags/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ include(../../test_header.cmake)
corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml)

add_executable(rustflags-cpp-exe main.cpp)
target_link_libraries(rustflags-cpp-exe PUBLIC rustflag-test-lib)
target_link_libraries(rustflags-cpp-exe PUBLIC rustflag_test_lib)

# Test --cfg=key="value" rustflag.
corrosion_add_target_rustflags(rustflag-test-lib --cfg=test_rustflag_cfg1="test_rustflag_cfg1_value")
corrosion_add_target_rustflags(rustflag_test_lib --cfg=test_rustflag_cfg1="test_rustflag_cfg1_value")

# Test using a generator expression to produce a rustflag and passing multiple rustflags.
corrosion_add_target_rustflags(rustflag-test-lib
corrosion_add_target_rustflags(rustflag_test_lib
--cfg=test_rustflag_cfg2="$<IF:$<OR:$<CONFIG:Debug>,$<CONFIG:>>,debug,release>"
"--cfg=test_rustflag_cfg3"
)

corrosion_add_target_local_rustflags(rustflag-test-lib "--cfg=test_local_rustflag1")
corrosion_add_target_local_rustflags(rustflag-test-lib --cfg=test_local_rustflag2="value")
corrosion_add_target_local_rustflags(rustflag_test_lib "--cfg=test_local_rustflag1")
corrosion_add_target_local_rustflags(rustflag_test_lib --cfg=test_local_rustflag2="value")

0 comments on commit f85b242

Please sign in to comment.