Skip to content
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

ability to link against darwin frameworks (such as CoreFoundation) when cross compiling #1349

Open
kristate opened this issue Aug 7, 2018 · 5 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. os-macos
Milestone

Comments

@kristate
Copy link
Contributor

kristate commented Aug 7, 2018

The std library now has code that must be linked against CoreFoundation on macOS and iOS.

What is the best way to do so?

kristate added a commit to kristate/zig that referenced this issue Aug 7, 2018
@andrewrk andrewrk added this to the 0.4.0 milestone Aug 7, 2018
@andrewrk andrewrk added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Aug 7, 2018
@andrewrk
Copy link
Member

andrewrk commented Aug 7, 2018

Here's what we need to accomplish:

  • Ability to link against darwin frameworks when cross-compiling, without any kind of SDK installed.
  • Only link against frameworks that are actually used. This is currently accomplished for dynamic libraries with the extern "libname" syntax.

@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Sep 28, 2018
@andrewrk andrewrk changed the title Darwin: Best way to link against CoreFoundation ability to link against darwin frameworks (such as CoreFoundation) when cross compiling Jul 2, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Jul 2, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Oct 17, 2019
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Apr 15, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@kubkon
Copy link
Member

kubkon commented Feb 2, 2022

Zig, and zig ld in particular, has the ability to link against frameworks when cross-compiling, however, a copy of the Darwin's sysroot (also called the SDK) is not bundled with Zig installation, therefore it is necessary to provide Zig valid paths to the sysroot and any search directories that may be required.

A typical invocation may look as follows,

$ zig cc -target aarch64-macos --sysroot=/home/kubkon/macos-SDK -I/usr/include -L/usr/lib -F/System/Library/Frameworks -framework CoreFoundation -o hello hello.c

@hardillb
Copy link

hardillb commented Dec 8, 2022

@kubkon I suspect the answer to this will be "Copy it from a Mac" but...

Any hints on where to get a sysroot bundle for MacOS?

If the answer is copy it, do you know where I can get a list of what bits I need to grab?

@kubkon
Copy link
Member

kubkon commented Dec 8, 2022

@kubkon I suspect the answer to this will be "Copy it from a Mac" but...

Any hints on where to get a sysroot bundle for MacOS?

If the answer is copy it, do you know where I can get a list of what bits I need to grab?

You can get macOS 12 SDK from Hexops for example. If you are looking for an older SDK version, you can get it here. In general tho, if you have a Mac, you just need to grab whatever xcrun --sdk macosx --show-sdk-path. Finally, there is also this website I am aware of but downloading the SDKs may require an active Apple Developer account: xcodereleases.com.

@shepherdjerred
Copy link

I got zig to cross-compile targeting aarch64 macOS on a Ubuntu Jammy host.

sdk contains a macOS SDK. Instructions on doing this can be found on the osxcross project. I packaged the SDK, and then unzipped it into sdk

Dockerfile:

  FROM ubuntu:jammy
  COPY sdk /sdk
  RUN apt update
  RUN apt install -y wget xz-utils
  WORKDIR /workspace
  RUN wget -O zig.tar.xz https://ziglang.org/download/0.10.1/zig-linux-aarch64-0.10.1.tar.xz
  RUN tar -xf zig.tar.xz
  RUN rm zig.tar.xz
  RUN mv zig* zig
  ENV PATH=$PATH:/workspace/zig
  COPY samples samples
  RUN zig cc -target aarch64-macos --sysroot=/sdk -I/sdk/usr/include -L/sdk/usr/lib -F/sdk/System/Library/Frameworks -framework CoreFoundation -o hello-c samples/hello.c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. os-macos
Projects
None yet
Development

No branches or pull requests

5 participants