mirror of
https://github.com/golang/go
synced 2024-11-02 11:50:30 +00:00
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 changed files with 40 additions and 34 deletions
|
@ -1,44 +1,50 @@
|
|||
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:
|
||||
For details on developing Go for iOS on macOS, see the documentation in the mobile
|
||||
subrepository:
|
||||
|
||||
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
|
||||
https://github.com/golang/mobile
|
||||
|
||||
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
|
||||
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.)
|
||||
Second, the Go exec wrapper must be told the developer account signing identity, the team
|
||||
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
|
||||
attempt to auto-detect suitable values. Run it as
|
||||
|
||||
# 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.
|
||||
go run detect.go
|
||||
|
||||
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.
|
||||
which will output something similar to
|
||||
|
||||
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.
|
||||
export GOIOS_DEV_ID="iPhone Developer: xxx@yyy.zzz (XXXXXXXX)"
|
||||
export GOIOS_APP_ID=YYYYYYYY.some.bundle.id
|
||||
export GOIOS_TEAM_ID=ZZZZZZZZ
|
||||
|
||||
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 a new issue