MacOS M2 cross compile to x86_64-macos-none fails
Mac M2 running Sequoia 15.5, zig 0.14.1.
Using the zig-webui repo, zig build run_minimal builds and runs fine. When trying to cross compile with -Dtarget=x86_64-macos-none the build will fail. Not sure if this is a zig, zig-webui or a "me" related issue (very new to the first two) but cross compiling a plain vanilla zig project to any platform works with no issues.
❯ zig build run_minimal -Dtarget=x86_64-macos-none
run_minimal
└─ run minimal
└─ zig build-exe minimal Debug x86_64-macos-none
└─ zig build-lib webui Debug x86_64-macos-none failure
error: error: unable to find framework 'Cocoa'. searched paths: none
error: unable to find framework 'WebKit'. searched paths: none
error: the following command exited with error code 1:
/opt/homebrew/Cellar/zig/0.14.1/bin/zig build-lib -cflags -DNO_SSL -- /Users/metx/.cache/zig/p/webui-2.5.0-beta.4-pxqD5bE4NwCVDCBguzzRmyOubiadAaVRNM0XMxqUv_GS/src/webui.c -cflags -DNO_CACHING -DNO_CGI -DUSE_WEBSOCKET -Wno-error=date-time -DUSE_WEBSOCKET -DNO_SSL -DNDEBUG -- /Users/metx/.cache/zig/p/webui-2.5.0-beta.4-pxqD5bE4NwCVDCBguzzRmyOubiadAaVRNM0XMxqUv_GS/src/civetweb/civetweb.c -cflags -- /Users/metx/.cache/zig/p/webui-2.5.0-beta.4-pxqD5bE4NwCVDCBguzzRmyOubiadAaVRNM0XMxqUv_GS/src/webview/wkwebview.m -ODebug -target x86_64-macos-none -mcpu baseline -I /Users/metx/.cache/zig/p/webui-2.5.0-beta.4-pxqD5bE4NwCVDCBguzzRmyOubiadAaVRNM0XMxqUv_GS/include -Mroot -framework Cocoa -framework WebKit -lc --cache-dir /Users/metx/Developer/zig/zig-webui/.zig-cache --global-cache-dir /Users/metx/.cache/zig --name webui -static --zig-lib-dir /opt/homebrew/Cellar/zig/0.14.1/lib/zig/ --listen=-
Build Summary: 2/7 steps succeeded; 1 failed
Can you test to run this zig build run_minimal -Dtarget=aarch64-macos ?
Same problem:
❯ zig build run_minimal -Dtarget=aarch64-macos
run_minimal
└─ run minimal
└─ zig build-exe minimal Debug aarch64-macos
└─ zig build-lib webui Debug aarch64-macos failure
error: error: unable to find framework 'Cocoa'. searched paths: none
error: unable to find framework 'WebKit'. searched paths: none
error: the following command exited with error code 1:
/opt/homebrew/Cellar/zig/0.14.1/bin/zig build-lib -cflags -DNO_SSL -- /Users/metx/.cache/zig/p/webui-2.5.0-beta.4-pxqD5bE4NwCVDCBguzzRmyOubiadAaVRNM0XMxqUv_GS/src/webui.c -cflags -DNO_CACHING -DNO_CGI -DUSE_WEBSOCKET -Wno-error=date-time -DUSE_WEBSOCKET -DNO_SSL -DNDEBUG -- /Users/metx/.cache/zig/p/webui-2.5.0-beta.4-pxqD5bE4NwCVDCBguzzRmyOubiadAaVRNM0XMxqUv_GS/src/civetweb/civetweb.c -cflags -- /Users/metx/.cache/zig/p/webui-2.5.0-beta.4-pxqD5bE4NwCVDCBguzzRmyOubiadAaVRNM0XMxqUv_GS/src/webview/wkwebview.m -ODebug -target aarch64-macos -mcpu baseline -I /Users/metx/.cache/zig/p/webui-2.5.0-beta.4-pxqD5bE4NwCVDCBguzzRmyOubiadAaVRNM0XMxqUv_GS/include -Mroot -framework Cocoa -framework WebKit -lc --cache-dir /Users/metx/Developer/zig/zig-webui/.zig-cache --global-cache-dir /Users/metx/.cache/zig --name webui -static --zig-lib-dir /opt/homebrew/Cellar/zig/0.14.1/lib/zig/ --listen=-
Build Summary: 2/7 steps succeeded; 1 failed
run_minimal transitive failure
└─ run minimal transitive failure
├─ zig build-exe minimal Debug aarch64-macos transitive failure
│ ├─ zig build-lib webui Debug aarch64-macos failure
│ ├─ zig build-lib webui Debug aarch64-macos (reused)
│ ├─ zig build-lib webui Debug aarch64-macos (reused)
│ └─ zig build-lib webui Debug aarch64-macos (reused)
└─ install minimal transitive failure
└─ zig build-exe minimal Debug aarch64-macos (+7 more reused dependencies)
error: the following build command failed with exit code 1:
/Users/metx/Developer/zig/zig-webui/.zig-cache/o/c258ec9754b426ffa836008b9e5b48f1/build /opt/homebrew/Cellar/zig/0.14.1/bin/zig /opt/homebrew/Cellar/zig/0.14.1/lib/zig /Users/metx/Developer/zig/zig-webui /Users/metx/Developer/zig/zig-webui/.zig-cache /Users/metx/.cache/zig --seed 0xac51964 -Zb5fb3f3c14a9cb07 run_minimal -Dtarget=aarch64-macos
Do you install xcode ?
Of course, XCode 16.4. Native and cross compile works for other zig projects. It is only cross compiling for this specific project that fails.
Side note: I also have no problems building a universal binary for the original WebUI 2.5 B4 C project in XCode.
OK, I'll try to test on m4 (I only have such a device)
Can you please confirm you correctly installed WebKit and Cocoa x86_64 version?
Can you please confirm you correctly installed
WebKitandCocoax86_64 version?
Does this help?
❯ pod --version
1.16.2
❯ arch -x86_64 pod --version
1.16.2
EDIT: Not sure how to check WebKit. But as I mentioned, my C WebUI project is linking Cocoa and WebKit and it builds a proper universal binary so I have to assume everything is correctly installed.
That's correct, if you cross compile webui C that's mean you have WebKit and Cocoa x86_64 installed. I think the issue is that Zig does not search for x86_64 paths in macOS.
I think the issue is that Zig does not search for x86_64 paths in macOS.
Note also that I don't have any issues cross compiling a plain vanilla zig project to x86_64, only zig-webui is problematic.
I was trying to get github actions to build for both x86_64-macos and aarch64-macos using the macos-latest runner, and this error comes up only if -Dtarget={...} is specified. Without specifying the target, the native compilation can find the necessary cocoa/webkit libraries.
Thank you for pointing this out, I wonder if we should modify/remove -Dtarget={...}
@jinzhongjia what do you think?
Looking at this.. https://github.com/ziglang/zig/issues/16557#issuecomment-1684932310 it seems that zig won't auto-detect sysroot when cross compiling. I wonder if the webui repo could provide a way to either automatically, or manually set the sysroot for library users to enable these things to be found.
It might also be awesome if the github ci is changed to enable building for x86_64-macos and aarch64-macos in the mac builds :)
Just re-posting my comment from the other issue here: I was able to get the cross compilation work for zig-webui using this. https://github.com/webui-dev/zig-webui/issues/107#issuecomment-3131891223
Thank you @happyalu for looking into this. Feel free to create a PR in webui-zig and webui-c if needed, @jinzhongjia will review them and validate.