How to use weak linking on macOS (link with `weak_framework`)?

Hi! We're looking for a way to weakly link to the Metal framework available in macOS in the metal crate. Typically this is done by by passing the linker argument weak_framework to the linker when linking Metal. The main benefit is that this would allow us to cross-compile for macOS on other host platforms (there is some more discussion in https://github.com/gfx-rs/wgpu-native/issues/50 for additional context).

Firefox currently does this by specifying weak_framework as a linker argument to use our crate, but we're hoping to find a way that we don't need to patch the linker arguments directly (e.g. avoiding manually patching the linker arguments, or using .cargo/config per user, etc.).

We tried specifying weak_framework in a couple places but neither appears to be allowed:

  • on externs with #[link(name = "Metal", kind = "weak_framework")] extern "C" { /* ... */ }
  • in build.rs with fn main() { println!("cargo:rustc-link-lib=weak_framework=Metal"); }

Is there anything else we could try? If not, how might we be able to support weak linking in Rust?

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.