mobile/cmd/gomobile: install darwin/arm and darwin/arm64 compilers
Change-Id: I16fe8db9ac9e22c7ba9c821b4d8bf858ab28f5f8 Reviewed-on: https://go-review.googlesource.com/11237 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
7319e3567c
commit
8fff803af0
@ -208,38 +208,14 @@ func runInit(cmd *command) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Move pre-compiled stdlib for android into GOROOT. This is
|
||||
// the only time we modify the user's GOROOT.
|
||||
cannotRemove := false
|
||||
if err := removeAll(filepath.Join(goroot, "pkg/android_arm")); err != nil {
|
||||
cannotRemove = true
|
||||
if err := installCC("android", "arm"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := move(filepath.Join(goroot, "pkg"), filepath.Join(tmpGoroot, "pkg"), "android_arm"); err != nil {
|
||||
// Move android_arm into a temp directory that outlives
|
||||
// this process and give the user installation instructions.
|
||||
dir, err := ioutil.TempDir("", "gomobile-")
|
||||
if err != nil {
|
||||
|
||||
if runtime.GOOS == "darwin" {
|
||||
if err := buildDarwinARMCC(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := move(dir, filepath.Join(tmpGoroot, "pkg"), "android_arm"); err != nil {
|
||||
return err
|
||||
}
|
||||
remove := ""
|
||||
if cannotRemove {
|
||||
if goos == "windows" {
|
||||
remove = "\trd /s /q %s\\pkg\\android_arm\n"
|
||||
} else {
|
||||
remove = "\trm -r -f %s/pkg/android_arm\n"
|
||||
}
|
||||
}
|
||||
return fmt.Errorf(
|
||||
`Cannot install android/arm in GOROOT.
|
||||
Make GOROOT writable (possibly by becoming the super user, using sudo) and run:
|
||||
%s mv %s %s`,
|
||||
remove,
|
||||
filepath.Join(dir, "android_arm"),
|
||||
filepath.Join(goroot, "pkg"),
|
||||
)
|
||||
}
|
||||
|
||||
if buildX {
|
||||
@ -253,17 +229,18 @@ Make GOROOT writable (possibly by becoming the super user, using sudo) and run:
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO(jbd): buildDarwinARMCC is not invoked from anywhere yet.
|
||||
// Once it is stable, it will be invoked from runInit.
|
||||
|
||||
func buildDarwinARMCC() error {
|
||||
envpath := os.Getenv("PATH")
|
||||
if buildN {
|
||||
envpath = "$PATH"
|
||||
}
|
||||
tmpGoroot := filepath.Join(tmpdir, "go")
|
||||
|
||||
makeCC := func(arch string) error {
|
||||
m := exec.Command(filepath.Join(tmpGoroot, "src/make.bash"), "--no-clean")
|
||||
m.Dir = filepath.Join(tmpGoroot, "src")
|
||||
m.Env = []string{
|
||||
`PATH=` + os.Getenv("PATH"),
|
||||
`PATH=` + envpath,
|
||||
`GOOS=darwin`,
|
||||
`GOROOT=` + tmpGoroot, // set to override any bad os.Environ
|
||||
`GOARCH=` + arch,
|
||||
@ -299,9 +276,24 @@ func buildDarwinARMCC() error {
|
||||
if err := makeCC("arm64"); err != nil {
|
||||
return nil
|
||||
}
|
||||
// TODO(jbd): Move the prebuilt library to the GOROOT.
|
||||
// mv tmpGoroot/pkg/darwin_arm GOROOT/pkg/darwin_arm
|
||||
// mv tmpGoroot/pkg/darwin_arm64 GOROOT/pkg/darwin_arm64
|
||||
if err := installCC("darwin", "arm"); err != nil {
|
||||
return err
|
||||
}
|
||||
return installCC("darwin", "arm64")
|
||||
}
|
||||
|
||||
func installCC(goos, goarch string) error {
|
||||
goroot := goEnv("GOROOT")
|
||||
tmpGoroot := filepath.Join(tmpdir, "go")
|
||||
// Move pre-compiled stdlib for GOROOT. This is
|
||||
// the only time we modify the user's GOROOT.
|
||||
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)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"text/template"
|
||||
@ -41,7 +42,12 @@ func TestInit(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
diff, err := diffOutput(buf.String(), initTmpl)
|
||||
tmpl := initTmpl
|
||||
if runtime.GOOS == "darwin" {
|
||||
tmpl = initDarwinTmpl
|
||||
}
|
||||
|
||||
diff, err := diffOutput(buf.String(), tmpl)
|
||||
if err != nil {
|
||||
t.Fatalf("computing diff failed: %v", err)
|
||||
}
|
||||
@ -133,3 +139,52 @@ mv $WORK/go/pkg/android_arm $GOROOT/pkg/android_arm
|
||||
go version > $GOMOBILE/version
|
||||
rm -r -f "$WORK"
|
||||
`))
|
||||
|
||||
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"
|
||||
mv $WORK/go/pkg/darwin_arm64 $GOROOT/pkg/darwin_arm64
|
||||
go version > $GOMOBILE/version
|
||||
rm -r -f "$WORK"
|
||||
`))
|
||||
|
Loading…
x
Reference in New Issue
Block a user