gfx-rs / metal-rs

Rust bindings for Metal
Apache License 2.0
583 stars 112 forks source link

Explicitly load Metal symbols #105

Open kvark opened 4 years ago

kvark commented 4 years ago

Similar to https://github.com/gfx-rs/d3d12-rs/pull/19, we need to avoid implicit linking of Metal framework if we want to run (any application that uses metal-rs in some way) on macOS 10.10 and earlier.

One workaround that the clients could do is "-weak_framework Metal" instead of just "-framework". See https://phabricator.services.mozilla.com/D54946 for Gecko. They would still need to make sure that no entry points are used.

I think loading the libraries dynamically and explicitly by metal-rs is still better for the following reasons:

grovesNL commented 4 years ago

If it's possible, would it make sense to use weak_framework here, and expose a helper function to check if Metal is available?

we load symbols when metal-rs objects are created (or some kind of a Metal context is initialized) instead of dynamically checking for symbols on each and every call

If we want to use libloading for this, how should this work? Would we internally share a map of function pointers?

GopherJ commented 4 years ago

Hi, any news on this?

grovesNL commented 4 years ago

@GopherJ not yet, we might experiment with the first approach above (i.e. using weak_framework and a helper function to check if it's loaded)

GopherJ commented 4 years ago

@grovesNL ok thanks take your time and ping me if it's resolved, I'll be excited to test again. 😄

kvark commented 4 years ago

Would #[link(name = "Metal", kind = "weak_framework")] work?

grovesNL commented 4 years ago

Yeah I think something like that should work – just need to test it out

grovesNL commented 3 years ago

Update: I asked on the Rust Zulip and Discourse (https://users.rust-lang.org/t/how-to-use-weak-linking-on-macos-link-with-weak-framework/50732) but had no response yet