From f961a99a35c180e90cf4cd9ae29947ccc1e0dfae Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Fri, 26 Dec 2014 01:24:42 -0500 Subject: [PATCH] misc/ios: add README and wrapper script to ease cross-compiling for darwin/arm Fixes #837. Change-Id: I2d601504addbd220b304d32d587144d2a702f753 Reviewed-on: https://go-review.googlesource.com/2127 Reviewed-by: David Crawshaw Reviewed-by: Russ Cox --- misc/ios/README | 44 +++++++++++++++++++++++++++++++++++++++++++ misc/ios/clangwrap.sh | 10 ++++++++++ 2 files changed, 54 insertions(+) create mode 100644 misc/ios/README create mode 100755 misc/ios/clangwrap.sh diff --git a/misc/ios/README b/misc/ios/README new file mode 100644 index 0000000000..417a217892 --- /dev/null +++ b/misc/ios/README @@ -0,0 +1,44 @@ +Go on iOS +========= + +To build a cross compiling toolchain for iOS on OS X, first modify clangwrap.sh +in misc/ios to match your setup. And then run: + + GOARM=7 CGO_ENABLED=1 GOARCH=arm CC_FOR_TARGET=`pwd`/../misc/ios/clangwrap.sh \ + CXX_FOR_TARGET=`pwd`/../misc/ios/clangwrap.sh ./make.bash + +To build a program, use the normal go build command: + + CGO_ENABLED=1 GOARCH=arm go build import/path + +To run a program on an iDevice, first make sure you have a valid developer +certificate and have setup your iDevice properly to run apps signed by your +developer certificate. Then install https://github.com/phonegap/ios-deploy. +At a first step, you can try building the famous hello world program to run +on your test device. +(The needed files are provided at https://github.com/minux/go-ios-examples.) + + # assume your program binary is helloworld.go, build it into the + # example hello.app bundle. + CGO_ENABLED=1 GOARCH=arm go build -o hello.app/hello helloworld.go + # sign the executable using your developer certificate + codesign -f -s "iPhone Developer" --entitlements hello.app/Entitlements.plist hello.app/hello + # run the program inside lldb on iDevice, run `ios-deploy` for more + # command options + ios-deploy --debug --uninstall --bundle hello.app + # Depending on your ios-deploy version, you might need to enter "run" + # into lldb to run your program, and its output will be shown by lldb. + +Notes: + - A dummy hello.app bundle is provided in this directory to help you get started. + - Running the program on an iDevice requires code sign and thus external linking, + if your program uses cgo, then it will automatically use external linking. + However, if your program does not use cgo, please make sure to add + import _ "runtime/cgo" + so that external linking will be used. + +Known issues +============ + - crypto/x509 won't build, I don't yet know how to get system root on iOS. + - Because I still want to be able to do native build, CGO_ENABLED=1 is not the + default, yet. diff --git a/misc/ios/clangwrap.sh b/misc/ios/clangwrap.sh new file mode 100755 index 0000000000..228f483ceb --- /dev/null +++ b/misc/ios/clangwrap.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# This uses the latest available iOS SDK, which is recommended. +# To select a specific SDK, run 'xcodebuild -showsdks' +# to see the available SDKs and replace iphoneos with one of them. +SDK=iphoneos +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` +exec $CLANG -arch armv7 -isysroot $SDK_PATH "$@" -- 2.50.0