Skip to content

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

Open

Description

@kristate

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

What is the best way to do so?

Activity

  1. added this to the 0.4.0 milestone on Aug 7, 2018
  2. added
    enhancementSolving this issue will likely involve adding new logic or components to the codebase.
    on Aug 7, 2018
  3. andrewrk commented on Aug 7, 2018

    @andrewrk
    Member

    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.
  4. modified the milestones: 0.4.0, 0.5.0 on Sep 28, 2018
  5. changed the title [-]Darwin: Best way to link against CoreFoundation[/-] [+]ability to link against darwin frameworks (such as CoreFoundation) when cross compiling[/+] on Jul 2, 2019
  6. modified the milestones: 0.5.0, 0.6.0 on Jul 2, 2019
  7. modified the milestones: 0.6.0, 0.7.0 on Oct 17, 2019
  8. modified the milestones: 0.7.0, 0.8.0 on Apr 15, 2020
  9. modified the milestones: 0.8.0, 0.9.0 on Nov 6, 2020
  10. modified the milestones: 0.9.0, 0.10.0 on May 19, 2021
  11. kubkon commented on Feb 2, 2022

    @kubkon
    Member

    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
    
  12. hardillb commented on Dec 8, 2022

    @hardillb

    @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?

  13. kubkon commented on Dec 8, 2022

    @kubkon
    Member

    @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.

  14. shepherdjerred commented on Feb 28, 2023

    @shepherdjerred

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.os-macosmacOS

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions