Issue golang/go#24058 demonstrates a Go package that fails to build with gomobile but builds successfully with a manually using the standalone NDK toolchain. I haven't been able to figure out a set of CPPFLAGS/LDFLAGS that fixes the build for 24058 so instead rework gomobile to use standalone NDK toolchains. Standalone toolchains fixes the 24058 build and is the official way to build Android programs. So gomobile should be less affected by future changes in the NDK toolchain internals. Create the standalone toolchains with gomobile init. With the new Go 1.10 build cache, the prebuild work by the gomobile init command is useless. Use the opportunity to simplify init to only creating NDK toolchains and, optionally, building OpenAL for Android. With that, it is no longer necessary to use gomobile init to build iOS apps and frameworks. Fixes golang/go#24058 Change-Id: I4692fcaa927e7076a6387d080ebc1726905afd72 Reviewed-on: https://go-review.googlesource.com/99875 Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
82 lines
2.5 KiB
Go
82 lines
2.5 KiB
Go
// Copyright 2015 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"text/template"
|
|
)
|
|
|
|
func TestIOSBuild(t *testing.T) {
|
|
buf := new(bytes.Buffer)
|
|
defer func() {
|
|
xout = os.Stderr
|
|
buildN = false
|
|
buildX = false
|
|
}()
|
|
xout = buf
|
|
buildN = true
|
|
buildX = true
|
|
buildO = "basic.app"
|
|
buildTarget = "ios"
|
|
gopath = filepath.SplitList(os.Getenv("GOPATH"))[0]
|
|
cmdBuild.flag.Parse([]string{"golang.org/x/mobile/example/basic"})
|
|
ctx.BuildTags = []string{"tag1"}
|
|
err := runBuild(cmdBuild)
|
|
if err != nil {
|
|
t.Log(buf.String())
|
|
t.Fatal(err)
|
|
}
|
|
|
|
teamID, err := detectTeamID()
|
|
if err != nil {
|
|
t.Fatalf("detecting team ID failed: %v", err)
|
|
}
|
|
|
|
data := struct {
|
|
outputData
|
|
TeamID string
|
|
}{
|
|
outputData: defaultOutputData(),
|
|
TeamID: teamID,
|
|
}
|
|
|
|
got := filepath.ToSlash(buf.String())
|
|
|
|
wantBuf := new(bytes.Buffer)
|
|
|
|
if err := iosBuildTmpl.Execute(wantBuf, data); err != nil {
|
|
t.Fatalf("computing diff failed: %v", err)
|
|
}
|
|
|
|
diff, err := diff(got, wantBuf.String())
|
|
|
|
if err != nil {
|
|
t.Fatalf("computing diff failed: %v", err)
|
|
}
|
|
if diff != "" {
|
|
t.Errorf("unexpected output:\n%s", diff)
|
|
}
|
|
}
|
|
|
|
var iosBuildTmpl = template.Must(infoplistTmpl.New("output").Parse(`GOMOBILE={{.GOPATH}}/pkg/gomobile
|
|
WORK=$WORK
|
|
mkdir -p $WORK/main.xcodeproj
|
|
echo "{{.Xproj}}" > $WORK/main.xcodeproj/project.pbxproj
|
|
mkdir -p $WORK/main
|
|
echo "{{template "infoplist" .Xinfo}}" > $WORK/main/Info.plist
|
|
mkdir -p $WORK/main/Images.xcassets/AppIcon.appiconset
|
|
echo "{{.Xcontents}}" > $WORK/main/Images.xcassets/AppIcon.appiconset/Contents.json
|
|
GOOS=darwin GOARCH=arm GOARM=7 CC=clang-iphoneos CXX=clang-iphoneos CGO_CFLAGS=-isysroot=iphoneos -miphoneos-version-min=6.1 -arch armv7 CGO_LDFLAGS=-isysroot=iphoneos -miphoneos-version-min=6.1 -arch armv7 CGO_ENABLED=1 go build -tags tag1 ios -x -o=$WORK/arm golang.org/x/mobile/example/basic
|
|
GOOS=darwin GOARCH=arm64 CC=clang-iphoneos CXX=clang-iphoneos CGO_CFLAGS=-isysroot=iphoneos -miphoneos-version-min=6.1 -arch arm64 CGO_LDFLAGS=-isysroot=iphoneos -miphoneos-version-min=6.1 -arch arm64 CGO_ENABLED=1 go build -tags tag1 ios -x -o=$WORK/arm64 golang.org/x/mobile/example/basic
|
|
xcrun lipo -create $WORK/arm $WORK/arm64 -o $WORK/main/main
|
|
mkdir -p $WORK/main/assets
|
|
xcrun xcodebuild -configuration Release -project $WORK/main.xcodeproj -allowProvisioningUpdates DEVELOPMENT_TEAM={{.TeamID}}
|
|
mv $WORK/build/Release-iphoneos/main.app basic.app
|
|
`))
|