From 7a5490396cf0f7983a10e17664733af64cbc1042 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sun, 1 Feb 2026 17:28:01 -0500 Subject: [PATCH] Switch xcode support to Makefile-based approach --- .gitignore | 2 +- README.md | 3 +++ xcode/Makefile | 44 +++++++++++++++++++++++++++++++++++++++++++ xcode/clangwrap.sh | 20 ++++++++++++++++++++ xcode/genXCModule.zsh | 26 ------------------------- 5 files changed, 68 insertions(+), 27 deletions(-) create mode 100644 xcode/Makefile create mode 100755 xcode/clangwrap.sh delete mode 100755 xcode/genXCModule.zsh diff --git a/.gitignore b/.gitignore index 8821164..c98686b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ /cmutton.h /testc /a.out -/xcode/build +/xcode/cmutton* diff --git a/README.md b/README.md index d832199..cc22002 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,10 @@ to export to C. # Usage ### Building +#### Generic `go build -buildmode=c-archive`. +#### Apple Platforms (iOS/iOS Simulator/MacOS) +If building for Apple platforms, use the `Makefile` in the `xcode` directory. ### Functions All relevant exported libmutton functions have C counterparts with similar names. Functions with multiple return values all have CGO-generated structs to store the return values. diff --git a/xcode/Makefile b/xcode/Makefile new file mode 100644 index 0000000..8ea8c92 --- /dev/null +++ b/xcode/Makefile @@ -0,0 +1,44 @@ +clean: + rm -rf ./cmutton* + +ios-hw: + CGO_ENABLED=1 \ + GOOS=darwin \ + GOARCH=arm64 \ + SDK=iphoneos \ + CC=$(PWD)/clangwrap.sh \ + CGO_CFLAGS="-fembed-bitcode" \ + go build -buildmode=c-archive -tags ios -o ./cmutton-ios-hw.a .. + +ios-sim: + CGO_ENABLED=1 \ + GOOS=darwin \ + GOARCH=arm64 \ + SDK=iphonesimulator \ + CC=$(PWD)/clangwrap.sh \ + go build -buildmode=c-archive -tags ios -o ./cmutton-ios-sim.a .. + +macos: + CGO_ENABLED=1 \ + GOOS=darwin \ + GOARCH=arm64 \ + SDK=macosx \ + go build -buildmode=c-archive -o ./cmutton-macos-arm64.a .. + +ios: ios-hw ios-sim + xcodebuild -create-xcframework \ + -library ./cmutton-ios-hw.a \ + -headers ./cmutton-ios-hw.h \ + -library ./cmutton-ios-sim.a \ + -headers ./cmutton-ios-sim.h \ + -output ./cmutton.xcframework + +apple: ios-hw ios-sim macos + xcodebuild -create-xcframework \ + -library ./cmutton-ios-hw.a \ + -headers ./cmutton-ios-hw.h \ + -library ./cmutton-ios-sim.a \ + -headers ./cmutton-ios-sim.h \ + -library ./cmutton-macos-arm64.a \ + -headers ./cmutton-macos-arm64.h \ + -output ./cmutton.xcframework diff --git a/xcode/clangwrap.sh b/xcode/clangwrap.sh new file mode 100755 index 0000000..1914b01 --- /dev/null +++ b/xcode/clangwrap.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +MIN_VERSION=26.0 + +SDK_PATH=`xcrun --sdk $SDK --show-sdk-path` +CLANG=`xcrun --sdk $SDK --find clang` + +if [ "$SDK" = "iphoneos" ]; then + export TARGET="-target $CARCH-apple-ios$MIN_VERSION" +elif [ "$SDK" = "iphonesimulator" ]; then + export TARGET="-target $CARCH-apple-ios$MIN_VERSION-simulator" +fi + +if [ "$GOARCH" == "amd64" ]; then + CARCH="x86_64" +elif [ "$GOARCH" == "arm64" ]; then + CARCH="arm64" +fi + +exec $CLANG -arch $CARCH $TARGET -isysroot $SDK_PATH -mios-version-min=$MIN_VERSION "$@" diff --git a/xcode/genXCModule.zsh b/xcode/genXCModule.zsh deleted file mode 100755 index 4679de0..0000000 --- a/xcode/genXCModule.zsh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env zsh -# TODO Support iOS simulator - -# setup working dirs w/modulemap -rm -rf ./build -mkdir -p ./build/{ios,macos} -echo "module cmutton { - header "cmutton.h" - link "cmutton" - export * -}" > ./build/{ios,macos}/module.modulemap - -# cd to Go source -cd .. - -# build static archive for all platforms -## iOS -CGO_ENABLED=1 GOOS=ios SDK=iphoneos go build -buildmode=c-archive -mv ./{cmutton.a,cmutton.h} ./xcode/build/ios/ -cp ./types.h ./xcode/build/ios/ -## macOS -CGO_ENABLED=1 GOOS=darwin go build -buildmode=c-archive -mv ./{cmutton.a,cmutton.h} ./xcode/build/macos/ -cp ./types.h ./xcode/build/macos/ - -cd ./xcode