Looking for example of successful Rust FFI on MacOS with non-Apple clang install

I’m developing a Rust library (on MacOS) that uses Rust’s FFI to call out to a C library.

I’m using a Homebrew-installed version of llvm/clang to build the C library and I’d like to take advantage of the clang sanitizers (e.g. -fsanitize=address -fsanitize=undefined) where possible.

I have no problem building the shared C library with the sanitizers enabled but they also require link-time support and of course when I build the Rust library Cargo can’t find sanitizer symbols (e.g. dyld: Symbol not found: ___ubsan_vptr_type_cache).

How can I persuade Cargo to look for the right Homebrew-installed support libraries on MacOS? Or, does someone have an example Rust FFI project I could look at that makes use of the Homebrew-installed llvm/clang?



Add build.rs to your project and print cargo:rustc-link-lib/cargo:rustc-link-search=native= directives to link the extra libraries needed.

Alternatively, instead of building a static C library, build a dynamic one (.dylib). AFAIK in such case it should have its own copy of the required runtime.

Thanks for the hint – will try that out.

The library is already a (shared) .dylib but there’s a bunch of clang-provided other dylibs with the sanitizer run time code (I think).