# Universal Binary CI Pipeline for macOS Apps

Canonical: https://figment.so/blog/mac-universal-binary-ci-pipeline

Build each architecture with xcodebuild, merge with lipo -create, verify both slices, then sign. An Apple silicon host can also run the arm64 result.

**Build the arm64 and x86_64 slices with two `xcodebuild` runs, merge them with `lipo -create`, check that both slices survived, then sign the merged file.** An Apple silicon host is the better place for the merge job because the same stage can also run the arm64 slice as a smoke test. An Intel host can still produce both slices by cross-compiling, but it cannot execute the arm64 output.

## What is a universal binary and when do I need one?

A universal binary holds an x86_64 slice and an arm64 slice in one Mach-O fat file. macOS picks the matching slice at launch, so one download runs natively on every Mac. If only x86_64 is present on an Apple silicon Mac, the system runs it under Rosetta, which Apple describes in [Porting your macOS apps to Apple silicon](https://developer.apple.com/documentation/apple-silicon/porting-your-macos-apps-to-apple-silicon). Rosetta works, but it adds launch overhead and gives up native arm64 performance features.

You need a universal binary when:

- You ship a DMG or ZIP directly (outside the App Store) and want one artifact for every Mac.
- Your framework or library is linked by other apps, and forcing them to pick a slice is awkward.
- You publish a CLI through Homebrew, whose modern formula flow expects universal binaries.

Apps delivered through the Mac App Store do not need a hand-merged fat binary. Xcode archives multiple architectures at submission.

## How do I build the x86_64 and arm64 slices?

Run `xcodebuild` once per architecture, each with its own derived-data path so outputs do not collide. `ARCHS` is defined in Apple's [Build Settings Reference](https://developer.apple.com/documentation/xcode/build-settings-reference), and command-line usage is in [Technical Note TN2339](https://developer.apple.com/library/archive/technotes/tn2339/_index.html). For projects targeting Xcode 27 on Intel, Apple's [porting guide](https://developer.apple.com/documentation/apple-silicon/porting-your-macos-apps-to-apple-silicon) instructs adding `x86_64` to `ARCHS`. If you still run Xcode on an Intel host, Apple says to use Xcode 26 or earlier.

```bash
# arm64 slice
xcodebuild \
  -scheme "MyCLITool" \
  -configuration Release \
  -derivedDataPath build/derived/arm64 \
  ARCHS=arm64 \
  ONLY_ACTIVE_ARCH=NO \
  build

# x86_64 slice
xcodebuild \
  -scheme "MyCLITool" \
  -configuration Release \
  -derivedDataPath build/derived/x86_64 \
  ARCHS=x86_64 \
  ONLY_ACTIVE_ARCH=NO \
  build
```

Replace `MyCLITool` with the scheme name that `xcodebuild -list` reports for your project. `ONLY_ACTIVE_ARCH=NO` makes xcodebuild honour `ARCHS` instead of defaulting to the host architecture, which is what allows cross-architecture compilation from one machine.

## How do I run both builds in parallel?

Use your CI system's matrix or fan-out feature. This GitHub Actions example builds both architectures in parallel and merges in a dependent job:

```yaml
jobs:
  build-slice:
    runs-on: [self-hosted, macOS, arm64]   # your Apple silicon runner
    strategy:
      fail-fast: true
      matrix:
        arch: [arm64, x86_64]
    steps:
      - uses: actions/checkout@v4
      - name: Build ${{ matrix.arch }} slice
        run: |
          set -euo pipefail
          xcodebuild \
            -scheme MyCLITool \
            -configuration Release \
            -derivedDataPath build/derived/${{ matrix.arch }} \
            ARCHS=${{ matrix.arch }} ONLY_ACTIVE_ARCH=NO \
            build
          cp "build/derived/${{ matrix.arch }}/Build/Products/Release/MyCLITool" \
             "MyCLITool-${{ matrix.arch }}"
      - uses: actions/upload-artifact@v4
        with:
          name: slice-${{ matrix.arch }}
          path: MyCLITool-${{ matrix.arch }}

  merge:
    needs: build-slice
    runs-on: [self-hosted, macOS, arm64]
    steps:
      - uses: actions/download-artifact@v4
        with: { pattern: slice-*, merge-multiple: true }
      - run: make universal
```

`set -euo pipefail` and `fail-fast: true` make a failed xcodebuild abort the pipeline instead of being counted as a quick success in later timing reports.

## How do I merge the slices with lipo?

`lipo -create` takes two or more architecture-specific Mach-O files and produces a fat binary:

```bash
lipo -create \
  MyCLITool-arm64 \
  MyCLITool-x86_64 \
  -output MyCLITool-universal
```

For a `.app` bundle, the merge target is the main executable under `Contents/MacOS/`. If the bundle also contains helper tools, dylibs or embedded `.framework` executables, merge every Mach-O file individually. The Makefile below handles a single-binary CLI tool. For app bundles, list the Mach-O files with `find Contents -type f -exec file {} +` and merge each one.

## How do I verify and re-sign the merged binary?

Check that both slices survived, then sign. `lipo` creates a new file, so any signature on the individual slices is gone, and signing must happen after the merge.

```bash
set -euo pipefail

lipo -info MyCLITool-universal | grep -qw "arm64"  || { echo "FAIL: arm64 missing";  exit 1; }
lipo -info MyCLITool-universal | grep -qw "x86_64" || { echo "FAIL: x86_64 missing"; exit 1; }

# Re-sign the merged binary. Use your Developer ID identity for distribution;
# the keychain and private key must already be unlocked in this job via your
# CI secret manager (never commit certificate files or paste secrets into env).
codesign --force --timestamp --options=runtime --sign "$DEVELOPER_ID_IDENTITY" MyCLITool-universal
codesign -v --strict MyCLITool-universal
```

## What does a Makefile for the whole pipeline look like?

Drop this at the repo root and run `make universal`. Set `SCHEME` to the value `xcodebuild -list` prints for your project.

```makefile
# Makefile - universal binary pipeline
SCHEME    := MyCLITool
CONFIG    := Release
DERIVED   := build/derived
PRODUCTS  := build/products

.PHONY: arm64-slice x86_64-slice universal clean

$(PRODUCTS):
	mkdir -p $@

arm64-slice: | $(PRODUCTS)
	set -euo pipefail; \
	xcodebuild \
	  -scheme "$(SCHEME)" \
	  -configuration "$(CONFIG)" \
	  -derivedDataPath "$(DERIVED)/arm64" \
	  ARCHS=arm64 ONLY_ACTIVE_ARCH=NO \
	  build
	cp "$(DERIVED)/arm64/Build/Products/$(CONFIG)/$(SCHEME)" \
	   "$(PRODUCTS)/$(SCHEME)-arm64"

x86_64-slice: | $(PRODUCTS)
	set -euo pipefail; \
	xcodebuild \
	  -scheme "$(SCHEME)" \
	  -configuration "$(CONFIG)" \
	  -derivedDataPath "$(DERIVED)/x86_64" \
	  ARCHS=x86_64 ONLY_ACTIVE_ARCH=NO \
	  build
	cp "$(DERIVED)/x86_64/Build/Products/$(CONFIG)/$(SCHEME)" \
	   "$(PRODUCTS)/$(SCHEME)-x86_64"

universal: arm64-slice x86_64-slice
	@echo "-> Merging slices with lipo..."
	lipo -create \
	  "$(PRODUCTS)/$(SCHEME)-arm64" \
	  "$(PRODUCTS)/$(SCHEME)-x86_64" \
	  -output "$(PRODUCTS)/$(SCHEME)"
	@echo "-> Verifying both slices..."
	@lipo -info "$(PRODUCTS)/$(SCHEME)" | grep -qw "arm64" \
	  || { echo "FAIL: arm64 slice missing after merge"; exit 1; }
	@lipo -info "$(PRODUCTS)/$(SCHEME)" | grep -qw "x86_64" \
	  || { echo "FAIL: x86_64 slice missing after merge"; exit 1; }
	@echo "PASS: $(PRODUCTS)/$(SCHEME) is a valid universal binary."
	@echo "      Next: sign with Developer ID, then package with dmgbuild."

clean:
	rm -rf build
```

This is an example, not a benchmark. Run it on your own project before wiring it into CI. Derived-data paths differ if you override `CONFIGURATION_BUILD_DIR` in an xcconfig.

## Which Figment Mac plan fits the merge job?

The merge job only needs `lipo`, `codesign` and `dmgbuild`, which run on any Mac. The choice depends on whether the same stage must execute the arm64 output.

| Figment plan | Builds arm64 slice | Builds x86_64 slice | Runs arm64 output |
|---|---|---|---|
| [Intel Mac VM](/mac-hosting#intel-vm) ($25/month) | Yes, cross-compiled with Xcode 26.0 to 26.3 (the range Apple lists for macOS Sequoia) | Yes, natively | No |
| [Apple Silicon Mac VM](/mac-hosting#apple-silicon-vm) ($39/month) | Yes, natively | Yes, via `ARCHS=x86_64` | Yes |
| [Dedicated M4 Pro 48 GB](/mac-hosting#dedicated-m4-pro) ($349/month) | Yes, natively | Yes, via `ARCHS=x86_64` | Yes |

Choose the Intel VM for cheap cross-compiled builds that stop at artifact production. Choose an Apple silicon plan when the stage also runs integration tests, UI smoke tests or Rosetta-versus-native checks on the arm64 output, or when you need Xcode 26.4 or later. VM vCPUs are shared, not reserved cores. The Apple Silicon VM has 4 shared vCPUs, 4GB RAM and 65GB SSD. The Dedicated M4 Pro 48 GB is a whole Mac (M4 Pro, 48GB RAM, 512GB SSD).

## How does the cost compare with another host?

[CloudMac](https://cloudmac.org/pricing) publishes an M4 with 16 GB RAM and 256 GB SSD at $99.99/month, and [an annual rate of $999/year](https://cloudmac.org/) (about $83.25/month effective). Over twelve months that is 12 x $99.99 = $1,199.88 monthly or $999 prepaid. Figment's Apple Silicon Mac VM is 12 x $39 = $468, and the Dedicated M4 Pro 48 GB is $3,228 paid up front, or 12 x $299 = $3,588 on a 12-month term. The hardware differs: CloudMac lists a whole Mac with 16 GB, the Figment VM has shared vCPUs and 4GB, and the Dedicated M4 Pro is a whole Mac with 48GB.

**Related guides:**

- [Sign iOS Builds with App Store Connect API Key](/blog/mac-app-store-connect-api-ci-signing)
- [Rotate Provisioning Profiles in CI Safely](/blog/mac-provisioning-profile-rotation-ci)
- [Xcode on Windows: Remote Mac Setup](/blog/mac-xcode-on-windows-remote-setup)
