Skip to content

Commit 5d5d88d

Browse files
author
Elias Naur
committed
cmd/gomobile: add CGO_ENABLED=1 to gobind runs
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]>
1 parent 9422505 commit 5d5d88d

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

bind/testdata/cgopkg/cgopkg.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package cgopkg
2+
3+
import (
4+
_ "golang.org/x/mobile/gl"
5+
)
6+
7+
func Dummy() {}

cmd/gobind/gobind_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var tests = []struct {
2222
{"Go-Testpkg", "go", "golang.org/x/mobile/bind/testdata/testpkg", ""},
2323
{"Java-Javapkg", "java", "golang.org/x/mobile/bind/testdata/testpkg/javapkg", "android"},
2424
{"Go-Javapkg", "go", "golang.org/x/mobile/bind/testdata/testpkg/javapkg", "android"},
25+
{"Go-Javapkg", "go,java,objc", "golang.org/x/mobile/bind/testdata/cgopkg", "android"},
2526
}
2627

2728
func installGobind() error {
@@ -35,6 +36,7 @@ func runGobind(lang, pkg, goos string) error {
3536
cmd := exec.Command("gobind", "-lang", lang, pkg)
3637
if goos != "" {
3738
cmd.Env = append(os.Environ(), "GOOS="+goos)
39+
cmd.Env = append(os.Environ(), "CGO_ENABLED=1")
3840
}
3941
if out, err := cmd.CombinedOutput(); err != nil {
4042
return fmt.Errorf("gobind -lang %s %s failed: %v: %s", lang, pkg, err, out)

cmd/gomobile/bind_androidapp.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func goAndroidBind(gobind string, pkgs []*build.Package, androidArchs []string)
3434
"-outdir="+tmpdir,
3535
)
3636
cmd.Env = append(cmd.Env, "GOOS=android")
37+
cmd.Env = append(cmd.Env, "CGO_ENABLED=1")
3738
if len(ctx.BuildTags) > 0 {
3839
cmd.Args = append(cmd.Args, "-tags="+strings.Join(ctx.BuildTags, ","))
3940
}

cmd/gomobile/bind_iosapp.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func goIOSBind(gobind string, pkgs []*build.Package, archs []string) error {
2222
"-outdir="+tmpdir,
2323
)
2424
cmd.Env = append(cmd.Env, "GOOS=darwin")
25+
cmd.Env = append(cmd.Env, "CGO_ENABLED=1")
2526
if len(ctx.BuildTags) > 0 {
2627
cmd.Args = append(cmd.Args, "-tags="+strings.Join(ctx.BuildTags, ","))
2728
}

cmd/gomobile/bind_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ func TestBindIOS(t *testing.T) {
175175

176176
var bindAndroidTmpl = template.Must(template.New("output").Parse(`GOMOBILE={{.GOPATH}}/pkg/gomobile
177177
WORK=$WORK
178-
GOOS=android gobind -lang=go,java -outdir=$WORK{{if .JavaPkg}} -javapkg={{.JavaPkg}}{{end}} golang.org/x/mobile/asset
178+
GOOS=android CGO_ENABLED=1 gobind -lang=go,java -outdir=$WORK{{if .JavaPkg}} -javapkg={{.JavaPkg}}{{end}} golang.org/x/mobile/asset
179179
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
180180
PWD=$WORK/java javac -d $WORK/javac-output -source 1.7 -target 1.7 -bootclasspath {{.AndroidPlatform}}/android.jar *.java
181181
jar c -C $WORK/javac-output .
182182
`))
183183

184184
var bindIOSTmpl = template.Must(template.New("output").Parse(`GOMOBILE={{.GOPATH}}/pkg/gomobile
185185
WORK=$WORK
186-
GOOS=darwin gobind -lang=go,objc -outdir=$WORK{{if .Prefix}} -prefix={{.Prefix}}{{end}} golang.org/x/mobile/asset
186+
GOOS=darwin CGO_ENABLED=1 gobind -lang=go,objc -outdir=$WORK -tags=ios{{if .Prefix}} -prefix={{.Prefix}}{{end}} golang.org/x/mobile/asset
187187
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
188188
rm -r -f "Asset.framework"
189189
mkdir -p Asset.framework/Versions/A/Headers

0 commit comments

Comments
 (0)