Switch xcode support to Makefile-based approach

This commit is contained in:
2026-02-01 17:28:01 -05:00
parent e0f126cc3e
commit 7a5490396c
5 changed files with 68 additions and 27 deletions
+1 -1
View File
@@ -2,4 +2,4 @@
/cmutton.h
/testc
/a.out
/xcode/build
/xcode/cmutton*
+3
View File
@@ -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.
+44
View File
@@ -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
+20
View File
@@ -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 "$@"
-26
View File
@@ -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