Skip to content

Commit

Permalink
cmd/gomobile: disable bitcode on Go 1.13 or older
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hajimehoshi authored and andydotxyz committed Apr 5, 2020
1 parent e2bfbda commit e2c45a8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
19 changes: 15 additions & 4 deletions cmd/fyne/internal/mobile/build_iosapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)},
}
Expand Down Expand Up @@ -263,7 +270,11 @@ var infoplistTmpl = template.Must(template.New("infoplist").Parse(`<?xml version
</plist>
`))

const projPbxproj = `// !$*UTF8*$!
type projPbxprojTmplData struct {
BitcodeEnabled bool
}

var projPbxprojTmpl = template.Must(template.New("projPbxproj").Parse(`// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -458,7 +469,7 @@ const projPbxproj = `// !$*UTF8*$!
};
rootObject = 254BB8361B1FD08900C56DE9 /* Project object */;
}
`
`))

const contentsJSON = `{
"images" : [
Expand Down
15 changes: 15 additions & 0 deletions cmd/fyne/internal/mobile/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var (
darwinArmNM string

allArchs = []string{"arm", "arm64", "386", "amd64"}

bitcodeEnabled bool
)

func buildEnvInit() (cleanup func(), err error) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e2c45a8

Please sign in to comment.