linker: Link dylib crates by path by petrochenkov · Pull Request #126094 · rust-lang/rust (original) (raw)
The basic problem is that Cargo doesn't have a way to designate a target as a "module" instead of a "library". It just has "cdylib", which is supposed to be linked. Modules should not be linked (except on Android).
For example, in CMake, you have "shared library" and "module library" as separate concepts. Similarly in Meson you have shared_library() and shared_module().
There are a number of differences between the two, not just SONAME, for example undefined symbols are allowed in
modules. However, cdylib
is all that was available, so it was used for modules too. We saw this in the early years of Meson as well, when everyone started using shared_library()
, and we had a transition period to shared_module()
, which involved people fixing their usage.
Also, answering some suggestions in that bug, I think it is a mistake to pawn-off these duties to build.rs
or cargo-c:
build.rs
is an anti-pattern, people should not need to use code to build code. 99% of use-cases should be covered by something declarative, and the 1% custom needs should be code. With build.rs right now if you have to interop with C, 99% of cases need code to build code.
cargo-c
is a great project, and I want more people to use it, but this problem cannot be solved in cargo-c, we already tried it and the cargo-c maintainer reviewed this PR.