I am currently writing a program in Rust that requires me to tap into system APIs that are not Rust native. In my case I have a static native library that is written in Swift using the C ABI for linking. I am able to link the Swift library into my static Rust library just fine but when I go to link the Rust binary against my Rust static library it requires me to link against the static Swift library again. Is it possible to forgo this extra step and help clean up my build.rs files?
Is it possible to link a static library to a C library and not link the binary against the C library
Asked
Active
Viewed 103 times
0
-
1No because your Rust library is not _linked_ with the Swift library. Linking only occurs when building programs or dynamic libraries, not static libraries. – Jmb Sep 21 '22 at 06:44
-
@Jmb thanks for clearing that up. What way would you recommend bundling the rust library and native library together to clean up the build process? – Hayden Stith Sep 21 '22 at 11:57
-
AFAIK there is no easy way to bundle the two libraries in a single file, although that might be theoretically possible on Linux (where they're both `ar` archives with added metadata). However you might be able to have the Swift library linked automatically when including the Rust library with the [`#[link(...)]` attribute](https://doc.rust-lang.org/nomicon/ffi.html#calling-foreign-functions). – Jmb Sep 21 '22 at 15:13