mirror of https://github.com/golang/go.git
misc/ios: update documentation for running iOS programs and tests
Change-Id: I8e3077ab9c7dff66877ac00dc4600b53c07eb1f8 Reviewed-on: https://go-review.googlesource.com/112655 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
599f56dc05
commit
25f73db0b6
|
|
@ -1,44 +1,50 @@
|
||||||
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
|
|
||||||
|
|
||||||
To build a program, use the normal go build command:
|
It is necessary to set up the environment before running tests or programs directly on a
|
||||||
|
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
|
||||||
|
ideviceinstaller tools from https://www.libimobiledevice.org/. Use the HEAD versions from
|
||||||
|
source; the stable versions have bugs that prevents the Go exec wrapper to install and run
|
||||||
|
apps.
|
||||||
|
|
||||||
To run a program on an iDevice, first make sure you have a valid developer
|
Second, the Go exec wrapper must be told the developer account signing identity, the team
|
||||||
certificate and have setup your iDevice properly to run apps signed by your
|
id and a provisioned bundle id to use. They're specified with the environment variables
|
||||||
developer certificate. Then install https://github.com/phonegap/ios-deploy.
|
GOIOS_DEV_ID, GOIOS_TEAM_ID and GOIOS_APP_ID. The detect.go program in this directory will
|
||||||
At a first step, you can try building the famous hello world program to run
|
attempt to auto-detect suitable values. Run it as
|
||||||
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
|
go run detect.go
|
||||||
# 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:
|
which will output something similar to
|
||||||
- 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
|
export GOIOS_DEV_ID="iPhone Developer: xxx@yyy.zzz (XXXXXXXX)"
|
||||||
============
|
export GOIOS_APP_ID=YYYYYYYY.some.bundle.id
|
||||||
- crypto/x509 won't build, I don't yet know how to get system root on iOS.
|
export GOIOS_TEAM_ID=ZZZZZZZZ
|
||||||
- Because I still want to be able to do native build, CGO_ENABLED=1 is not the
|
|
||||||
default, yet.
|
If you have multiple devices connected, specify the device UDID with the GOIOS_DEVICE_ID
|
||||||
|
variable. Use `idevice_id -l` to list all available UDIDs.
|
||||||
|
|
||||||
|
Finally, to run the standard library tests, run iostest.bash with GOARCH set. For example,
|
||||||
|
|
||||||
|
GOARCH=arm64 ./iostest.bash
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
export PATH=$GOROOT/bin:$PATH
|
||||||
|
GOARCH=arm64 go test archive/tar
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue