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,