1
0
mirror of https://github.com/golang/go synced 2024-11-05 22:56:11 -07:00
go/misc/ios
Elias Naur c3cb44fdef misc/ios: make detect.go more robust
To enable the exec wrapper go_darwin_arm_exec.go to run binaries
on iOS devices, the GOIOS_DEV_ID variable needs to be set to a code
signing identity. The program detect.go attempts to detect suitable
values for GOIOS_DEV_ID (along with GOIOS_APP_ID and GOIOS_TEAM_ID).

Before this change, detect.go would use "security find-identity
-p codesigning -v" to list all available identities for code signing
and pick the first one with "iPhone Developer" in its name. However,
that pick might be invalid since if it was replaced by an identity
issued later.

For example, on the mobile builder:

$ security find-identity -p codesigning -v
  1) 0E251DE41FE4490574E475AC320B47F58D6D3635 "lldb_codesign"
  2) 0358588D07AA6A19478981BA405F40A97F95F187 "iPhone Developer: xxx@xxx (2754T98W8E)"
  3) FC6D96F24A3223C98BF7A2C2C5194D82E04CD23E "iPhone Developer: xxx@xxx (2754T98W8E)"
     3 valid identities found

In this case, the identity 0358588D07AA6A19478981BA405F40A97F95F187
is picked by detect.go even though it has been invalidated by
FC6D96F24A3223C98BF7A2C2C5194D82E04CD23E.

Instead of attempting to find an identity from the "security
find-identity" list, use the identity from the CommonName in the
embedded certificate in the provisioning file. The CommonName only
lists the identity name (iPhone Developer: xxx@xxx (2754T98W8E)),
not the fingerprint (FC6D96F24A3223C98BF7A2C2C5194D82E04CD23E), but
fortunately the codesign tool accepts both.

Identity names may not be unique, as demonstrated by the example,
but that will result in an ambiguity error at codesigning instead of
a more obscure error about an invalid identity when
go_darwin_arm_exec.go runs a binary.
The fix is then to delete the invalid identity from the system
keychain.

While here, find all connected devices instead of the first connected
and only consider provision files that covers them all. This matters
for the mobile builder where two devices are connected.

Change-Id: I6beb59ace3fc5e071ba76222a20a607765943989
Reviewed-on: https://go-review.googlesource.com/105436
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2018-04-10 16:36:33 +00:00
..
clangwrap.sh build: fix darwin/arm broken on macOS 10.12 with Xcode 8.0 2016-12-21 12:27:41 +00:00
detect.go misc/ios: make detect.go more robust 2018-04-10 16:36:33 +00:00
go_darwin_arm_exec.go misc/ios,runtime/cgo: remove SIGINT handshake for the iOS exec wrapper 2018-04-10 16:30:07 +00:00
README

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:

	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

To build a program, use the normal go build command:

	CGO_ENABLED=1 GOARCH=arm go build import/path

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.)

	# 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.

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.

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.