Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ios build fixes #53

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
build/
examples/a.out
ios/
46 changes: 30 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
IOS_OUT=ios

ios-arm64:
GOOS=ios \
GOARCH=arm64 \
CGO_ENABLED=1 \
CLANGARCH=arm64 \
SDK=iphoneos \
CC=$(PWD)/clangwrap.sh \
CGO_CFLAGS="-fembed-bitcode" \
go build -buildmode=c-archive -o $(IOS_OUT)/libpolygonid-ios.a ./cmd/polygonid
MIN_VERSION=16 \
./build-ios.sh

ios-sim-arm64:
GOARCH=arm64 \
SDK=iphonesimulator \
MIN_VERSION=16 \
./build-ios.sh

ios-simulator:
GOOS=darwin \
ios-sim-amd64:
GOARCH=amd64 \
CGO_ENABLED=1 \
CLANGARCH=x86_64 \
SDK=iphonesimulator \
CC=$(PWD)/clangwrap.sh \
CGO_CFLAGS="-fembed-bitcode" \
go build -tags ios -buildmode=c-archive -o $(IOS_OUT)/libpolygonid-ios-simulator.a ./cmd/polygonid
MIN_VERSION=16 \
./build-ios.sh

darwin-arm64:
GOOS=darwin \
Expand All @@ -28,9 +25,26 @@ darwin-arm64:
CLANGARCH=arm64 \
go build -buildmode=c-archive -o $(IOS_OUT)/libpolygonid-darwin-arm64.a ./cmd/polygonid

ios: ios-arm64 ios-simulator
lipo $(IOS_OUT)/libpolygonid-ios.a $(IOS_OUT)/libpolygonid-ios-simulator.a -create -output $(IOS_OUT)/libpolygonid.a
cp $(IOS_OUT)/libpolygonid-ios.h $(IOS_OUT)/libpolygonid.h
darwin-amd64:
GOOS=darwin \
GOARCH=amd64 \
CGO_ENABLED=1 \
CLANGARCH=x86_64 \
go build -buildmode=c-archive -o $(IOS_OUT)/libpolygonid-darwin-amd64.a ./cmd/polygonid

ios-device: ios-arm64
cp $(IOS_OUT)/libpolygonid-ios-arm64.a $(IOS_OUT)/libpolygonid-ios.a
cp $(IOS_OUT)/libpolygonid-ios-arm64.h $(IOS_OUT)/libpolygonid.h

ios-simulator: ios-sim-arm64 ios-sim-amd64
lipo $(IOS_OUT)/libpolygonid-ios-sim-amd64.a $(IOS_OUT)/libpolygonid-ios-sim-arm64.a -create -output $(IOS_OUT)/libpolygonid-ios-sim.a
cp $(IOS_OUT)/libpolygonid-ios-sim-arm64.h $(IOS_OUT)/libpolygonid.h

ios: ios-device ios-simulator

darwin: darwin-arm64 darwin-amd64
lipo $(IOS_OUT)/libpolygonid-darwin-arm64.a $(IOS_OUT)/libpolygonid-darwin-amd64.a -create -output $(IOS_OUT)/libpolygonid-darwin.a
cp $(IOS_OUT)/libpolygonid-darwin-arm64.h $(IOS_OUT)/libpolygonid.h

dylib:
go build -buildmode=c-shared -o $(IOS_OUT)/libpolygonid.dylib ./cmd/polygonid
Expand Down
30 changes: 30 additions & 0 deletions build-ios.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export GOOS=ios
export CGO_ENABLED=1
export CC=$(PWD)/clangwrap.sh
export CGO_CFLAGS="-fembed-bitcode"


if [ "$GOARCH" = "amd64" ]; then
CLANGARCH="x86_64"
elif [ "$GOARCH" = "arm64" ]; then
CLANGARCH="arm64"
fi


if [ "$SDK" = "iphoneos" ]; then
export TARGET="$CLANGARCH-apple-ios$MIN_VERSION"
elif [ "$SDK" = "iphonesimulator" ]; then
export TARGET="$CLANGARCH-apple-ios$MIN_VERSION-simulator"
fi

export SDK_PATH=$(xcrun --sdk "$SDK" --show-sdk-path)

export CGO_LDFLAGS="-target ${TARGET} -syslibroot \"${SDK_PATH}\""

if [ "$SDK" = "iphoneos" ]; then
export LIB_FILE=ios/libpolygonid-ios-$CLANGARCH.a
elif [ "$SDK" = "iphonesimulator" ]; then
export LIB_FILE=ios/libpolygonid-ios-sim-$CLANGARCH.a
fi

go build -buildmode c-archive -trimpath -o $LIB_FILE ./cmd/polygonid
11 changes: 3 additions & 8 deletions clangwrap.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/bin/sh
# To select a specific SDK, run 'xcodebuild -showsdks'
# You need to specify SDK & CLANGARCH
#!/bin/zsh

SDK_PATH=`xcrun --sdk $SDK --show-sdk-path`
export IPHONEOS_DEPLOYMENT_TARGET=5.1
# cmd/cgo doesn't support llvm-gcc-4.2, so we have to use clang.
CLANG=`xcrun --sdk $SDK --find clang`
CLANG=$(xcrun --sdk "$SDK" --find clang)

exec "$CLANG" -arch $CLANGARCH -isysroot "$SDK_PATH" -mios-version-min=10.0 "$@"
exec "$CLANG" -target "$TARGET" -isysroot "$SDK_PATH" "$@"
Loading