README 2.7 KB

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