Skip to content

Commit

Permalink
cmd/gomobile: add CGO_ENABLED=1 to gobind runs
Browse files Browse the repository at this point in the history
A previous CL switched gobind to use the "source" importer so go
files using cgo can be type checked. However, CGO_ENABLED=1 also
have to be passed in for such files not be ignored.

Also add -tags ios to the gomobile test output missing from CL
99777.

Fixes golang/go#24941

Change-Id: I868469af3061b82ab592899e365a8a90a0333e58
Reviewed-on: https://go-review.googlesource.com/108336
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
  • Loading branch information
Elias Naur committed Apr 20, 2018
1 parent 18bb643 commit 6ede5c3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions bind/testdata/cgopkg/cgopkg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package cgopkg

import (
_ "golang.org/x/mobile/gl"
)

func Dummy() {}
2 changes: 2 additions & 0 deletions cmd/gobind/gobind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var tests = []struct {
{"Go-Testpkg", "go", "golang.org/x/mobile/bind/testdata/testpkg", ""},
{"Java-Javapkg", "java", "golang.org/x/mobile/bind/testdata/testpkg/javapkg", "android"},
{"Go-Javapkg", "go", "golang.org/x/mobile/bind/testdata/testpkg/javapkg", "android"},
{"Go-Javapkg", "go,java,objc", "golang.org/x/mobile/bind/testdata/cgopkg", "android"},
}

func installGobind() error {
Expand All @@ -35,6 +36,7 @@ func runGobind(lang, pkg, goos string) error {
cmd := exec.Command("gobind", "-lang", lang, pkg)
if goos != "" {
cmd.Env = append(os.Environ(), "GOOS="+goos)
cmd.Env = append(os.Environ(), "CGO_ENABLED=1")
}
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("gobind -lang %s %s failed: %v: %s", lang, pkg, err, out)
Expand Down
1 change: 1 addition & 0 deletions cmd/gomobile/bind_androidapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func goAndroidBind(gobind string, pkgs []*build.Package, androidArchs []string)
"-outdir="+tmpdir,
)
cmd.Env = append(cmd.Env, "GOOS=android")
cmd.Env = append(cmd.Env, "CGO_ENABLED=1")
if len(ctx.BuildTags) > 0 {
cmd.Args = append(cmd.Args, "-tags="+strings.Join(ctx.BuildTags, ","))
}
Expand Down
1 change: 1 addition & 0 deletions cmd/gomobile/bind_iosapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func goIOSBind(gobind string, pkgs []*build.Package, archs []string) error {
"-outdir="+tmpdir,
)
cmd.Env = append(cmd.Env, "GOOS=darwin")
cmd.Env = append(cmd.Env, "CGO_ENABLED=1")
if len(ctx.BuildTags) > 0 {
cmd.Args = append(cmd.Args, "-tags="+strings.Join(ctx.BuildTags, ","))
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/gomobile/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ func TestBindIOS(t *testing.T) {

var bindAndroidTmpl = template.Must(template.New("output").Parse(`GOMOBILE={{.GOPATH}}/pkg/gomobile
WORK=$WORK
GOOS=android gobind -lang=go,java -outdir=$WORK{{if .JavaPkg}} -javapkg={{.JavaPkg}}{{end}} golang.org/x/mobile/asset
GOOS=android CGO_ENABLED=1 gobind -lang=go,java -outdir=$WORK{{if .JavaPkg}} -javapkg={{.JavaPkg}}{{end}} golang.org/x/mobile/asset
GOOS=android GOARCH=arm CC=$GOMOBILE/ndk-toolchains/arm/bin/arm-linux-androideabi-clang CXX=$GOMOBILE/ndk-toolchains/arm/bin/arm-linux-androideabi-clang++ CGO_ENABLED=1 GOARM=7 GOPATH=$WORK:$GOPATH go build -x -buildmode=c-shared -o=$WORK/android/src/main/jniLibs/armeabi-v7a/libgojni.so gobind
PWD=$WORK/java javac -d $WORK/javac-output -source 1.7 -target 1.7 -bootclasspath {{.AndroidPlatform}}/android.jar *.java
jar c -C $WORK/javac-output .
`))

var bindIOSTmpl = template.Must(template.New("output").Parse(`GOMOBILE={{.GOPATH}}/pkg/gomobile
WORK=$WORK
GOOS=darwin gobind -lang=go,objc -outdir=$WORK{{if .Prefix}} -prefix={{.Prefix}}{{end}} golang.org/x/mobile/asset
GOOS=darwin CGO_ENABLED=1 gobind -lang=go,objc -outdir=$WORK -tags=ios{{if .Prefix}} -prefix={{.Prefix}}{{end}} golang.org/x/mobile/asset
GOARM=7 GOOS=darwin GOARCH=arm 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 GOPATH=$WORK:$GOPATH go build -tags ios -x -buildmode=c-archive -o $WORK/asset-arm.a gobind
rm -r -f "Asset.framework"
mkdir -p Asset.framework/Versions/A/Headers
Expand Down

0 comments on commit 6ede5c3

Please sign in to comment.