2
0
mirror of synced 2025-02-23 23:08:14 +00:00

mobile/cmd/gomobile: add iOS binary builder from darwin/arm

This is the initial CL of a series to add iOS build support for
darwin/arm and darwin/arm64.

The builder utility is not invoked during $ gomobile build currently.

gomobile build will invoke goIOSBuild and codesign the generated
binary with assets available on the source directory to build an app
file. This app file might converted into an IPA as an ad-hoc
distribution archive.

darwin/arm and darwin/arm64 cross builders need to be built during
gomobile initialization step and tools need to be moved under
$GOROOT/pkg/gomobile/ios.

Change-Id: Ifb8d3c0f37611c78ca9c8887a367750fb98a546a
Reviewed-on: https://go-review.googlesource.com/10085
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
Burcu Dogan 2015-05-14 14:33:56 -07:00
parent 6e800237e4
commit a5e8a96a7f
2 changed files with 62 additions and 8 deletions

View File

@ -129,7 +129,7 @@ func runBind(cmd *command) error {
androidDir := filepath.Join(tmpdir, "android") androidDir := filepath.Join(tmpdir, "android")
err = gobuild(mainFile, filepath.Join(androidDir, "src/main/jniLibs/armeabi-v7a/libgojni.so")) err = goAndroidBuild(mainFile, filepath.Join(androidDir, "src/main/jniLibs/armeabi-v7a/libgojni.so"))
if err != nil { if err != nil {
return err return err
} }

View File

@ -17,6 +17,7 @@ import (
"os/exec" "os/exec"
"path" "path"
"path/filepath" "path/filepath"
"runtime"
"strconv" "strconv"
"strings" "strings"
) )
@ -83,7 +84,7 @@ func runBuild(cmd *command) (err error) {
if pkg.Name != "main" { if pkg.Name != "main" {
// Not an app, don't build a final package. // Not an app, don't build a final package.
return gobuild(pkg.ImportPath, "") return goAndroidBuild(pkg.ImportPath, "")
} }
// Building a program, make sure it is appropriate for mobile. // Building a program, make sure it is appropriate for mobile.
@ -140,7 +141,7 @@ func runBuild(cmd *command) (err error) {
} }
libPath := filepath.Join(tmpdir, "lib"+libName+".so") libPath := filepath.Join(tmpdir, "lib"+libName+".so")
if err := gobuild(pkg.ImportPath, libPath); err != nil { if err := goAndroidBuild(pkg.ImportPath, libPath); err != nil {
return err return err
} }
block, _ := pem.Decode([]byte(debugCert)) block, _ := pem.Decode([]byte(debugCert))
@ -273,10 +274,13 @@ func runBuild(cmd *command) (err error) {
// TODO: add gdbserver to apk? // TODO: add gdbserver to apk?
if buildN { if !buildN {
return nil if err := apkw.Close(); err != nil {
return err
}
} }
return apkw.Close()
return nil
} }
var xout io.Writer = os.Stderr var xout io.Writer = os.Stderr
@ -323,9 +327,59 @@ func addBuildFlagsNVX(cmd *command) {
cmd.flag.BoolVar(&buildX, "x", false, "") cmd.flag.BoolVar(&buildX, "x", false, "")
} }
// gobuild builds a package. // TODO(jbd): Build darwin/arm cross compiler during gomobile init.
func goIOSBuild(src string) error {
// iOS builds are achievable only if the host machine is darwin.
if runtime.GOOS != "darwin" {
return nil
}
goroot := goEnv("GOROOT")
gopath := goEnv("GOPATH")
gocmd := exec.Command(
`go`,
`build`,
`-tags=`+strconv.Quote(strings.Join(ctx.BuildTags, ",")))
if buildV {
gocmd.Args = append(gocmd.Args, "-v")
}
if buildI {
gocmd.Args = append(gocmd.Args, "-i")
}
if buildX {
gocmd.Args = append(gocmd.Args, "-x")
}
gocmd.Args = append(gocmd.Args, src)
// TODO(jbd): Return a user-friendly error if xcode command line
// tools are not available.
gocmd.Stdout = os.Stdout
gocmd.Stderr = os.Stderr
gocmd.Env = []string{
`GOOS=darwin`,
`GOARCH=arm`, // TODO(jbd): Build for arm64
`GOARM=7`,
`CGO_ENABLED=1`,
`CC=` + filepath.Join(goroot, "misc/ios/clangwrap.sh"), // TODO(jbd): reimplement clangwrap here.
`CXX=` + filepath.Join(goroot, "misc/ios/clangwrap.sh"),
`GOROOT=` + goroot,
`GOPATH=` + gopath,
}
if buildX {
printcmd("%s", strings.Join(gocmd.Env, " ")+" "+strings.Join(gocmd.Args, " "))
}
if !buildN {
gocmd.Env = environ(gocmd.Env)
if err := gocmd.Run(); err != nil {
return err
}
}
return nil
}
// goAndroidBuild builds a package.
// If libPath is specified then it builds as a shared library. // If libPath is specified then it builds as a shared library.
func gobuild(src, libPath string) error { func goAndroidBuild(src, libPath string) error {
version, err := goVersion() version, err := goVersion()
if err != nil { if err != nil {
return err return err