You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Having a workspace with multiple crates, libraries and binaries combined. One of the libraries should be compiled as dylib and used from an FFI context in another language. When the crate is in a workspace, it has certain libraries linked dynamically that cannot be found:
We can add the library in the exclude section in the workspace Cargo.toml and try compiling it again. This time it holds its own target directory and the linking works as supposed, as can be seen in the ldd output:
Maybe I need to provide more information why I use dylib instead of cdylib.
This crate uses neon bindings and the resulting so is loaded using node's require that just does not work right with a cdylib, but works quite well with a statically compiled dylib:
Thanks for the reports here! When compiling a Rust dynamic library though to integrate into another language you'll want to use a cdylib, not a dylib. Although an unfortunate historical accident a dylib is a different kind of artifact, so that should do the trick when implementing this.
Problem
Having a workspace with multiple crates, libraries and binaries combined. One of the libraries should be compiled as
dylib
and used from an FFI context in another language. When the crate is in a workspace, it has certain libraries linked dynamically that cannot be found:The
cargo build -vv --package migration-core
reveals how Cargo adds an extra flag-C prefer-dynamic
to the build parameters:We can add the library in the
exclude
section in the workspaceCargo.toml
and try compiling it again. This time it holds its own target directory and the linking works as supposed, as can be seen in the ldd output:And we can see the
prefer-dynamic
build flag is not set:Steps
git clone git@github.com:prisma/prisma.git --branch lift_ffi
cd prisma/server/prisma-rs
cargo build -vv --package migration-core
-C prefer-dynamic
ldd target/debug/libmigration_core.so
for missing dependenciescd migration-engine/core/
cargo build -vv
-C prefer-dynamic
set.ldd target/debug/libmigration_core.so
and see howlibstd
andliblexical_core
are now statically linked and not missing.Notes
The text was updated successfully, but these errors were encountered: