Convert Figma logo to code with AI

tpoechtrager logoosxcross

MacOS Cross-Toolchain for Linux and *BSD

3,107
337
3,107
135

Top Related Projects

A versatile (cross-)toolchain generator.

10,123

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.

Quick Overview

The tpoechtrager/osxcross project is a cross-compilation toolchain that allows developers to build applications for macOS on non-macOS platforms, such as Linux or Windows. It provides a comprehensive set of tools and libraries to simplify the process of cross-compiling for the macOS platform.

Pros

  • Cross-Platform Compilation: Enables developers to build macOS applications on various operating systems, including Linux and Windows, without the need for a dedicated macOS machine.
  • Comprehensive Toolchain: Includes a wide range of tools and libraries, such as the Clang compiler, the LLVM toolchain, and various macOS SDK versions, to ensure a complete cross-compilation environment.
  • Automated Setup: Provides a streamlined setup process, with scripts and configuration files to automate the installation and configuration of the cross-compilation toolchain.
  • Flexibility: Supports multiple macOS SDK versions, allowing developers to target different versions of the macOS operating system.

Cons

  • Complexity: The setup process, while automated, can still be complex and time-consuming, especially for developers new to cross-compilation.
  • Maintenance: The project requires ongoing maintenance to keep up with the latest macOS SDK versions and compiler updates, which can be a burden for some users.
  • Limited Documentation: The project's documentation, while generally helpful, could be more comprehensive and easier to navigate for new users.
  • Potential Compatibility Issues: Depending on the specific requirements of the project, there may be compatibility issues with certain libraries or frameworks when cross-compiling for macOS.

Getting Started

To get started with tpoechtrager/osxcross, follow these steps:

  1. Clone the repository:
git clone https://github.com/tpoechtrager/osxcross.git
  1. Change to the project directory:
cd osxcross
  1. Run the setup script to download and configure the necessary tools and libraries:
./build.sh
  1. Once the setup is complete, you can use the osxcross toolchain to compile your macOS applications. For example, to compile a simple C program:
$OSX_CROSS_ENV/bin/x86_64-apple-darwin19-clang hello.c -o hello

This will generate a macOS-compatible binary that can be executed on a macOS system.

Competitor Comparisons

A versatile (cross-)toolchain generator.

Pros of crosstool-ng/crosstool-ng

  • Supports a wide range of target architectures and operating systems, including Linux, macOS, and Windows.
  • Provides a modular and customizable build system, allowing users to select the specific components they need.
  • Offers a well-documented and active community, with a large number of contributed toolchain configurations.

Cons of crosstool-ng/crosstool-ng

  • The build process can be more complex and time-consuming compared to tpoechtrager/osxcross, especially for users who are new to cross-compilation.
  • The configuration options can be overwhelming, and it may take some time to understand the different components and how they interact.
  • The project's focus is on cross-compilation in general, rather than being specifically tailored for macOS development.

Code Comparison

Here's a brief comparison of the build process for both projects:

crosstool-ng/crosstool-ng:

$ ./configure --enable-local
$ make
$ make install

tpoechtrager/osxcross:

$ ./build.sh

As you can see, the crosstool-ng build process is more involved, requiring configuration and multiple make commands, while tpoechtrager/osxcross provides a more streamlined build script.

10,123

Pros of gcc-mirror/gcc

  • Comprehensive collection of GCC source code, including all historical versions and branches.
  • Active development and maintenance by a large community of contributors.
  • Extensive documentation and resources available for GCC development and usage.

Cons of gcc-mirror/gcc

  • Primarily focused on the GCC compiler itself, without additional cross-compilation tools or support.
  • May require more setup and configuration to use for cross-compilation tasks compared to tpoechtrager/osxcross.

Code Comparison

Here's a brief code comparison between the two repositories:

tpoechtrager/osxcross:

#!/bin/bash

# Set the target platform
export UNIXNAME=darwin
export ARCH=x86_64

# Build the cross-compiler
./build.sh

gcc-mirror/gcc:

#!/bin/bash

# Configure the GCC build
./configure --prefix=/usr/local --enable-languages=c,c++

# Build GCC
make -j$(nproc)

# Install GCC
make install

The tpoechtrager/osxcross script sets the target platform and builds the cross-compiler, while the gcc-mirror/gcc script configures, builds, and installs the GCC compiler itself.

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.

Pros of llvm/llvm-project

  • Comprehensive and actively maintained project covering the entire LLVM ecosystem
  • Extensive documentation and community support
  • Supports a wide range of target architectures and platforms

Cons of llvm/llvm-project

  • Larger codebase and more complex to build and configure
  • May have a steeper learning curve for newcomers
  • Potentially slower development cycles compared to smaller, more focused projects

Code Comparison

llvm/llvm-project (Clang):

int main(int argc, char *argv[]) {
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
    return 1;
  }

  // Perform Clang-based compilation
  return 0;
}

tpoechtrager/osxcross:

#!/bin/bash

# Set up environment variables
export UNATTENDED=1
export OSXCROSS_RELEASE_BUILD=1

# Build the cross-compiler
./build.sh

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

macOS Cross-Toolchain for Linux and *BSD

OSXCross branches:

master:

  • Uses cctools 986 and ld64 711. Known to be stable and well-working.

2.0-llvm-based:

  • OSXCross based on LLVM tools.
    Easiest to build and recommended for new projects.
    Does not support building for i386.

testing:

  • Uses the latest versions of cctools and ld64 — currently cctools 1024.3 and ld64 955.13.
    Takes the longest to build due to additional dependencies introduced in the latest versions.

ppc-test:

  • An older branch with support for PPC targets.

What is OSXCross

OSXCross provides a macOS cross-compilation toolchain.

Supported OSes and architectures

  • Host OSes: Linux, *BSD
  • Host architectures: x86, x86_64, ARM, AArch64/arm64
  • Target architectures: arm64, arm64e, x86_64, i386

How It Works

macOS cross-compilation requires:

  • Clang/LLVM (cross-compilation supported by default)
  • A macOS SDK

This branch of OSXCross uses cctools-port. cctools-port provides toolchain tools such as ar, lipo, otool, and ld64 as linker.

OSXCross provides a set of scripts for preparing the SDK, building cctools-port (along with its dependencies), and compiling the compiler wrapper.

It also includes scripts for optionally building:

  • Up-to-date LLVM tools and clang (./build_clang.sh, ./build_apple_clang.sh)
  • Vanilla GCC as a cross-compiler for target macOS (./build_gcc.sh
  • The "compiler-rt" runtime library (./build_compiler_rt.sh)

Package Manager

A minimal MacPorts package manager is included. See README.MACPORTS.md.


Installation

Place your packaged SDK in the tarballs/ directory.

Install the following dependencies:

clang cmake git patch python libssl-dev lzma-dev libxml2-dev xz bzip2 cpio libbz2 zlib1g-dev bash

Optional:

  • llvm-dev: For Link Time Optimization support and ld64 -bitcode_bundle support
  • uuid-dev: For ld64 -random_uuid support

You can run sudo tools/get_dependencies.sh to get these (and the optional packages) automatically. (outdated)

Build Clang (Optional - if you need an up-to-date version of LLVM/Clang)

./build_clang.sh                           # Builds mainline Clang
./build_apple_clang.sh                     # Builds Apple's Clang
INSTALLPREFIX=/opt/clang ./build_clang.sh  # Custom install path

Build OSXCross

By default, this installs the osxcross toolchain into <current-directory>/target.
To specify a different installation path or run the build unattended,
set the TARGET_DIR and/or UNATTENDED environment variables accordingly.

./build.sh 
[TARGET_DIR=/usr/local/osxcross] [OSX_VERSION_MIN=XX.X] [UNATTENDED=1] ./build.sh 

Add <target>/bin to your PATH after installation.

Build GCC (Optional)

./build_gcc.sh
GCC_VERSION=5.2.0 ENABLE_FORTRAN=1 ./build_gcc.sh

Install GCC dependencies:

sudo apt-get install gcc g++ zlib1g-dev libmpc-dev libmpfr-dev libgmp-dev

Notes:

  • To enable -Werror=implicit-function-declaration, set OSXCROSS_ENABLE_WERROR_IMPLICIT_FUNCTION_DECLARATION=1
  • To disable static linking: OSXCROSS_GCC_NO_STATIC_RUNTIME=1
  • *-g++-libc++ uses Clang's libc++ — only use if needed

Packaging the SDK

Please ensure you have read and understood the Xcode license terms before continuing.

SDKs can be extracted either from the full Xcode or from the Xcode Command Line Tools.

On macOS

From Full Xcode

  1. Download Xcode
  2. Mount Xcode.dmg (Right-click → Open With → DiskImageMounter)
    • If you see a crossed-circle dialog when mounting, ignore it — installation of Xcode is not required
  3. Run: ./tools/gen_sdk_package.sh (from the OSXCross package)
  4. Copy the resulting SDK (*.tar.* or *.pkg) to a USB stick
  5. On Linux/BSD, move the SDK to the tarballs/ directory of OSXCross

From Command Line Tools

  1. Download Command Line Tools
  2. Mount the Command_Line_Tools_for_Xcode.dmg (Open With → DiskImageMounter)
  3. Install Command Line Tools.pkg (Open With → Installer)
  4. Run: ./tools/gen_sdk_package_tools.sh
  5. Copy the resulting SDK (*.tar.* or *.pkg) to a USB stick
  6. On Linux/BSD, move the SDK to the tarballs/ directory of OSXCross

On Linux (and others)

Method 1 (Xcode > 8.0)
Requires up to 45 GB free disk space. SSD strongly recommended.

  1. Download Xcode as described above
  2. Install: clang, make, libssl-devel, lzma-devel, and libxml2-devel
  3. Run: ./tools/gen_sdk_package_pbzx.sh <xcode>.xip
  4. Move the SDK to the tarballs/ directory

Method 2 (up to Xcode 7.3)

  1. Download Xcode as described above
  2. Install: cmake, libxml2-dev, and fuse
  3. Run: ./tools/gen_sdk_package_darling_dmg.sh <xcode>.dmg
  4. Move the SDK to the tarballs/ directory

Method 3 (up to Xcode 7.2)

  1. Download Xcode as described above
  2. Ensure clang and make are installed
  3. Run: ./tools/gen_sdk_package_p7zip.sh <xcode>.dmg
  4. Move the SDK to the tarballs/ directory

Method 4 (Xcode 4.2)

  1. Download Xcode 4.2 for Snow Leopard (ensure it's the correct version)
  2. Install dmg2img
  3. As root, run: ./tools/mount_xcode_image.sh /path/to/xcode.dmg
  4. Follow the on-screen instructions from the script
  5. Move the SDK to the tarballs/ directory

From Xcode Command Line Tools

  1. Download Command Line Tools as described above
  2. Install: clang, make, libssl-devel, lzma-devel, and libxml2-devel
  3. Run: ./tools/gen_sdk_package_tools_dmg.sh <command_line_tools_for_xcode>.dmg
  4. Move the SDK to the tarballs/ directory

Usage Examples

Compile test.cpp

  • i386: i386-apple-darwinXX-clang++ test.cpp -O3 -o test (if your SDK supports i386)
  • x86_64: x86_64-apple-darwinXX-clang++ test.cpp -O3 -o test
  • arm64: arm64-apple-darwinXX-clang++ test.cpp -O3 -o test
  • arm64e: arm64e-apple-darwinXX-clang++ test.cpp -O3 -o test

Or by using xcrun:

  • i386: xcrun clang++ -arch x86_64 test.cpp -O3 -o test
  • x86_64: xcrun clang++ -arch x86_64 test.cpp -O3 -o test
  • arm64: xcrun clang++ -arch arm64 test.cpp -O3 -o test
  • arm64e: xcrun clang++ -arch arm64e test.cpp -O3 -o test

GCC: Replace clang++ with g++ as needed

Check your target version with osxcross-conf, see TARGET.

Build Makefile project

xcrun -f clang prints the path to clang.

make CC=$(xcrun -f clang) CXX=$(xcrun -f clang++)

Build autotools project

CC=x86_64-apple-darwinXX-clang CXX=x86_64-apple-darwinXX-clang++ ./configure --host=x86_64-apple-darwinXX

libc++ Example (macOS 10.7+ required)

xcrun clang++ -stdlib=libc++ -std=c++11 test.cpp -o test

Shortcut:

x86_64-apple-darwinXX-clang++-libc++ -std=c++11 test.cpp -o test

LTO Example

xcrun clang++ test1.cpp -O3 -flto -c
xcrun clang++ test2.cpp -O3 -flto -c
xcrun clang++ -O3 -flto test1.o test2.o -o test

Universal Binary

xcrun clang++ test.cpp -O3 -arch x86_64 -arch arm64 -o test

GCC:

xcrun g++ -arch x86_64 test.cpp -O3 -o test.x86_64
xcrun g++ -arch arm64 test.cpp -O3 -o test.arm64
xcrun lipo -create test.x86_64 test.arm64 -output test

Deployment Target

Default:

  • SDK ≤ 10.13 → macOS 10.6
  • SDK ≥ 10.14 → macOS 10.9
  • SDK ≥ 14.0 → macOS 10.13

Can be overriden via:

  1. During the build: OSX_VERSION_MIN=XX.X ./build.sh.
  2. By passing -mmacos-version-min=XX.X to the compiler.
  3. By setting MACOSX_DEPLOYMENT_TARGET=XX.X env var.

Note: Deployment target ≥ 10.9 defaults to libc++.
Can be explicitely overriden by setting the C++ library to libstdc++ via -stdlib=libstdc++.


Projects Using OSXCross

  • multiarch/crossbuild:
    various cross-compilers
    (Systems: Linux, macOS, Windows, Archs: x86_64,i386, arm, ppc, mips)
    in Docker. OSXCross powers the Darwin builds.
  • Smartmontools

License

  • scripts/wrapper: GPLv2
  • cctools/ld64: APSL 2.0 (legacy)
  • xar: New BSD