From e2c45a883cae913a66a1b4011e7993ff3a415c28 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 5 Mar 2020 13:56:50 +0000 Subject: [PATCH] cmd/gomobile: disable bitcode on Go 1.13 or older iOS's bitcode conflicts with headerpad on Go 1.13 or older. This problem is fixed on Go 1.14. This CL disables bitcode only on Go 1.13 or older. Fixes golang/go#32963 Cherry picked from github.com/golang/mobile --- cmd/fyne/internal/mobile/build_iosapp.go | 19 +++++++++++++++---- cmd/fyne/internal/mobile/env.go | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/cmd/fyne/internal/mobile/build_iosapp.go b/cmd/fyne/internal/mobile/build_iosapp.go index b28bb786ba..60efe6c2d5 100644 --- a/cmd/fyne/internal/mobile/build_iosapp.go +++ b/cmd/fyne/internal/mobile/build_iosapp.go @@ -24,6 +24,13 @@ func goIOSBuild(pkg *packages.Package, bundleID string, archs []string, appName src := pkg.PkgPath buildO = rfc1034Label(appName) + ".app" + projPbxproj := new(bytes.Buffer) + if err := projPbxprojTmpl.Execute(projPbxproj, projPbxprojTmplData{ + BitcodeEnabled: bitcodeEnabled, + }); err != nil { + return nil, err + } + infoplist := new(bytes.Buffer) if err := infoplistTmpl.Execute(infoplist, infoplistTmplData{ BundleID: bundleID, @@ -36,7 +43,7 @@ func goIOSBuild(pkg *packages.Package, bundleID string, archs []string, appName name string contents []byte }{ - {tmpdir + "/main.xcodeproj/project.pbxproj", []byte(projPbxproj)}, + {tmpdir + "/main.xcodeproj/project.pbxproj", projPbxproj.Bytes()}, {tmpdir + "/main/Info.plist", infoplist.Bytes()}, {tmpdir + "/main/Images.xcassets/AppIcon.appiconset/Contents.json", []byte(contentsJSON)}, } @@ -263,7 +270,11 @@ var infoplistTmpl = template.Must(template.New("infoplist").Parse(` `)) -const projPbxproj = `// !$*UTF8*$! +type projPbxprojTmplData struct { + BitcodeEnabled bool +} + +var projPbxprojTmpl = template.Must(template.New("projPbxproj").Parse(`// !$*UTF8*$! { archiveVersion = 1; classes = { @@ -421,7 +432,7 @@ const projPbxproj = `// !$*UTF8*$! SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; - ENABLE_BITCODE = NO; + {{if not .BitcodeEnabled}}ENABLE_BITCODE = NO;{{end}} }; name = Release; }; @@ -458,7 +469,7 @@ const projPbxproj = `// !$*UTF8*$! }; rootObject = 254BB8361B1FD08900C56DE9 /* Project object */; } -` +`)) const contentsJSON = `{ "images" : [ diff --git a/cmd/fyne/internal/mobile/env.go b/cmd/fyne/internal/mobile/env.go index 0aab213753..a838b9fb2e 100644 --- a/cmd/fyne/internal/mobile/env.go +++ b/cmd/fyne/internal/mobile/env.go @@ -23,6 +23,8 @@ var ( darwinArmNM string allArchs = []string{"arm", "arm64", "386", "amd64"} + + bitcodeEnabled bool ) func buildEnvInit() (cleanup func(), err error) { @@ -73,6 +75,15 @@ func buildEnvInit() (cleanup func(), err error) { } func envInit() (err error) { + // Check the current Go version by go-list. + out, err := exec.Command("go", "list", "-e", "-f", `{{range context.ReleaseTags}}{{if eq . "go1.14"}}{{.}}{{end}}{{end}}`).Output() + if err != nil { + return err + } + if len(strings.TrimSpace(string(out))) > 0 { + bitcodeEnabled = true + } + // Setup the cross-compiler environments. if ndkRoot, err := ndkRoot(); err == nil { androidEnv = make(map[string][]string) @@ -136,6 +147,10 @@ func envInit() (err error) { if err != nil { return err } + + if bitcodeEnabled { + cflags += " -fembed-bitcode" + } env = append(env, "GOOS=darwin", "GOARCH="+arch,