Skip to content

Commit 8bfffaa

Browse files
committed
Change build script to make a universal binary
1 parent a783fd1 commit 8bfffaa

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

ax/Makefile

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
1-
build:
2-
swift build -c release
1+
# Makefile for ax Swift utility
32

4-
run:
5-
swift run -c release
3+
# Variables
4+
SWIFT_BUILD_DIR := .build/apple/Products/Release
5+
UNIVERSAL_BINARY_NAME := ax
6+
UNIVERSAL_BINARY_PATH := $(SWIFT_BUILD_DIR)/$(UNIVERSAL_BINARY_NAME)
7+
FINAL_BINARY_PATH := $(CURDIR)/$(UNIVERSAL_BINARY_NAME)
8+
9+
# Default target
10+
all: $(FINAL_BINARY_PATH)
11+
12+
# Build the universal binary, strip it, and place it in the ax/ directory
13+
$(FINAL_BINARY_PATH): $(UNIVERSAL_BINARY_PATH)
14+
@echo "Copying stripped universal binary to $(FINAL_BINARY_PATH)"
15+
@cp $(UNIVERSAL_BINARY_PATH) $(FINAL_BINARY_PATH)
16+
@echo "Final binary ready at $(FINAL_BINARY_PATH)"
17+
18+
$(UNIVERSAL_BINARY_PATH):
19+
@echo "Building universal binary for $(UNIVERSAL_BINARY_NAME) (arm64 + x86_64) with size optimization (Osize, ThinLTO, dead_strip)..."
20+
@swift build -c release --arch arm64 --arch x86_64 -Xswiftc -Osize -Xswiftc -lto=llvm-thin -Xcc -Wl,-dead_strip
21+
@echo "Stripping symbols from $(UNIVERSAL_BINARY_PATH)..."
22+
@strip $(UNIVERSAL_BINARY_PATH)
23+
@echo "Universal binary built and stripped at $(UNIVERSAL_BINARY_PATH)"
24+
25+
# Clean build artifacts
26+
clean:
27+
@echo "Cleaning build artifacts..."
28+
@rm -rf .build $(FINAL_BINARY_PATH)
29+
@echo "Clean complete."
30+
31+
.PHONY: all clean

ax/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let package = Package(
1212
// Targets are the basic building blocks of a package, defining a module or a test suite.
1313
// Targets can depend on other targets in this package and products from dependencies.
1414
.executableTarget(
15-
name: "x",
15+
name: "ax",
1616
swiftSettings: [
1717
.unsafeFlags(["-framework", "ApplicationServices", "-framework", "AppKit"])
1818
]

ax/ax_runner.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22
# Simple wrapper script to catch signals and diagnose issues
33

4-
exec ./.build/release/x "$@"
4+
exec ./ax "$@"

0 commit comments

Comments
 (0)