corrosion-rs / corrosion

Marrying Rust and CMake - Easy Rust and C/C++ Integration!
https://corrosion-rs.github.io/corrosion/
MIT License
1.02k stars 97 forks source link

Breaking change to target names containing dashes with Rust 1.79 #501

Closed jschwe closed 2 months ago

jschwe commented 3 months ago

cargo-metadata output for target names changes with Rust 1.79 due to PR https://github.com/rust-lang/cargo/pull/12783 fixing issue https://github.com/rust-lang/cargo/issues/12780. (TLDR: dashes in target names are replaced with underscores starting with Rust 1.79)

Users would notice this by receiving errors that CMake can't find Rust targets with dashes in the name anymore, e.g.:

CMake Error at /Users/jschwender/Dev/corrosion/cmake/Corrosion.cmake:1172 (set_property):
  set_property could not find TARGET rustflag-test-lib.  Perhaps it has not
  yet been created.
Call Stack (most recent call first):
  CMakeLists.txt:11 (corrosion_add_target_rustflags)

Example of an affected Cargo.toml file:

[package]
name = "flags-lib"
version = "0.1.0"
edition = "2018"

[lib]
# Note how there is no explicit `name` field here.
crate-type=["staticlib"]

With Rust 1.79, corrosion would now import a crate named flags_lib, i.e. the CMake target name changed.

Affected crates

Solution / Required actions

tronical commented 3 months ago

We ran into the same issue but worked around it by explicitly setting lib.name (https://github.com/slint-ui/slint/commit/eeb7bad4aeec0fcdef16d59f74467cf908c6af13 ).

But I guess it also ok to do a _ -> - transformation unconditionally in corrosion.

jschwe commented 3 months ago

We ran into the same issue but worked around it by explicitly setting lib.name (https://github.com/slint-ui/slint/commit/eeb7bad4aeec0fcdef16d59f74467cf908c6af13 ).

Thanks - I updated the issue description, and included your commit as an example that other users could follow. If you have any suggestions to improve the issue description, feel free to edit the description.

But I guess it also ok to do a _ -> - transformation unconditionally in corrosion.

There are also crates which use _ in their package name, so such a transformation would break those users instead. I would just unconditionally transform - to _, so that corrosion matches cargos post 1.79 behavior.

jschwe commented 2 months ago

Corrosion v0.5 and newer unconditionally replace dashes with underscores in library names, to match the behavior of Rust 1.79 and newer.