-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Regression in linker, cross compiling for macos #17130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@slimsag this may be an outkast event, but also it may be sensible to add some basic cross-build CI to ensure that the automatic PRs aren't merged with regressions, like in the branch used to reproduce the regression. I think right now xcode_frameworks seems fragile enough to justify it |
I wonder could this be related to #16818? |
Apparently not entirely. It does include the -iframework now, but it is missing the -F # good
/usr/local/lib/zig/zig build-exe /workspaces/mach-glfw/example/main.zig /workspaces/mach-glfw/zig-cache/o/639c138bb970d1d8ed2f85992cc244b2/libglfw.a /workspaces/mach-glfw/zig-cache/o/ffff0e5b8ab378129a9ec35b4c56c825/libvulkan-headers.a -lobjc /workspaces/mach-glfw/zig-cache/o/ffff0e5b8ab378129a9ec35b4c56c825/libvulkan-headers.a /workspaces/mach-glfw/zig-cache/o/31a83fe8d5b388726093745432f2e756/libx11-headers.a /workspaces/mach-glfw/zig-cache/o/e9e3d3b8e8fffa07062b4354f04babcd/libwayland-headers.a -lc --verbose-link --cache-dir /workspaces/mach-glfw/zig-cache --global-cache-dir /home/node/.cache/zig --name example -target aarch64-macos -mcpu generic --mod glfw::/workspaces/mach-glfw/src/main.zig --deps glfw -I /home/node/.cache/zig/p/1220fe0763e9722d56d3f93f8740e077fccf338d9697f08239d79a1ee27ae5833e62/include \
-isystem /home/node/.cache/zig/p/1220293eae4bf67a7c27a18a8133621337cde91a97bc6859a9431b3b2d4217dfb5fb/zig-cache/xcode_frameworks/include \
-I /workspaces/mach-glfw/zig-cache/i/f237565cd8e8d1d9bdd8b82de4ae04ce/include \
-I /workspaces/mach-glfw/zig-cache/i/801083cb93794881a77d1764bc388945/include \
-I /workspaces/mach-glfw/zig-cache/i/45f59e6632d069fa730b125989be9996/include \
-L /home/node/.cache/zig/p/1220293eae4bf67a7c27a18a8133621337cde91a97bc6859a9431b3b2d4217dfb5fb/zig-cache/xcode_frameworks/lib \
-iframework /home/node/.cache/zig/p/1220293eae4bf67a7c27a18a8133621337cde91a97bc6859a9431b3b2d4217dfb5fb/zig-cache/xcode_frameworks/Frameworks \
+ -F /home/node/.cache/zig/p/1220293eae4bf67a7c27a18a8133621337cde91a97bc6859a9431b3b2d4217dfb5fb/zig-cache/xcode_frameworks/Frameworks \
-framework CoreFoundation -framework AppKit -framework CoreServices -framework Metal -framework CoreGraphics -framework IOKit -framework Foundation --listen=-
# using addSystemFrameworkPath
/usr/local/lib/zig/zig build-exe /workspaces/mach-glfw/example/main.zig /workspaces/mach-glfw/zig-cache/o/e0c0d01eab963d7746ec0821e4966b81/libglfw.a /workspaces/mach-glfw/zig-cache/o/624869063b9487aa0656fffb16ad422b/libvulkan-headers.a -lobjc /workspaces/mach-glfw/zig-cache/o/624869063b9487aa0656fffb16ad422b/libvulkan-headers.a /workspaces/mach-glfw/zig-cache/o/5fd3803e75d7ce137630d9994e8b5d98/libx11-headers.a /workspaces/mach-glfw/zig-cache/o/a3cbd3950fdd54726e733cbce5011c1c/libwayland-headers.a -lc --verbose-link --cache-dir /workspaces/mach-glfw/zig-cache --global-cache-dir /home/node/.cache/zig --name example -target aarch64-macos -mcpu generic --mod glfw::/workspaces/mach-glfw/src/main.zig --deps glfw -I /home/node/.cache/zig/p/1220fe0763e9722d56d3f93f8740e077fccf338d9697f08239d79a1ee27ae5833e62/include \
-iframework /home/node/.cache/zig/p/1220bb0bd84dbe379d5ad02c37f3a2af8da5d296f5110bf7ea788d8b6ec0d3d2727d/zig-cache/xcode_frameworks/Frameworks \
-isystem /home/node/.cache/zig/p/1220bb0bd84dbe379d5ad02c37f3a2af8da5d296f5110bf7ea788d8b6ec0d3d2727d/zig-cache/xcode_frameworks/include \
-I /workspaces/mach-glfw/zig-cache/i/dcf9574a0199c4a2d9a16e9a3e27c447/include \
-I /workspaces/mach-glfw/zig-cache/i/9f02276e6a0279a1ecb23bd7df2665e2/include \
-I /workspaces/mach-glfw/zig-cache/i/07ee617160c3200c7fa40bc5eeeb7f49/include \
-L /home/node/.cache/zig/p/1220bb0bd84dbe379d5ad02c37f3a2af8da5d296f5110bf7ea788d8b6ec0d3d2727d/zig-cache/xcode_frameworks/lib \
-framework CoreFoundation -framework AppKit -framework CoreServices -framework Metal -framework CoreGraphics -framework IOKit -framework Foundation --listen=-
menduz/mach-glfw@5250c09 |
Hmm, that should not have the impact on the linker as |
The arguments for the
|
I'm using absolute paths: https://github.com/menduz/xcode-frameworks-pkg/blob/main/build.zig#L28, I think that doesn't apply in this case |
Hmm, I don't see the sysroot set though. It needs to be set for Zig to pass it on to the linker as |
No inconvenience at all. Yes, it is. You should set it to the same value to what you prepend in |
Many thanks, I've got it working. There is one subtlety, it seems that the compiler is assuming the vendor file structure of the SDK, regardless of passing custom paths for addFrameworkPath, include, lib, etc. So I had to copy the same structure verbatim. Then, properly use the .sysroot and finally the build is now passing. Again, many, many thanks @kubkon. Without your guidance this would have costed me a day. CC: @slimsag FYI |
FYI in Mach we don't use a sysroot; instead we treat frameworks as just frameworks and just add them to the paths: https://github.com/hexops/xcode-frameworks/blob/fb8ce986a98a72cdcbb844bbcfbafeb3133564a2/build.zig#L18-L22 |
@kubkon I realize now we're facing this issue as well:
Can you shed more light on why this behavior changed? I know this worked in 0.12.0-dev.21+ac95cfe44 and stopped working in 0.12.0-dev.389+61b70778b Specifically, I'd like to understand why a sysroot is necessary - what's the reason these three calls are no longer sufficient? Also, if I use a sysroot on a macOS host (in hopes users don't need to install Xcode) - does that imply frameworks cannot come from outside the sysroot? e.g. can I use the sysroot on a macOS host, can users still pull in their own custom frameworks - or would they need to fork the xcode-frameworks repository and add their frameworks to the sysroot? |
With two-level namespace, dylibs are allowed to re-export other dylibs by their install name. The linker then when resolving them tries that verbatim path followed by I believe there are three ways we could address this:
Let me know what you think @slimsag and in the meantime I am re-opening the issue. |
From my POV options 1/2 make sense, and it sounds like 3 has a runtime penalty which would be nice to avoid. As I understand it, that means the linker would try:
I've made a 'guess' here that you are also talking about ...anywho, as long as there is a way for me to ship xcode frameworks to mac users, in the direction of 'you don't have to install ~2.5G of Xcode)', but some way to still allow them to pull in their own frameworks/libraries from outside that set I ship, then that seems perfect/ideal from my POV. |
@slimsag I think I've got to a good solution. It uses the b.sysroot property to cross compile to mac targets from linux. First, the zig compiler makes some assumptions about the structure of the sysroot directory. I called that "vendor file structure" here. Silent PR here it is just renames. We are still using the same three lines, but with a different file structure to enable the compiler to look for the objects to link. This may be a bug in the library resolver, but I don't think so. menduz/xcode-frameworks-pkg@55f954f + const sdk = if (b.sysroot) |sysroot| sysroot else xSdkPath("/zig-cache/xcode_frameworks");
+ b.sysroot = sdk;
- step.addLibraryPath(.{ .path = xSdkPath("/zig-cache/xcode_frameworks/lib") });
+ step.addSystemFrameworkPath(.{ .path = b.pathJoin(&.{ b.sysroot.?, "/System/Library/Frameworks" }) });
- step.addSystemIncludePath(.{ .path = xSdkPath("/zig-cache/xcode_frameworks/include") });
+ step.addSystemIncludePath(.{ .path = b.pathJoin(&.{ b.sysroot.?, "/usr/include" }) });
- step.addLibraryPath(.{ .path = xSdkPath("/zig-cache/xcode_frameworks/lib") });
+ step.addLibraryPath(.{ .path = b.pathJoin(&.{ b.sysroot.?, "/usr/lib" }) }); That does the trick. Now we can easily cross compile again. |
Thanks for explaining that @menduz - I think the problem with that approach is that using |
Wanted to mention I've added this to Mach's |
Signed-off-by: Stephen Gutekanst <[email protected]>
Signed-off-by: Stephen Gutekanst <[email protected]>
Signed-off-by: Stephen Gutekanst <[email protected]>
I ran into this as well. Like the others in this thread If I go back to a Zig release from ~August my CI works great, if I move to a newer Zig the MacOS builds break. |
FYI my comments regarding |
@slimsag OK, confirmed locally on Linux with the following changes to diff --git a/build.zig b/build.zig
index e63356f3..a936d992 100644
--- a/build.zig
+++ b/build.zig
@@ -82,14 +82,6 @@ pub fn build(b: *std.Build) void {
});
},
.macos => {
- // Transitive dependencies, explicit linkage of these works around
- // ziglang/zig#17130
- lib.linkFramework("CFNetwork");
- lib.linkFramework("ApplicationServices");
- lib.linkFramework("ColorSync");
- lib.linkFramework("CoreText");
- lib.linkFramework("ImageIO");
-
// Direct dependencies
lib.linkSystemLibrary("objc");
lib.linkFramework("IOKit"); And then, in diff --git a/build.zig.zon b/build.zig.zon
index e4908b2..a477e94 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -11,9 +11,6 @@
"README.md",
},
.dependencies = .{
- .glfw = .{
- .url = "https://pkg.machengine.org/glfw/7b1a45feeacf876428bfbd924d4aca9a9a158cd9.tar.gz",
- .hash = "122052f6e113bb8c74fceb80de8e92b6dce5792213ab703be2584bb638ec30f36edf",
- },
+ .glfw = .{ .path = "../glfw" },
},
} it builds successfully with #18677 applied:
|
Amazing! You rock! |
Uh oh!
There was an error while loading. Please reload this page.
Zig Version
0.12.0-dev.293+f33bb0228
Steps to Reproduce and Observed Behavior
https://github.com/menduz/mach-glfw/actions/runs/6164914009 <- reproduction using github actions
I'd usually dig deeper and bisect the non working versions, but I'm having trouble finding the list of releases. Instead I have two big numbers known to work and not work
0.12.0-dev.21+ac95cfe44
(works) and0.12.0-dev.293+f33bb0228
(no works).I'm not an expert in the compiler/linker code, but I smell that the problem may be related to this PR, #17030. That's why I'm tagging you @kubkon.
The error is the following:
Here is a working log:
Expected Behavior
The compiler should receive some extra arguments for frameworks.
# good /usr/local/lib/zig/zig build-exe /workspaces/mach-glfw/example/main.zig /workspaces/mach-glfw/zig-cache/o/639c138bb970d1d8ed2f85992cc244b2/libglfw.a /workspaces/mach-glfw/zig-cache/o/ffff0e5b8ab378129a9ec35b4c56c825/libvulkan-headers.a -lobjc /workspaces/mach-glfw/zig-cache/o/ffff0e5b8ab378129a9ec35b4c56c825/libvulkan-headers.a /workspaces/mach-glfw/zig-cache/o/31a83fe8d5b388726093745432f2e756/libx11-headers.a /workspaces/mach-glfw/zig-cache/o/e9e3d3b8e8fffa07062b4354f04babcd/libwayland-headers.a -lc --verbose-link --cache-dir /workspaces/mach-glfw/zig-cache --global-cache-dir /home/node/.cache/zig --name example -target aarch64-macos -mcpu generic --mod glfw::/workspaces/mach-glfw/src/main.zig --deps glfw -I /home/node/.cache/zig/p/1220fe0763e9722d56d3f93f8740e077fccf338d9697f08239d79a1ee27ae5833e62/include \ -isystem /home/node/.cache/zig/p/1220293eae4bf67a7c27a18a8133621337cde91a97bc6859a9431b3b2d4217dfb5fb/zig-cache/xcode_frameworks/include \ -I /workspaces/mach-glfw/zig-cache/i/f237565cd8e8d1d9bdd8b82de4ae04ce/include \ -I /workspaces/mach-glfw/zig-cache/i/801083cb93794881a77d1764bc388945/include \ -I /workspaces/mach-glfw/zig-cache/i/45f59e6632d069fa730b125989be9996/include \ -L /home/node/.cache/zig/p/1220293eae4bf67a7c27a18a8133621337cde91a97bc6859a9431b3b2d4217dfb5fb/zig-cache/xcode_frameworks/lib \ + -iframework /home/node/.cache/zig/p/1220293eae4bf67a7c27a18a8133621337cde91a97bc6859a9431b3b2d4217dfb5fb/zig-cache/xcode_frameworks/Frameworks \ -F /home/node/.cache/zig/p/1220293eae4bf67a7c27a18a8133621337cde91a97bc6859a9431b3b2d4217dfb5fb/zig-cache/xcode_frameworks/Frameworks \ -framework CoreFoundation -framework AppKit -framework CoreServices -framework Metal -framework CoreGraphics -framework IOKit -framework Foundation --listen=- # not good /usr/local/lib/zig/zig build-exe /workspaces/mach-glfw/example/main.zig /workspaces/mach-glfw/zig-cache/o/e0c0d01eab963d7746ec0821e4966b81/libglfw.a /workspaces/mach-glfw/zig-cache/o/624869063b9487aa0656fffb16ad422b/libvulkan-headers.a -lobjc /workspaces/mach-glfw/zig-cache/o/624869063b9487aa0656fffb16ad422b/libvulkan-headers.a /workspaces/mach-glfw/zig-cache/o/5fd3803e75d7ce137630d9994e8b5d98/libx11-headers.a /workspaces/mach-glfw/zig-cache/o/a3cbd3950fdd54726e733cbce5011c1c/libwayland-headers.a -lc --verbose-link --cache-dir /workspaces/mach-glfw/zig-cache --global-cache-dir /home/node/.cache/zig --name example -target aarch64-macos -mcpu generic --mod glfw::/workspaces/mach-glfw/src/main.zig --deps glfw -I /home/node/.cache/zig/p/1220fe0763e9722d56d3f93f8740e077fccf338d9697f08239d79a1ee27ae5833e62/include \ -F /home/node/.cache/zig/p/1220293eae4bf67a7c27a18a8133621337cde91a97bc6859a9431b3b2d4217dfb5fb/zig-cache/xcode_frameworks/Frameworks \ -isystem /home/node/.cache/zig/p/1220293eae4bf67a7c27a18a8133621337cde91a97bc6859a9431b3b2d4217dfb5fb/zig-cache/xcode_frameworks/include \ -I /workspaces/mach-glfw/zig-cache/i/dcf9574a0199c4a2d9a16e9a3e27c447/include \ -I /workspaces/mach-glfw/zig-cache/i/9f02276e6a0279a1ecb23bd7df2665e2/include \ -I /workspaces/mach-glfw/zig-cache/i/07ee617160c3200c7fa40bc5eeeb7f49/include \ -L /home/node/.cache/zig/p/1220293eae4bf67a7c27a18a8133621337cde91a97bc6859a9431b3b2d4217dfb5fb/zig-cache/xcode_frameworks/lib \ -framework CoreFoundation -framework AppKit -framework CoreServices -framework Metal -framework CoreGraphics -framework IOKit -framework Foundation --listen=-
The text was updated successfully, but these errors were encountered: