mirror of
https://github.com/rwinkhart/cmutton.git
synced 2026-08-27 20:36:31 -04:00
Switch xcode support to Makefile-based approach
This commit is contained in:
+1
-1
@@ -2,4 +2,4 @@
|
|||||||
/cmutton.h
|
/cmutton.h
|
||||||
/testc
|
/testc
|
||||||
/a.out
|
/a.out
|
||||||
/xcode/build
|
/xcode/cmutton*
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ to export to C.
|
|||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
### Building
|
### Building
|
||||||
|
#### Generic
|
||||||
`go build -buildmode=c-archive`.
|
`go build -buildmode=c-archive`.
|
||||||
|
#### Apple Platforms (iOS/iOS Simulator/MacOS)
|
||||||
|
If building for Apple platforms, use the `Makefile` in the `xcode` directory.
|
||||||
### Functions
|
### Functions
|
||||||
All relevant exported libmutton functions have C counterparts with similar names.
|
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.
|
Functions with multiple return values all have CGO-generated structs to store the return values.
|
||||||
|
|||||||
@@ -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
|
||||||
Executable
+20
@@ -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 "$@"
|
||||||
@@ -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
|
|
||||||
Reference in New Issue
Block a user