Passing link-args (via cargo) for one platform (Mac) only


My dream is to meld Erlang and Rust in one application. Daniel Goertzen has written a nice library (ruster_unsafe on GitHub) that helps with this. It builds fine on Mac, Linux, and FreeBSD. However, the demo does not build on Mac. I’ve found out a way to build it, which is to invoke cargo rustc -- --codegen link-args='-flat_namespace -undefined suppress', which is all well and good, but I was hoping for a more streamlined approach. That is, anyone could clone my repo and simply invoke cargo build and be done.

One idea I had was to write a that output cargo:rustc-link-args="-flat_namespace -undefined suppress" but that option is not supported in cargo. If it were supported, the script would output this when running on Darwin, but not on other platforms.

I understand that passing linker flags via cargo/rustc is verboten, but I really want this to work on Mac, and this is the only way I have found to make it work. If there is a better approach, I’m all ears.



I hit the same problem writing a Ruby extension. I wonder if rustc should automatically add these flags if it encounters an extern block without a #[link(...)] attribute. Or perhaps explicitly with a new attribute such as #[dynamic_link].

Are there are any situations where either -flat_namespace or -undefined suppress would break something?