2
0
mirror of synced 2025-02-23 06:48:15 +00:00

cmd/gomobile: simplify init

The Go toolchain used to require that we rebuild the compiler and
friends (the cgo command) when building a cgo-enabled cross compiler.
This meant that gomobile init used to invoke make.bash in a temporary
copy of the GOROOT. This works, but brings with it several
complications, including needing to use -toolexec when invoking the
go tool, finding a boostrap copy of Go 1.4, long initialization
times, and a variety of unusual failure modes.

Fortunately we don't need our own compiler any more. All that's
necessary is building the standard library for the cross-compilation
targets and making sure the right C compiler is used when calling
go build (as it always was). This means most of the initialization
process can be replaced with a carefully invoked 'go install std'.

While here, remove the source install instructions (most of it is
documented already, and the final step, choosing the right git
revision should be within the skills of anyone using pre-release
software.) Some other documentation is changing because it's been a
while since go generate was run.

Change-Id: I88c10fef87867536e83c7df063ae7241b2e9eea4
Reviewed-on: https://go-review.googlesource.com/11711
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
David Crawshaw 2015-06-29 14:37:57 -04:00
parent d1e52bb351
commit 743b9bfd9a
6 changed files with 130 additions and 355 deletions

View File

@ -383,7 +383,7 @@ func goAndroidBuild(src, libPath string) error {
`go`, `go`,
`build`, `build`,
`-tags=`+strconv.Quote(strings.Join(ctx.BuildTags, ",")), `-tags=`+strconv.Quote(strings.Join(ctx.BuildTags, ",")),
`-toolexec=`+filepath.Join(ndkccbin, "toolexec")) )
if buildV { if buildV {
gocmd.Args = append(gocmd.Args, "-v") gocmd.Args = append(gocmd.Args, "-v")
} }
@ -415,7 +415,6 @@ func goAndroidBuild(src, libPath string) error {
`GOGCCFLAGS="-fPIC -marm -pthread -fmessage-length=0"`, `GOGCCFLAGS="-fPIC -marm -pthread -fmessage-length=0"`,
`GOROOT=` + goEnv("GOROOT"), `GOROOT=` + goEnv("GOROOT"),
`GOPATH=` + gopath, `GOPATH=` + gopath,
`GOMOBILEPATH=` + ndkccbin, // for toolexec
} }
if buildX { if buildX {
printcmd("%s", strings.Join(gocmd.Env, " ")+" "+strings.Join(gocmd.Args, " ")) printcmd("%s", strings.Join(gocmd.Env, " ")+" "+strings.Join(gocmd.Args, " "))

View File

@ -48,6 +48,6 @@ func TestBuild(t *testing.T) {
var buildTmpl = template.Must(template.New("output").Parse(`WORK=$WORK var buildTmpl = template.Must(template.New("output").Parse(`WORK=$WORK
GOMOBILE={{.GOPATH}}/pkg/gomobile GOMOBILE={{.GOPATH}}/pkg/gomobile
GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=$GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-gcc{{.EXE}} CXX=$GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-g++{{.EXE}} GOGCCFLAGS="-fPIC -marm -pthread -fmessage-length=0" GOROOT=$GOROOT GOPATH=$GOPATH GOMOBILEPATH=$GOMOBILE/android-{{.NDK}}/arm/bin go build -tags="" -toolexec=$GOMOBILE/android-{{.NDK}}/arm/bin/toolexec -x -buildmode=c-shared -o $WORK/libbasic.so golang.org/x/mobile/example/basic GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=$GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-gcc{{.EXE}} CXX=$GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-g++{{.EXE}} GOGCCFLAGS="-fPIC -marm -pthread -fmessage-length=0" GOROOT=$GOROOT GOPATH=$GOPATH go build -tags="" -x -buildmode=c-shared -o $WORK/libbasic.so golang.org/x/mobile/example/basic
rm -r -f "$WORK" rm -r -f "$WORK"
`)) `))

View File

@ -7,47 +7,16 @@
/* /*
Gomobile is a tool for building and running mobile apps written in Go. Gomobile is a tool for building and running mobile apps written in Go.
Installation: To install:
$ go get golang.org/x/mobile/cmd/gomobile $ go get golang.org/x/mobile/cmd/gomobile
$ gomobile init $ gomobile init
Note that until Go 1.5 is released, you must compile Go from tip. At least Go 1.5 is required. Until it is released, build tip from
source: http://golang.org/doc/install/source
Clone the source from the tip under $HOME/go directory. On Windows, Initialization rebuilds the standard library and may download
you may like to clone the repo to your user folder, %USERPROFILE%\go. the Android NDK compiler.
$ git clone https://go.googlesource.com/go $HOME/go
Go 1.5 requires Go 1.4. Read more about this requirement at
http://golang.org/s/go15bootstrap.
Set GOROOT_BOOTSTRAP to the GOROOT of your existing 1.4 installation or
follow the steps below to checkout go1.4 from the source and build.
$ git clone https://go.googlesource.com/go $HOME/go1.4
$ cd $HOME/go1.4
$ git checkout go1.4.1
$ cd src && ./make.bash
If you clone Go 1.4 to a different destination, set GOROOT_BOOTSTRAP
environmental variable accordingly.
Build Go 1.5 and add Go 1.5 bin to your path.
$ cd $HOME/go/src && ./make.bash
$ export PATH=$PATH:$HOME/go/bin
Set a GOPATH if no GOPATH is set, add $GOPATH/bin to your path.
$ export GOPATH=$HOME
$ export PATH=$PATH:$GOPATH/bin
Now you can get the gomobile tool and initialize.
$ go get golang.org/x/mobile/cmd/gomobile
$ gomobile init
It may take a while to initialize gomobile, please wait.
Usage: Usage:
@ -69,67 +38,67 @@ Build a shared library for android APK and iOS app
Usage: Usage:
gomobile bind [package] gomobile bind [-target android|ios] [-o output] [build flags] [package]
Bind generates language bindings like gobind (golang.org/x/mobile/cmd/gobind) Bind generates language bindings for the package named by the import
for a package and builds a shared library for each platform from the go binding path, and compiles a library for the named target system.
code.
For Android, the bind command produces an AAR (Android ARchive) file that The -target flag takes a target system name, either android (the
archives the precompiled Java API stub classes, the compiled shared libraries, default) or ios.
and all asset files in the /assets subdirectory under the package directory.
The output AAR file name is '<package_name>.aar'.
The AAR file is commonly used for binary distribution of an Android library For -target android, the bind command produces an AAR (Android ARchive)
project and most Android IDEs support AAR import. For example, in Android file that archives the precompiled Java API stub classes, the compiled
Studio (1.2+), an AAR file can be imported using the module import wizard shared libraries, and all asset files in the /assets subdirectory under
(File > New > New Module > Import .JAR or .AAR package), and setting it as the package directory. The output is named '<package_name>.aar' by
a new dependency (File > Project Structure > Dependencies). default. This AAR file is commonly used for binary distribution of an
Android library project and most Android IDEs support AAR import. For
example, in Android Studio (1.2+), an AAR file can be imported using
the module import wizard (File > New > New Module > Import .JAR or
.AAR package), and setting it as a new dependency
(File > Project Structure > Dependencies). This requires 'javac'
(version 1.7+) and Android SDK (API level 9 or newer) to build the
library for Android. The environment variable ANDROID_HOME must be set
to the path to Android SDK.
This command requires 'javac' (version 1.7+) and Android SDK (API level 9 For -target ios, gomobile must be run on an OS X machine with Xcode
or newer) to build the library for Android. The environment variable installed. Support is not complete.
ANDROID_HOME must be set to the path to Android SDK.
The -v flag provides verbose output, including the list of packages built. The -v flag provides verbose output, including the list of packages built.
These build flags are shared by the build command. The build flags -a, -i, -n, -x, and -tags are shared with the build command.
For documentation, see 'go help build': For documentation, see 'go help build'.
-a
-i
-n
-x
-tags 'tag list'
Compile android APK and iOS app Compile android APK and iOS app
Usage: Usage:
gomobile build [-o output] [-i] [build flags] [package] gomobile build [-target android|ios] [-o output] [build flags] [package]
Build compiles and encodes the app named by the import path. Build compiles and encodes the app named by the import path.
The named package must define a main function. The named package must define a main function.
If an AndroidManifest.xml is defined in the package directory, it is The -target flag takes a target system name, either android (the
added to the APK file. Otherwise, a default manifest is generated. default) or ios.
For -target android, if an AndroidManifest.xml is defined in the
package directory, it is added to the APK output. Otherwise, a default
manifest is generated.
For -target ios, gomobile must be run on an OS X machine with Xcode
installed. Support is not complete.
If the package directory contains an assets subdirectory, its contents If the package directory contains an assets subdirectory, its contents
are copied into the APK file. are copied into the output.
The -o flag specifies the output file name. If not specified, the The -o flag specifies the output file name. If not specified, the
output file name depends on the package built. The output file must end output file name depends on the package built.
in '.apk'.
The -v flag provides verbose output, including the list of packages built. The -v flag provides verbose output, including the list of packages built.
These build flags are shared by the build, install, and test commands. The build flags -a, -i, -n, -x, and -tags are shared with the build command.
For documentation, see 'go help build': For documentation, see 'go help build'.
-a
-i
-n
-x
-tags 'tag list'
Install android compiler toolchain Install android compiler toolchain
@ -152,13 +121,14 @@ Compile android APK and iOS app and install on device
Usage: Usage:
gomobile install [package] gomobile install [-target android] [build flags] [package]
Install compiles and installs the app named by the import path on the Install compiles and installs the app named by the import path on the
attached mobile device. attached mobile device.
This command requires the 'adb' tool on the PATH. Only -target android is supported. The 'adb' tool must be on the PATH.
See the build command help for common flags and common behavior. The build flags -a, -i, -n, -x, and -tags are shared with the build command.
For documentation, see 'go help build'.
*/ */
package main package main

View File

@ -109,12 +109,6 @@ func runInit(cmd *command) error {
} }
defer removeAll(tmpdir) defer removeAll(tmpdir)
goroot := goEnv("GOROOT")
tmpGoroot := filepath.Join(tmpdir, "go")
if err := copyGoroot(tmpGoroot, goroot); err != nil {
return err
}
if err := fetchNDK(); err != nil { if err := fetchNDK(); err != nil {
return err return err
} }
@ -122,98 +116,15 @@ func runInit(cmd *command) error {
return err return err
} }
dst := filepath.Join(ndkccpath, "arm") // Install standard libraries for cross compilers.
if err := installAndroidArm(); err != nil {
ndkccbin := filepath.Join(dst, "bin")
envpath := os.Getenv("PATH")
if buildN {
envpath = "$PATH"
}
makeScript := filepath.Join(tmpGoroot, "src/make")
if goos == "windows" {
makeScript += ".bat"
} else {
makeScript += ".bash"
}
bin := func(name string) string {
if goos == "windows" {
return name + ".exe"
}
return name
}
make := exec.Command(makeScript, "--no-clean")
make.Dir = filepath.Join(tmpGoroot, "src")
make.Env = []string{
`PATH=` + envpath,
`GOOS=android`,
`GOROOT=` + tmpGoroot, // set to override any bad os.Environ
`GOARCH=arm`,
`GOARM=7`,
`CGO_ENABLED=1`,
`CC_FOR_TARGET=` + filepath.Join(ndkccbin, bin("arm-linux-androideabi-gcc")),
`CXX_FOR_TARGET=` + filepath.Join(ndkccbin, bin("arm-linux-androideabi-g++")),
}
make.Env = appendCommonEnv(make.Env)
if v := goEnv("GOROOT_BOOTSTRAP"); v != "" {
make.Env = append(make.Env, `GOROOT_BOOTSTRAP=`+v)
}
if buildV {
fmt.Fprintf(os.Stderr, "building android/arm cross compiler\n")
make.Stdout = os.Stdout
make.Stderr = os.Stderr
}
if buildX {
printcmd("%s", strings.Join(make.Env, " ")+" "+strings.Join(make.Args, " "))
}
if !buildN {
if err := make.Run(); err != nil {
return err
}
}
if err := checkVersionMatch(tmpGoroot, version); err != nil {
return err return err
} }
if goos == "darwin" {
// Move the Go cross compiler toolchain into GOPATH. if err := installDarwin("arm"); err != nil {
gotoolsrc := filepath.Join(tmpGoroot, "pkg/tool", goos+"_"+goarch)
tools := []string{"compile", "asm", "cgo", "nm", "old5a", "pack", "link"}
for i, name := range tools {
tools[i] = bin(name)
}
if err := move(ndkccbin, gotoolsrc, tools...); err != nil {
return err
}
// Build toolexec command.
toolexecSrc := filepath.Join(tmpdir, "toolexec.go")
if !buildN {
if err := ioutil.WriteFile(toolexecSrc, []byte(toolexec), 0644); err != nil {
return err return err
} }
} if err := installDarwin("arm64"); err != nil {
make = exec.Command("go", "build", "-o", filepath.Join(ndkccbin, bin("toolexec")), toolexecSrc)
if buildV {
fmt.Fprintf(os.Stderr, "building gomobile toolexec\n")
make.Stdout = os.Stdout
make.Stderr = os.Stderr
}
if buildX {
printcmd("%s", strings.Join(make.Args, " "))
}
if !buildN {
if err := make.Run(); err != nil {
return err
}
}
if err := installCC("android", "arm"); err != nil {
return err
}
if runtime.GOOS == "darwin" {
if err := buildDarwinARMCC(); err != nil {
return err return err
} }
} }
@ -229,70 +140,81 @@ func runInit(cmd *command) error {
return nil return nil
} }
func buildDarwinARMCC() error { func installAndroidArm() error {
removeAll(filepath.Join(goEnv("GOROOT"), "pkg", "android_arm"))
ndkccbin := filepath.Join(ndkccpath, "arm", "bin")
envpath := os.Getenv("PATH") envpath := os.Getenv("PATH")
if buildN { if buildN {
envpath = "$PATH" envpath = "$PATH"
} }
tmpGoroot := filepath.Join(tmpdir, "go")
makeCC := func(arch string) error { bin := func(name string) string {
m := exec.Command(filepath.Join(tmpGoroot, "src/make.bash"), "--no-clean") if goos == "windows" {
m.Dir = filepath.Join(tmpGoroot, "src") return name + ".exe"
m.Env = []string{
`PATH=` + envpath,
`GOOS=darwin`,
`GOROOT=` + tmpGoroot, // set to override any bad os.Environ
`GOARCH=` + arch,
`CGO_ENABLED=1`,
`CC_FOR_TARGET=` + filepath.Join(tmpGoroot, "misc/ios/clangwrap.sh"),
`CXX_FOR_TARGET=` + filepath.Join(tmpGoroot, "misc/ios/clangwrap.sh"),
} }
if arch == "arm" { return name
m.Env = append(m.Env, "GOARM=7")
}
m.Env = appendCommonEnv(m.Env)
if v := goEnv("GOROOT_BOOTSTRAP"); v != "" {
m.Env = append(m.Env, `GOROOT_BOOTSTRAP=`+v)
}
if buildV {
fmt.Fprintf(os.Stderr, "building darwin/arm cross compiler\n")
m.Stdout = os.Stdout
m.Stderr = os.Stderr
}
if buildX {
printcmd("%s", strings.Join(m.Env, " ")+" "+strings.Join(m.Args, " "))
}
if !buildN {
if err := m.Run(); err != nil {
return err
}
}
return nil
} }
if err := makeCC("arm"); err != nil {
return nil cmd := exec.Command("go", "install", "std")
cmd.Env = []string{
`PATH=` + envpath,
`GOOS=android`,
`GOARCH=arm`,
`GOARM=7`,
`CGO_ENABLED=1`,
`CC=` + filepath.Join(ndkccbin, bin("arm-linux-androideabi-gcc")),
`CXX=` + filepath.Join(ndkccbin, bin("arm-linux-androideabi-g++")),
} }
if err := makeCC("arm64"); err != nil { cmd.Env = appendCommonEnv(cmd.Env)
return nil if buildV {
fmt.Fprintf(os.Stderr, "Building android/arm standard library.\n")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
} }
if err := installCC("darwin", "arm"); err != nil { if buildX {
return err printcmd("%s", strings.Join(cmd.Env, " ")+" "+strings.Join(cmd.Args, " "))
} }
return installCC("darwin", "arm64") if !buildN {
if err := cmd.Run(); err != nil {
return err
}
}
return nil
} }
func installCC(goos, goarch string) error { func installDarwin(arch string) error {
goroot := goEnv("GOROOT") removeAll(filepath.Join(goEnv("GOROOT"), "pkg", "darwin_"+arch))
tmpGoroot := filepath.Join(tmpdir, "go") envpath := os.Getenv("PATH")
// Move pre-compiled stdlib for GOROOT. This is if buildN {
// the only time we modify the user's GOROOT. envpath = "$PATH"
name := goos + "_" + goarch
if err := removeAll(filepath.Join(goroot, "pkg", name)); err != nil {
return fmt.Errorf("GOROOT is not writable: %v", err)
} }
if err := move(filepath.Join(goroot, "pkg"), filepath.Join(tmpGoroot, "pkg"), name); err != nil {
return fmt.Errorf("GOROOT is not writable: %v", err) goroot := goEnv("GOROOT")
cmd := exec.Command("go", "install", "std")
cmd.Env = []string{
`PATH=` + envpath,
`GOOS=darwin`,
`GOARCH=` + arch,
`CGO_ENABLED=1`,
`CC=` + filepath.Join(goroot, "misc/ios/clangwrap.sh"),
`CXX=` + filepath.Join(goroot, "misc/ios/clangwrap.sh"),
}
if arch == "arm" {
cmd.Env = append(cmd.Env, "GOARM=7")
}
cmd.Env = appendCommonEnv(cmd.Env)
if buildV {
fmt.Fprintf(os.Stderr, "Building darwin/%s standard library.\n", arch)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
}
if buildX {
printcmd("%s", strings.Join(cmd.Env, " ")+" "+strings.Join(cmd.Args, " "))
}
if !buildN {
if err := cmd.Run(); err != nil {
return err
}
} }
return nil return nil
} }
@ -311,30 +233,6 @@ func appendCommonEnv(env []string) []string {
return env return env
} }
// toolexec is the source of a small program designed to be passed to
// the -toolexec flag of go build.
const toolexec = `package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
)
func main() {
args := append([]string{}, os.Args[1:]...)
args[0] = filepath.Join(os.Getenv("GOMOBILEPATH"), filepath.Base(args[0]))
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}
`
func removeGomobilepkg() { func removeGomobilepkg() {
dir, err := os.Open(gomobilepath) dir, err := os.Open(gomobilepath)
if err != nil { if err != nil {
@ -415,6 +313,8 @@ func goVersion() ([]byte, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("bad Go tool: %v (%s)", err, buildHelp) return nil, fmt.Errorf("bad Go tool: %v (%s)", err, buildHelp)
} }
// TODO(crawshaw): this is a crude test for Go 1.5. After release,
// remove this and check it is not an old release version.
if !bytes.Contains(buildHelp, []byte("-toolexec")) { if !bytes.Contains(buildHelp, []byte("-toolexec")) {
return nil, fmt.Errorf("installed Go tool does not support -toolexec") return nil, fmt.Errorf("installed Go tool does not support -toolexec")
} }
@ -641,7 +541,7 @@ func fetch(url string) (dst string, err error) {
return "", err return "", err
} }
if buildV { if buildV {
fmt.Fprintf(os.Stderr, "fetching %s\n", url) fmt.Fprintf(os.Stderr, "Downloading %s.\n", url)
} }
name := path.Base(url) name := path.Base(url)
dst = filepath.Join(gomobilepath, "dl", name) dst = filepath.Join(gomobilepath, "dl", name)

View File

@ -8,7 +8,6 @@ import (
"bytes" "bytes"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
"testing" "testing"
"text/template" "text/template"
@ -43,9 +42,6 @@ func TestInit(t *testing.T) {
} }
tmpl := initTmpl tmpl := initTmpl
if runtime.GOOS == "darwin" {
tmpl = initDarwinTmpl
}
diff, err := diffOutput(buf.String(), tmpl) diff, err := diffOutput(buf.String(), tmpl)
if err != nil { if err != nil {
@ -93,18 +89,13 @@ type outputData struct {
} }
const ( const (
unixBuildScript = `TMPDIR=$WORK HOME=$HOME GOROOT_BOOTSTRAP=go1.4 $WORK/go/src/make.bash --no-clean` unixBuildScript = `TMPDIR=$WORK HOME=$HOME go install std`
windowsBuildScript = `TEMP=$WORK TMP=$WORK HOMEDRIVE=C: HOMEPATH=$HOMEPATH GOROOT_BOOTSTRAP=go1.4 $WORK/go/src/make.bat --no-clean` windowsBuildScript = `TEMP=$WORK TMP=$WORK HOMEDRIVE=C: HOMEPATH=$HOMEPATH go install std`
) )
var initTmpl = template.Must(template.New("output").Parse(`GOMOBILE={{.GOPATH}}/pkg/gomobile var initTmpl = template.Must(template.New("output").Parse(`GOMOBILE={{.GOPATH}}/pkg/gomobile
mkdir -p $GOMOBILE/android-{{.NDK}} mkdir -p $GOMOBILE/android-{{.NDK}}
WORK=/GOPATH1/pkg/gomobile/work WORK=/GOPATH1/pkg/gomobile/work
mkdir -p $WORK/go/pkg
cp -a $GOROOT/lib $WORK/go/lib
cp -a $GOROOT/src $WORK/go/src
cp -a $GOROOT/misc $WORK/go/misc
ln -s $GOROOT/.git $WORK/go/.git
mkdir -p $GOMOBILE/dl mkdir -p $GOMOBILE/dl
curl -o$GOMOBILE/dl/gomobile-{{.NDK}}-{{.GOOS}}-{{.NDKARCH}}.tar.gz https://dl.google.com/go/mobile/gomobile-{{.NDK}}-{{.GOOS}}-{{.NDKARCH}}.tar.gz curl -o$GOMOBILE/dl/gomobile-{{.NDK}}-{{.GOOS}}-{{.NDKARCH}}.tar.gz https://dl.google.com/go/mobile/gomobile-{{.NDK}}-{{.GOOS}}-{{.NDKARCH}}.tar.gz
tar xfz $GOMOBILE/dl/gomobile-{{.NDK}}-{{.GOOS}}-{{.NDKARCH}}.tar.gz tar xfz $GOMOBILE/dl/gomobile-{{.NDK}}-{{.GOOS}}-{{.NDKARCH}}.tar.gz
@ -125,66 +116,12 @@ tar xfz $GOMOBILE/dl/gomobile-openal-soft-1.16.0.1.tar.gz
mv $WORK/openal/include/AL $GOMOBILE/android-{{.NDK}}/arm/sysroot/usr/include/AL mv $WORK/openal/include/AL $GOMOBILE/android-{{.NDK}}/arm/sysroot/usr/include/AL
mkdir -p $GOMOBILE/android-{{.NDK}}/openal mkdir -p $GOMOBILE/android-{{.NDK}}/openal
mv $WORK/openal/lib $GOMOBILE/android-{{.NDK}}/openal/lib mv $WORK/openal/lib $GOMOBILE/android-{{.NDK}}/openal/lib
PATH=$PATH GOOS=android GOROOT=$WORK/go GOARCH=arm GOARM=7 CGO_ENABLED=1 CC_FOR_TARGET=$GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-gcc{{.EXE}} CXX_FOR_TARGET=$GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-g++{{.EXE}} {{.BuildScript}}
mv $WORK/go/pkg/tool/{{.GOOS}}_{{.GOARCH}}/compile{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/bin/compile{{.EXE}}
mv $WORK/go/pkg/tool/{{.GOOS}}_{{.GOARCH}}/asm{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/bin/asm{{.EXE}}
mv $WORK/go/pkg/tool/{{.GOOS}}_{{.GOARCH}}/cgo{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/bin/cgo{{.EXE}}
mv $WORK/go/pkg/tool/{{.GOOS}}_{{.GOARCH}}/nm{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/bin/nm{{.EXE}}
mv $WORK/go/pkg/tool/{{.GOOS}}_{{.GOARCH}}/old5a{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/bin/old5a{{.EXE}}
mv $WORK/go/pkg/tool/{{.GOOS}}_{{.GOARCH}}/pack{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/bin/pack{{.EXE}}
mv $WORK/go/pkg/tool/{{.GOOS}}_{{.GOARCH}}/link{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/bin/link{{.EXE}}
go build -o $GOMOBILE/android-{{.NDK}}/arm/bin/toolexec{{.EXE}} $WORK/toolexec.go
rm -r -f "$GOROOT/pkg/android_arm" rm -r -f "$GOROOT/pkg/android_arm"
mv $WORK/go/pkg/android_arm $GOROOT/pkg/android_arm PATH=$PATH GOOS=android GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=$GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-gcc{{.EXE}} CXX=$GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-g++{{.EXE}} {{.BuildScript}}
go version > $GOMOBILE/version {{if eq .GOOS "darwin"}}rm -r -f "$GOROOT/pkg/darwin_arm"
rm -r -f "$WORK" PATH=$PATH GOOS=darwin GOARCH=arm CGO_ENABLED=1 CC=$GOROOT/misc/ios/clangwrap.sh CXX=$GOROOT/misc/ios/clangwrap.sh GOARM=7 {{.BuildScript}}
`))
var initDarwinTmpl = template.Must(template.New("output").Parse(`GOMOBILE={{.GOPATH}}/pkg/gomobile
mkdir -p $GOMOBILE/android-{{.NDK}}
WORK=/GOPATH1/pkg/gomobile/work
mkdir -p $WORK/go/pkg
cp -a $GOROOT/lib $WORK/go/lib
cp -a $GOROOT/src $WORK/go/src
cp -a $GOROOT/misc $WORK/go/misc
ln -s $GOROOT/.git $WORK/go/.git
mkdir -p $GOMOBILE/dl
curl -o$GOMOBILE/dl/gomobile-{{.NDK}}-{{.GOOS}}-{{.NDKARCH}}.tar.gz https://dl.google.com/go/mobile/gomobile-{{.NDK}}-{{.GOOS}}-{{.NDKARCH}}.tar.gz
tar xfz $GOMOBILE/dl/gomobile-{{.NDK}}-{{.GOOS}}-{{.NDKARCH}}.tar.gz
mkdir -p $GOMOBILE/android-{{.NDK}}/arm/sysroot/usr
mv $WORK/android-{{.NDK}}/platforms/android-15/arch-arm/usr/include $GOMOBILE/android-{{.NDK}}/arm/sysroot/usr/include
mv $WORK/android-{{.NDK}}/platforms/android-15/arch-arm/usr/lib $GOMOBILE/android-{{.NDK}}/arm/sysroot/usr/lib
mv $WORK/android-{{.NDK}}/toolchains/arm-linux-androideabi-4.8/prebuilt/{{.GOOS}}-{{.NDKARCH}}/bin $GOMOBILE/android-{{.NDK}}/arm/bin
mv $WORK/android-{{.NDK}}/toolchains/arm-linux-androideabi-4.8/prebuilt/{{.GOOS}}-{{.NDKARCH}}/lib $GOMOBILE/android-{{.NDK}}/arm/lib
mv $WORK/android-{{.NDK}}/toolchains/arm-linux-androideabi-4.8/prebuilt/{{.GOOS}}-{{.NDKARCH}}/libexec $GOMOBILE/android-{{.NDK}}/arm/libexec
mkdir -p $GOMOBILE/android-{{.NDK}}/arm/arm-linux-androideabi/bin
ln -s $GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-ld{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/arm-linux-androideabi/bin/ld{{.EXE}}
ln -s $GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-as{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/arm-linux-androideabi/bin/as{{.EXE}}
ln -s $GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-gcc{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/arm-linux-androideabi/bin/gcc{{.EXE}}
ln -s $GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-g++{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/arm-linux-androideabi/bin/g++{{.EXE}}
mkdir -p $GOMOBILE/dl
curl -o$GOMOBILE/dl/gomobile-openal-soft-1.16.0.1.tar.gz https://dl.google.com/go/mobile/gomobile-openal-soft-1.16.0.1.tar.gz
tar xfz $GOMOBILE/dl/gomobile-openal-soft-1.16.0.1.tar.gz
mv $WORK/openal/include/AL $GOMOBILE/android-{{.NDK}}/arm/sysroot/usr/include/AL
mkdir -p $GOMOBILE/android-{{.NDK}}/openal
mv $WORK/openal/lib $GOMOBILE/android-{{.NDK}}/openal/lib
PATH=$PATH GOOS=android GOROOT=$WORK/go GOARCH=arm GOARM=7 CGO_ENABLED=1 CC_FOR_TARGET=$GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-gcc{{.EXE}} CXX_FOR_TARGET=$GOMOBILE/android-{{.NDK}}/arm/bin/arm-linux-androideabi-g++{{.EXE}} {{.BuildScript}}
mv $WORK/go/pkg/tool/{{.GOOS}}_{{.GOARCH}}/compile{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/bin/compile{{.EXE}}
mv $WORK/go/pkg/tool/{{.GOOS}}_{{.GOARCH}}/asm{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/bin/asm{{.EXE}}
mv $WORK/go/pkg/tool/{{.GOOS}}_{{.GOARCH}}/cgo{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/bin/cgo{{.EXE}}
mv $WORK/go/pkg/tool/{{.GOOS}}_{{.GOARCH}}/nm{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/bin/nm{{.EXE}}
mv $WORK/go/pkg/tool/{{.GOOS}}_{{.GOARCH}}/old5a{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/bin/old5a{{.EXE}}
mv $WORK/go/pkg/tool/{{.GOOS}}_{{.GOARCH}}/pack{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/bin/pack{{.EXE}}
mv $WORK/go/pkg/tool/{{.GOOS}}_{{.GOARCH}}/link{{.EXE}} $GOMOBILE/android-{{.NDK}}/arm/bin/link{{.EXE}}
go build -o $GOMOBILE/android-{{.NDK}}/arm/bin/toolexec{{.EXE}} $WORK/toolexec.go
rm -r -f "$GOROOT/pkg/android_arm"
mv $WORK/go/pkg/android_arm $GOROOT/pkg/android_arm
PATH=$PATH GOOS=darwin GOROOT=$WORK/go GOARCH=arm CGO_ENABLED=1 CC_FOR_TARGET=$WORK/go/misc/ios/clangwrap.sh CXX_FOR_TARGET=$WORK/go/misc/ios/clangwrap.sh GOARM=7 TMPDIR=$WORK HOME=$HOME GOROOT_BOOTSTRAP=go1.4 $WORK/go/src/make.bash --no-clean
PATH=$PATH GOOS=darwin GOROOT=$WORK/go GOARCH=arm64 CGO_ENABLED=1 CC_FOR_TARGET=$WORK/go/misc/ios/clangwrap.sh CXX_FOR_TARGET=$WORK/go/misc/ios/clangwrap.sh TMPDIR=$WORK HOME=$HOME GOROOT_BOOTSTRAP=go1.4 $WORK/go/src/make.bash --no-clean
rm -r -f "$GOROOT/pkg/darwin_arm"
mv $WORK/go/pkg/darwin_arm $GOROOT/pkg/darwin_arm
rm -r -f "$GOROOT/pkg/darwin_arm64" rm -r -f "$GOROOT/pkg/darwin_arm64"
mv $WORK/go/pkg/darwin_arm64 $GOROOT/pkg/darwin_arm64 PATH=$PATH GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 CC=$GOROOT/misc/ios/clangwrap.sh CXX=$GOROOT/misc/ios/clangwrap.sh {{.BuildScript}}
go version > $GOMOBILE/version {{end}}go version > $GOMOBILE/version
rm -r -f "$WORK" rm -r -f "$WORK"
`)) `))

View File

@ -100,7 +100,7 @@ const documentationHeader = `// Copyright 2015 The Go Authors. All rights reser
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// DO NOT EDIT. GENERATED BY 'gomobile help documentation'. // DO NOT EDIT. GENERATED BY 'gomobile help documentation doc.go'.
` `
func helpDocumentation(path string) { func helpDocumentation(path string) {
@ -151,47 +151,16 @@ func (cmd *command) usage() {
var usageTmpl = template.Must(template.New("usage").Parse( var usageTmpl = template.Must(template.New("usage").Parse(
`Gomobile is a tool for building and running mobile apps written in Go. `Gomobile is a tool for building and running mobile apps written in Go.
Installation: To install:
$ go get golang.org/x/mobile/cmd/gomobile $ go get golang.org/x/mobile/cmd/gomobile
$ gomobile init $ gomobile init
Note that until Go 1.5 is released, you must compile Go from tip. At least Go 1.5 is required. Until it is released, build tip from
source: http://golang.org/doc/install/source
Clone the source from the tip under $HOME/go directory. On Windows, Initialization rebuilds the standard library and may download
you may like to clone the repo to your user folder, %USERPROFILE%\go. the Android NDK compiler.
$ git clone https://go.googlesource.com/go $HOME/go
Go 1.5 requires Go 1.4. Read more about this requirement at
http://golang.org/s/go15bootstrap.
Set GOROOT_BOOTSTRAP to the GOROOT of your existing 1.4 installation or
follow the steps below to checkout go1.4 from the source and build.
$ git clone https://go.googlesource.com/go $HOME/go1.4
$ cd $HOME/go1.4
$ git checkout go1.4.1
$ cd src && ./make.bash
If you clone Go 1.4 to a different destination, set GOROOT_BOOTSTRAP
environmental variable accordingly.
Build Go 1.5 and add Go 1.5 bin to your path.
$ cd $HOME/go/src && ./make.bash
$ export PATH=$PATH:$HOME/go/bin
Set a GOPATH if no GOPATH is set, add $GOPATH/bin to your path.
$ export GOPATH=$HOME
$ export PATH=$PATH:$GOPATH/bin
Now you can get the gomobile tool and initialize.
$ go get golang.org/x/mobile/cmd/gomobile
$ gomobile init
It may take a while to initialize gomobile, please wait.
Usage: Usage: