Commit 25f73db0 authored by Elias Naur's avatar Elias Naur

misc/ios: update documentation for running iOS programs and tests

Change-Id: I8e3077ab9c7dff66877ac00dc4600b53c07eb1f8
Reviewed-on: https://go-review.googlesource.com/112655Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 599f56dc
Go on iOS Go on iOS
========= =========
To build a cross compiling toolchain for iOS on OS X, first modify clangwrap.sh For details on developing Go for iOS on macOS, see the documentation in the mobile
in misc/ios to match your setup. And then run: subrepository:
GOARM=7 CGO_ENABLED=1 GOARCH=arm CC_FOR_TARGET=`pwd`/../misc/ios/clangwrap.sh \ https://github.com/golang/mobile
CXX_FOR_TARGET=`pwd`/../misc/ios/clangwrap.sh ./make.bash
It is necessary to set up the environment before running tests or programs directly on a
To build a program, use the normal go build command: device.
CGO_ENABLED=1 GOARCH=arm go build import/path First make sure you have a valid developer certificate and have setup your device properly
to run apps signed by your developer certificate. Then install the libimobiledevice and
To run a program on an iDevice, first make sure you have a valid developer ideviceinstaller tools from https://www.libimobiledevice.org/. Use the HEAD versions from
certificate and have setup your iDevice properly to run apps signed by your source; the stable versions have bugs that prevents the Go exec wrapper to install and run
developer certificate. Then install https://github.com/phonegap/ios-deploy. apps.
At a first step, you can try building the famous hello world program to run
on your test device. Second, the Go exec wrapper must be told the developer account signing identity, the team
(The needed files are provided at https://github.com/minux/go-ios-examples.) id and a provisioned bundle id to use. They're specified with the environment variables
GOIOS_DEV_ID, GOIOS_TEAM_ID and GOIOS_APP_ID. The detect.go program in this directory will
# assume your program binary is helloworld.go, build it into the attempt to auto-detect suitable values. Run it as
# example hello.app bundle.
CGO_ENABLED=1 GOARCH=arm go build -o hello.app/hello helloworld.go go run detect.go
# sign the executable using your developer certificate
codesign -f -s "iPhone Developer" --entitlements hello.app/Entitlements.plist hello.app/hello which will output something similar to
# run the program inside lldb on iDevice, run `ios-deploy` for more
# command options export GOIOS_DEV_ID="iPhone Developer: xxx@yyy.zzz (XXXXXXXX)"
ios-deploy --debug --uninstall --bundle hello.app export GOIOS_APP_ID=YYYYYYYY.some.bundle.id
# Depending on your ios-deploy version, you might need to enter "run" export GOIOS_TEAM_ID=ZZZZZZZZ
# into lldb to run your program, and its output will be shown by lldb.
If you have multiple devices connected, specify the device UDID with the GOIOS_DEVICE_ID
Notes: variable. Use `idevice_id -l` to list all available UDIDs.
- 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, Finally, to run the standard library tests, run iostest.bash with GOARCH set. For example,
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 GOARCH=arm64 ./iostest.bash
import _ "runtime/cgo"
so that external linking will be used. To use the go tool directly to run programs and tests, put $GOROOT/bin into PATH to ensure
the go_darwin_$GOARCH_exec wrapper is found. For example, to run the archive/tar tests
Known issues
============ export PATH=$GOROOT/bin:$PATH
- crypto/x509 won't build, I don't yet know how to get system root on iOS. GOARCH=arm64 go test archive/tar
- Because I still want to be able to do native build, CGO_ENABLED=1 is not the
default, yet. Note that the go_darwin_$GOARCH_exec wrapper uninstalls any existing app identified by
the bundle id before installing a new app. If the uninstalled app is the last app by
the developer identity, the device might also remove the permission to run apps from
that developer, and the exec wrapper will fail to install the new app. To avoid that,
install another app with the same developer identity but with a different bundle id.
That way, the permission to install apps is held on to while the primary app is
uninstalled.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment