Open ensc opened 4 months ago
I believe this is expected behavior. The bar
package refers to foo::func()
, and thus must pull in the foo
rlib as a static library. Rust does not support dynamically loading cdylib
s automatically.
You can use dylib
to dynamically link Rust projects, or use a library like libloading
to dynamically load a cdylib. (I think artifact dependencies can also do something similar, but it's more advanced and requires an extern block to set up the bindings.)
I do not think this is related to loading cdylib
from rust. I want to use it like
graph LR;
c_app[C application]
libfoo[libfoo.so]
libbar[libbar.so]
libbaz[libbaz.so]
c_app -- foo_func() --> libfoo;
c_app -- bar_func() --> libbar;
c_app -- baz_func() --> libbaz;
libbar -. foo::func() .-> libfoo;
libbaz -. foo::func() .-> libfoo;
(to avoid an easy solution like "use only libbar.so", I added a libbaz.so
which is similarly to libbar.so
)
It would be nice when the rust internal linking between libbar.so
and libfoo.so
would work (I tried dylib
but this breaks somehow when building tests; perhaps LTO related and another issue). For now, it is ok when libbar.so
contains the statically linked rust code of libfoo.so
.
But the problem is that the C library libbar.so
(and libbaz.so
) contains the symbols of libfoo.so
.
cdylib
libraries should be created in a way that extern "C"
symbols of dependent cdylib
are exported as hidden (in C __attribute__((__visibility__(hidden)))
or the corresponding link flag). When dependency is a pure rlib
, they should be public.
Problem
When a
cdylib
has anothercdylib
as a dependency, the resulting library contains the symbols of both packages.E.g. when building a project (see https://github.com/ensc/cargo-13978) like
the resulting (outer) library contains
The inner library (which can be installed separately) contains
foo_func
should be only inlibfoo.so
.Version