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 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 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?