From f85b2422d39fb2f7daca33aa6c2ee7647e9f9348 Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Fri, 5 Apr 2024 16:11:23 +0200 Subject: [PATCH] Breaking: Replace dashes with underscores in lib names --- RELEASES.md | 6 +++++- cmake/CorrosionGenerator.cmake | 7 +++++++ test/cargo_flags/cargo_flags/CMakeLists.txt | 8 ++++---- test/cbindgen/rust2cpp/CMakeLists.txt | 4 ++-- test/custom_profiles/basic_profiles/CMakeLists.txt | 2 +- test/custom_profiles/custom_profiles/CMakeLists.txt | 4 ++-- test/cxxbridge/cxxbridge_rust2cpp/CMakeLists.txt | 4 ++-- test/envvar/envvar/CMakeLists.txt | 4 ++-- test/features/features/CMakeLists.txt | 4 ++-- test/rust2cpp/rust2cpp/CMakeLists.txt | 4 ++-- test/rustflags/rustflags/CMakeLists.txt | 10 +++++----- 11 files changed, 34 insertions(+), 23 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 5e480a51..7e22041f 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -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`. @@ -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 @@ -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_` (e.g. `CC_x86_64-unknown-linux-gnu=/path/to/my-compiler`) environment variables ([#475]). [#475]: https://github.com/corrosion-rs/corrosion/pull/475 diff --git a/cmake/CorrosionGenerator.cmake b/cmake/CorrosionGenerator.cmake index 787d139f..594645af 100644 --- a/cmake/CorrosionGenerator.cmake +++ b/cmake/CorrosionGenerator.cmake @@ -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 "") diff --git a/test/cargo_flags/cargo_flags/CMakeLists.txt b/test/cargo_flags/cargo_flags/CMakeLists.txt index 90b3d248..8c4d0784 100644 --- a/test/cargo_flags/cargo_flags/CMakeLists.txt +++ b/test/cargo_flags/cargo_flags/CMakeLists.txt @@ -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_link_libraries(flags-exe PUBLIC flags_lib) +corrosion_set_cargo_flags(flags_lib --features two) +corrosion_set_cargo_flags(flags_lib $) set_property( - TARGET flags-lib + TARGET flags_lib APPEND PROPERTY more_flags --features three ) diff --git a/test/cbindgen/rust2cpp/CMakeLists.txt b/test/cbindgen/rust2cpp/CMakeLists.txt index da459430..71967796 100644 --- a/test/cbindgen/rust2cpp/CMakeLists.txt +++ b/test/cbindgen/rust2cpp/CMakeLists.txt @@ -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) diff --git a/test/custom_profiles/basic_profiles/CMakeLists.txt b/test/custom_profiles/basic_profiles/CMakeLists.txt index 0ab33ca1..d020df4f 100644 --- a/test/custom_profiles/basic_profiles/CMakeLists.txt +++ b/test/custom_profiles/basic_profiles/CMakeLists.txt @@ -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) diff --git a/test/custom_profiles/custom_profiles/CMakeLists.txt b/test/custom_profiles/custom_profiles/CMakeLists.txt index 16b0ff5c..c9b5cd2e 100644 --- a/test/custom_profiles/custom_profiles/CMakeLists.txt +++ b/test/custom_profiles/custom_profiles/CMakeLists.txt @@ -8,7 +8,7 @@ set(custom_profile $,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}" ) @@ -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) diff --git a/test/cxxbridge/cxxbridge_rust2cpp/CMakeLists.txt b/test/cxxbridge/cxxbridge_rust2cpp/CMakeLists.txt index 17d71208..b8979b74 100644 --- a/test/cxxbridge/cxxbridge_rust2cpp/CMakeLists.txt +++ b/test/cxxbridge/cxxbridge_rust2cpp/CMakeLists.txt @@ -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() diff --git a/test/envvar/envvar/CMakeLists.txt b/test/envvar/envvar/CMakeLists.txt index 20cdd655..2e0eeabd 100644 --- a/test/envvar/envvar/CMakeLists.txt +++ b/test/envvar/envvar/CMakeLists.txt @@ -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" "$" "COR_CARGO_VERSION_MAJOR=${Rust_CARGO_VERSION_MAJOR}" @@ -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) diff --git a/test/features/features/CMakeLists.txt b/test/features/features/CMakeLists.txt index a3d5b865..7b376795 100644 --- a/test/features/features/CMakeLists.txt +++ b/test/features/features/CMakeLists.txt @@ -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 diff --git a/test/rust2cpp/rust2cpp/CMakeLists.txt b/test/rust2cpp/rust2cpp/CMakeLists.txt index 71b3bee6..e14de93a 100644 --- a/test/rust2cpp/rust2cpp/CMakeLists.txt +++ b/test/rust2cpp/rust2cpp/CMakeLists.txt @@ -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) diff --git a/test/rustflags/rustflags/CMakeLists.txt b/test/rustflags/rustflags/CMakeLists.txt index 422c352b..9a4f25cd 100644 --- a/test/rustflags/rustflags/CMakeLists.txt +++ b/test/rustflags/rustflags/CMakeLists.txt @@ -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="$,$>,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")