Skip to content

Use -isysroot on Catalina too, not just Big Sur #7957

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

Merged
merged 1 commit into from
Feb 7, 2021

Conversation

mk12
Copy link
Contributor

@mk12 mk12 commented Feb 5, 2021

I am writing a Zig program on macOS Catalina 10.15.7 that uses system frameworks.

Under Zig 0.7.1, I had to use this workaround otherwise it wouldn't find framework headers such as #include <Carbon/Carbon.h>:

fn getMacFrameworksDir(b: *Builder) ![]u8 {
    const sdk = try b.exec(&[_][]const u8{ "xcrun", "--show-sdk-path" });
    const parts = &[_][]const u8{
        std.mem.trimRight(u8, sdk, "\n"),
        "/System/Library/Frameworks",
    };
    return std.mem.concat(b.allocator, u8, parts);
}

pub fn build(b: *Builder) !void {
    // ...
    exe.addFrameworkDir(try getMacFrameworksDir(b));
    // ...
}

I then switched to tip-of-tree Zig (8661a13, zig version is 0.8.0-dev.1118+8661a13b7) which I built from source using Option A, and it stopped working — with or without my workaround. However, after applying this patch to make main.zig use -isysroot on Catalina or later, it worked, and I don't need the workaround anymore.

This was already done in #7506, but only for Big Sur or later. This PR just expands the check to include Catalina.

(Or, maybe we should just always attempt getSDKPath on macOS? Threads complaining about these headers moving go back years, so I'm not sure if Catalina is the earliest where it can happen.)

Related issues: #7697, #2208

@mikdusan
Copy link
Member

mikdusan commented Feb 5, 2021

Big Sur forced zig to use xcrun --show-sdk-path because no headers or linking was possible without it. Technically speaking, if memory serves, Catalina was the first macOS to ship without /usr/include but it still had system .dylib available in the normal filesystem. And some developers forced cmdlinetools to install headers with a manual switch but it was not recommended.

Thus I'm inclined to include Catalina in automatic SDK detection and use.

This amends ziglang#7506 to apply to macOS versions since Catalina (10.15),
rather than since Big Sur (11.0).
@mikdusan
Copy link
Member

mikdusan commented Feb 7, 2021

looks good. Thanks!

@mikdusan mikdusan merged commit 905c85b into ziglang:master Feb 7, 2021
@mk12 mk12 deleted the catalina branch February 7, 2021 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants