Shenghou Ma | f961a99 | 2014-12-26 01:24:42 -0500 | [diff] [blame] | 1 | Go on iOS |
| 2 | ========= |
| 3 | |
Elias Naur | 869c02c | 2020-09-16 15:23:58 +0200 | [diff] [blame] | 4 | To run the standard library tests, run all.bash as usual, but with the compiler |
| 5 | set to the clang wrapper that invokes clang for iOS. For example, this command runs |
| 6 | all.bash on the iOS emulator: |
Shenghou Ma | f961a99 | 2014-12-26 01:24:42 -0500 | [diff] [blame] | 7 | |
Elias Naur | 869c02c | 2020-09-16 15:23:58 +0200 | [diff] [blame] | 8 | GOOS=ios GOARCH=amd64 CGO_ENABLED=1 CC_FOR_TARGET=$(pwd)/../misc/ios/clangwrap.sh ./all.bash |
Shenghou Ma | f961a99 | 2014-12-26 01:24:42 -0500 | [diff] [blame] | 9 | |
Cherry Zhang | f83e0f6 | 2020-12-28 14:33:14 -0500 | [diff] [blame] | 10 | If CC_FOR_TARGET is not set when the toolchain is built (make.bash or all.bash), CC |
Daniel Martà | 780b4de | 2020-12-29 21:37:06 +0000 | [diff] [blame] | 11 | can be set on the command line. For example, |
Cherry Zhang | f83e0f6 | 2020-12-28 14:33:14 -0500 | [diff] [blame] | 12 | |
| 13 | GOOS=ios GOARCH=amd64 CGO_ENABLED=1 CC=$(go env GOROOT)/misc/ios/clangwrap.sh go build |
| 14 | |
| 15 | Setting CC is not necessary if the toolchain is built with CC_FOR_TARGET set. |
| 16 | |
Elias Naur | 869c02c | 2020-09-16 15:23:58 +0200 | [diff] [blame] | 17 | To use the go tool to run individual programs and tests, put $GOROOT/bin into PATH to ensure |
| 18 | the go_ios_$GOARCH_exec wrapper is found. For example, to run the archive/tar tests: |
| 19 | |
| 20 | export PATH=$GOROOT/bin:$PATH |
| 21 | GOOS=ios GOARCH=amd64 CGO_ENABLED=1 go test archive/tar |
| 22 | |
| 23 | The go_ios_exec wrapper uses GOARCH to select the emulator (amd64) or the device (arm64). |
| 24 | However, further setup is required to run tests or programs directly on a device. |
Shenghou Ma | f961a99 | 2014-12-26 01:24:42 -0500 | [diff] [blame] | 25 | |
Elias Naur | 25f73db | 2018-05-10 17:38:23 +0200 | [diff] [blame] | 26 | First make sure you have a valid developer certificate and have setup your device properly |
| 27 | to run apps signed by your developer certificate. Then install the libimobiledevice and |
| 28 | ideviceinstaller tools from https://www.libimobiledevice.org/. Use the HEAD versions from |
| 29 | source; the stable versions have bugs that prevents the Go exec wrapper to install and run |
| 30 | apps. |
Shenghou Ma | f961a99 | 2014-12-26 01:24:42 -0500 | [diff] [blame] | 31 | |
Elias Naur | 25f73db | 2018-05-10 17:38:23 +0200 | [diff] [blame] | 32 | Second, the Go exec wrapper must be told the developer account signing identity, the team |
| 33 | id and a provisioned bundle id to use. They're specified with the environment variables |
| 34 | GOIOS_DEV_ID, GOIOS_TEAM_ID and GOIOS_APP_ID. The detect.go program in this directory will |
| 35 | attempt to auto-detect suitable values. Run it as |
Shenghou Ma | f961a99 | 2014-12-26 01:24:42 -0500 | [diff] [blame] | 36 | |
Elias Naur | 25f73db | 2018-05-10 17:38:23 +0200 | [diff] [blame] | 37 | go run detect.go |
Shenghou Ma | f961a99 | 2014-12-26 01:24:42 -0500 | [diff] [blame] | 38 | |
Elias Naur | 25f73db | 2018-05-10 17:38:23 +0200 | [diff] [blame] | 39 | which will output something similar to |
Shenghou Ma | f961a99 | 2014-12-26 01:24:42 -0500 | [diff] [blame] | 40 | |
Elias Naur | 25f73db | 2018-05-10 17:38:23 +0200 | [diff] [blame] | 41 | export GOIOS_DEV_ID="iPhone Developer: xxx@yyy.zzz (XXXXXXXX)" |
| 42 | export GOIOS_APP_ID=YYYYYYYY.some.bundle.id |
| 43 | export GOIOS_TEAM_ID=ZZZZZZZZ |
| 44 | |
| 45 | If you have multiple devices connected, specify the device UDID with the GOIOS_DEVICE_ID |
Elias Naur | 869c02c | 2020-09-16 15:23:58 +0200 | [diff] [blame] | 46 | variable. Use `idevice_id -l` to list all available UDIDs. Then, setting GOARCH to arm64 |
| 47 | will select the device: |
Elias Naur | 25f73db | 2018-05-10 17:38:23 +0200 | [diff] [blame] | 48 | |
Elias Naur | 869c02c | 2020-09-16 15:23:58 +0200 | [diff] [blame] | 49 | GOOS=ios GOARCH=arm64 CGO_ENABLED=1 CC_FOR_TARGET=$(pwd)/../misc/ios/clangwrap.sh ./all.bash |
Elias Naur | 25f73db | 2018-05-10 17:38:23 +0200 | [diff] [blame] | 50 | |
| 51 | Note that the go_darwin_$GOARCH_exec wrapper uninstalls any existing app identified by |
| 52 | the bundle id before installing a new app. If the uninstalled app is the last app by |
| 53 | the developer identity, the device might also remove the permission to run apps from |
| 54 | that developer, and the exec wrapper will fail to install the new app. To avoid that, |
| 55 | install another app with the same developer identity but with a different bundle id. |
| 56 | That way, the permission to install apps is held on to while the primary app is |
| 57 | uninstalled. |