Open GopherJ opened 4 years ago
See also: https://github.com/hecrj/iced/issues/536
The script that I used to compile is located at:
https://github.com/GopherJ/cfg/blob/master/scripts/osxcross.sh
Environments:
System: Linux Mint 20 Cinamon Rust: rustc 1.46.0-nightly (feb3536eb 2020-06-09)
Am I missing something?
wgpu uses Metal.framework
(normally available in macOS/iOS SDKs), so the argument "-framework" "Metal"
will try to link to Metal.framework
and fail if it can't be found.
I'm not sure how easy or possible it is to use the macOS SDK (specifically Metal.framework
) from Linux for cross-compilation. I've heard it's possible at least (e.g. @kvark mentioned that Gecko cross-compiles wgpu for macOS from a Linux host). Unfortunately we haven't been using cross-compilation in this project (we use macOS hosts), so we don't have much experience with this.
@grovesNL Firefox CI already does it. The Firefox macOS builds are produced on Linux, and they include wgpu
.
The secret was to link with -weak-framework Metal
, see https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html#//apple_ref/doc/uid/20002378-107026
Alright thanks! So it sounds the cross-compilation can already be done manually by replacing "-framework" "Metal"
with "-weak_framework" "Metal"
, and longer term we might want to consider changing how this works upstream in our metal bindings (gfx-rs/metal-rs#105).
@GopherJ would you like to try manually running the "x86_64-apple-darwin14-clang" "-m64" "-L" ...
command from above, but replacing "-framework" "Metal"
with "-weak_framework" "Metal"
?
@grovesNL Thanks for your reply, is there a way to do this through cargo?
To reproduce:
clone iced
git clone https://github.com/hecrj/iced
change working directory
cd examples/game_of_life
curl -O https://raw.githubusercontent.com/GopherJ/cfg/master/scripts/osxcross.sh
chmod u+x osxcross.sh
./osxcross.sh
I'm not sure if there's a way to do it with cargo directly – we'd need to intercept the build command generated by cargo to replace the framework
with weak_framework
for Metal and run that. I was thinking we could just try manually running that "x86_64-apple-darwin14-clang" ...
command from above with the replacement to check if it works for you.
(the eventual fix will probably be gfx-rs/metal-rs#105, but hoping we could workaround it for now)
I tried specifying weak_framework
on the externs:
#[link(name = "Metal", kind = "weak_framework")]
extern "C" {
/* ... */
}
but that fails with unknown kind:
error[E0458]: unknown kind: `weak_framework`
--> src/device.rs:1352:24
|
1352 | #[link(name = "Metal", kind = "weak_framework")]
| -----------------------^^^^^^^^^^^^^^^^^^^^^^^--
| |
| unknown kind
error: aborting due to previous error
I also tried using build.rs and passing it as an linker argument there:
fn main() {
println!("cargo:rustc-link-lib=weak_framework=Metal");
}
but that also fails:
error: unknown library kind `weak_framework`, expected one of dylib, framework, or static
So it looks like we'll have to find some other ways to pass weak_framework
to the linker. I think it's possible to do it with a custom .cargo/config
but we can't use that here either.
Could you file a bug to rust-lang about "weak_framework" not recognized as an option?
I asked on Zulip and Discourse, I guess we can track updates in https://github.com/gfx-rs/metal-rs/issues/105#issuecomment-720811909
While cross compiling
iced
I came across an error onwgpu-native
:Any idea on this?