(regression) x86_64-macos -> aarch64-macos cross compilation failing after update to Zig master #108
Labels
No labels
CI
all
basisu
blog
bug
build
contributor-friendly
core
correctness
deferred
dev
direct3d-headers
docs
driver-os-issue
duplicate
dxcompiler
editor
examples
experiment
feature-idea
feedback
flac
freetype
gamemode
gkurve
glfw
gpu
gpu-dawn
harfbuzz
help welcome
in-progress
infrastructure
invalid
libmach
linux-audio-headers
long-term
mach
mach.gfx
mach.math
mach.physics
mach.testing
model3d
needs-triage
object
opengl-headers
opus
os/linux
os/macos
os/wasm
os/windows
package-manager
priority
proposal
proposal-accepted
question
roadmap
slipped
stability
sysaudio
sysgpu
sysjs
validating-fix
vulkan-zig-generated
wayland-headers
website
wontfix
wrench
www
x11-headers
xcode-frameworks
zig-update
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
hexops/mach#108
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
After updating to latest Zig master https://github.com/hexops/mach/pull/107 we find an intriguing failure when cross compiling x86_64-macos -> aarch64-macos.
Notably, linux/windows -> aarch64-macos do not fail.
https://github.com/hexops/mach/runs/4339864442?check_suite_focus=true
Huh, strangely with (nearly) the same Zig version on my Intel MBP everything is fine:
Could be a difference in the XCode versions.
Or possibly the macOS version even? GitHub actions aren't running Monterey yet (but maybe we can opt in? see https://github.com/github/roadmap/issues/240 ) while my system is on Monterey.
Prior tests were with latest XCode for macOS 12, and CLT 11.3 SDK (surprisingly updating XCode doesn't update CLT)
Same thing with no XCode/CLT, though: it just works.
Looks like macOS 12 on GitHub Actions won't be supported until at least early 2022, yuck.
https://github.com/actions/virtual-environments/issues/3649
Also tried what is described in https://github.com/github/roadmap/issues/240 but no dice, if there is a beta program for Monterey we're not in it.
With
set_sysroot = truewe don't run into the issue. This implies that Zig is picking up system x86_64 libraries (maybe during dependency resolution?) and trying to link those in by accident, instead of properly resolving the ones in the-iframeworkand-Fparameters first.Looks like
macos-latestrefers to macOS 11 with GitHub actions, and includes XCode 13.1 / CLT 13.0.0https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md
What we know so far..
When cross compiling x86_64-macos -> aarch64-macos:
mismatched cpu architecture: expected Arch.aarch64, found Arch.x86_64The only fundamental difference here is macOS 11 vs macOS 12.
OK, finally have a complete explanation.
Context: We do not wish to set
sysroot, doing so prevents someone wishing to use e.g. mach-glfw alone from including libraries not found in the mach native SDKs (e.g. Vulkan is not included in our sdk-macos-11.3), we just want to use the sdk-macos-11.3 only for libraries mach-glfw needs by default - things not present on the native system.Framework .tbd stubs define re-exported libraries:
github.com/hexops/sdk-macos-11.3@6d49d06e12/root/System/Library/Frameworks/Foundation.framework/Foundation.tbd (L24-L25)When we link
-framework Foundationwithout setting sysroot, it finds our sdk-macos-11.3 copy because we've added it to the framework include path.On macOS 12+, it simply fails to find these reexported libraries:
This is fine on macOS 12+, because we also explicitly link
CoreFoundationandobjcseparately (not with absolute paths like in those reexported libraries.)But on macOS 11 and earlier, these libraries in fact exist on the system.
/usr/lib/libobjc.A.dylibis a real x86_64 dylib, and that's a mismatch.Here is where in the Zig linker code that these re-exported libraries are resolved: https://sourcegraph.com/github.com/ziglang/zig@aa61e03f244a72ea01f05c3ceea7c5fb5aadf1ff/-/blob/src/link/MachO.zig?L1267:4
One option I looked into here: what if we made these paths relative (
/usr/lib/libobjc.A.dylib->usr/lib/libobjc.A.dylib) in our copy only, then includedsdk-macos-11.3/rooton the lib path. The hope being thatusr/lib/libobjc.A.dylibdoesn't resolve the system copy, but it would resolve to thesdk-macos-11.3/root/usr/lib/libobjc.A.dylibcopy.The problem with that is that when resolving dependencies, Zig's linker doesn't consider the framework/library search path - it expects absolute paths (rightfully so perhaps?) so unless we could specify fully qualified paths, that's a no-go.
Another option is to say we don't support cross compilation to Mac unless you're on macOS 12+. But this is icky, particularly because we're relying on some subtle behavior here which could change (that these libs do not exist on the system.)
Another option to consider: maybe we send a PR to zld to have it respect framework/lib include dirs when resolving dependencies, if an absolute filepath is not found. At first thought, that would seem specific to what Mach is doing but I think Zig would need to solve this too when it starts distributing tbd stubs with the package manager?
Another valid relatively low-effort option: strip all dependency sections from the .tbd files we distribute.
Maybe this option is not too bad - the number of dependencies for system libs seems small in general, there's no harm in specifying all dependencies manually, and if you're using
system_sdk.zigyou are already specifying libs to link.I plan to go this route. However, this is a non-backwards-compatible change to the sdk-macos repos. Thus, I am first going to ensure we have SDK version pinning and automatic updates for SDKs.