Skip to content

Commit e1251fe

Browse files
committed
Merge remote-tracking branch 'origin/master' into fix-android-minsdk-usage-in-binres
2 parents a0bd17f + b38b881 commit e1251fe

21 files changed

+102
-99
lines changed

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2009 The Go Authors. All rights reserved.
1+
Copyright 2009 The Go Authors.
22

33
Redistribution and use in source and binary forms, with or without
44
modification, are permitted provided that the following conditions are
@@ -10,7 +10,7 @@ notice, this list of conditions and the following disclaimer.
1010
copyright notice, this list of conditions and the following disclaimer
1111
in the documentation and/or other materials provided with the
1212
distribution.
13-
* Neither the name of Google Inc. nor the names of its
13+
* Neither the name of Google LLC nor the names of its
1414
contributors may be used to endorse or promote products derived from
1515
this software without specific prior written permission.
1616

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ and the [bind](https://golang.org/x/mobile/example/bind) example apps.
2424

2525
--
2626

27-
Contributions to Go are appreciated. See https://golang.org/doc/contribute.html.
27+
Contributions to Go are appreciated. See https://go.dev/doc/contribute.
2828

29-
* Bugs can be filed at the [Go issue tracker](https://golang.org/issue/new?title=x/mobile:+).
29+
The git repository is https://go.googlesource.com/mobile.
30+
31+
* Bugs can be filed at the [Go issue tracker](https://go.dev/issue/new?title=x/mobile:+).
3032
* Feature requests should preliminary be discussed on
3133
[golang-nuts](https://groups.google.com/forum/#!forum/golang-nuts)
3234
mailing list.

app/android.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ func runInputQueue(vm, jniEnv, ctx uintptr) error {
365365

366366
var q *C.AInputQueue
367367
for {
368-
if C.ALooper_pollAll(-1, nil, nil, nil) == C.ALOOPER_POLL_WAKE {
368+
if C.ALooper_pollOnce(-1, nil, nil, nil) == C.ALOOPER_POLL_WAKE {
369369
select {
370370
default:
371371
case p := <-pending:

asset/asset_darwin_armx.go

Lines changed: 0 additions & 23 deletions
This file was deleted.

asset/asset_desktop.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build (linux && !android) || (darwin && !arm && !arm64) || windows
5+
//go:build (linux && !android) || (darwin && !ios) || windows
66

77
package asset
88

asset/asset_ios.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2024 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package asset
6+
7+
import (
8+
"os"
9+
)
10+
11+
func openAsset(name string) (File, error) {
12+
return os.Open(name)
13+
}

bind/genclasses.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ func (g *ClassGen) genCMethodBody(cls *java.Class, f *java.Func, virtual bool) {
381381
g.Printf("Nonvirtual")
382382
}
383383
if f.Ret != nil {
384-
g.Printf(f.Ret.JNICallType())
384+
g.Printf("%s", f.Ret.JNICallType())
385385
} else {
386386
g.Printf("Void")
387387
}
@@ -430,7 +430,7 @@ func (g *ClassGen) genFuncDecl(local bool, fs *java.FuncSet) {
430430
if i == len(fs.Params)-1 && fs.Variadic {
431431
g.Printf("...")
432432
}
433-
g.Printf(g.goType(a, local))
433+
g.Printf("%s", g.goType(a, local))
434434
}
435435
g.Printf(")")
436436
if fs.Throws {
@@ -879,7 +879,7 @@ func (g *ClassGen) genInterface(cls *java.Class) {
879879
if !g.isFuncSetSupported(fs) {
880880
continue
881881
}
882-
g.Printf(fs.GoName)
882+
g.Printf("%s", fs.GoName)
883883
g.genFuncDecl(true, fs)
884884
g.Printf("\n")
885885
}
@@ -904,7 +904,7 @@ func flattenName(n string) string {
904904
return strings.Replace(strings.Replace(n, ".", "_", -1), "$", "_", -1)
905905
}
906906

907-
var (
907+
const (
908908
classesPkgHeader = gobindPreamble + `
909909
package Java
910910

bind/gengo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ func (g *goGen) genInterface(obj *types.TypeName) {
341341
g.Printf(") ")
342342

343343
if res.Len() == 1 {
344-
g.Printf(g.typeString(res.At(0).Type()))
344+
g.Printf("%s", g.typeString(res.At(0).Type()))
345345
} else if res.Len() == 2 {
346346
g.Printf("(%s, error)", g.typeString(res.At(0).Type()))
347347
}

bind/genjava.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func (g *JavaGen) genConstructor(f *types.Func, n string, jcls bool) {
437437
if i > 0 {
438438
g.Printf(", ")
439439
}
440-
g.Printf(g.paramName(params, i))
440+
g.Printf("%s", g.paramName(params, i))
441441
}
442442
g.Printf(");\n")
443443
}
@@ -447,7 +447,7 @@ func (g *JavaGen) genConstructor(f *types.Func, n string, jcls bool) {
447447
if i > 0 {
448448
g.Printf(", ")
449449
}
450-
g.Printf(g.paramName(params, i))
450+
g.Printf("%s", g.paramName(params, i))
451451
}
452452
g.Printf(");\n")
453453
g.Printf("Seq.trackGoRef(refnum, this);\n")
@@ -757,21 +757,21 @@ func (g *JavaGen) genJNIFuncSignature(o *types.Func, sName string, jm *java.Func
757757
g.Printf("Java_%s_", g.jniPkgName())
758758
if sName != "" {
759759
if proxy {
760-
g.Printf(java.JNIMangle(g.className()))
760+
g.Printf("%s", java.JNIMangle(g.className()))
761761
// 0024 is the mangled form of $, for naming inner classes.
762762
g.Printf("_00024proxy%s", sName)
763763
} else {
764-
g.Printf(java.JNIMangle(g.javaTypeName(sName)))
764+
g.Printf("%s", java.JNIMangle(g.javaTypeName(sName)))
765765
}
766766
} else {
767-
g.Printf(java.JNIMangle(g.className()))
767+
g.Printf("%s", java.JNIMangle(g.className()))
768768
}
769769
g.Printf("_")
770770
if jm != nil {
771-
g.Printf(jm.JNIName)
771+
g.Printf("%s", jm.JNIName)
772772
} else {
773773
oName := javaNameReplacer(lowerFirst(o.Name()))
774-
g.Printf(java.JNIMangle(oName))
774+
g.Printf("%s", java.JNIMangle(oName))
775775
}
776776
g.Printf("(JNIEnv* env, ")
777777
if sName != "" {
@@ -839,9 +839,9 @@ func (g *JavaGen) genFuncSignature(o *types.Func, jm *java.Func, hasThis bool) {
839839

840840
g.Printf("%s ", ret)
841841
if jm != nil {
842-
g.Printf(jm.Name)
842+
g.Printf("%s", jm.Name)
843843
} else {
844-
g.Printf(javaNameReplacer(lowerFirst(o.Name())))
844+
g.Printf("%s", javaNameReplacer(lowerFirst(o.Name())))
845845
}
846846
g.Printf("(")
847847
g.genFuncArgs(o, jm, hasThis)

bind/genobjc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ func (g *ObjcGen) genStructH(obj *types.TypeName, t *types.Struct) {
10601060
if oinf != nil {
10611061
for _, sup := range oinf.supers {
10621062
if !sup.Protocol {
1063-
g.Printf(sup.Name)
1063+
g.Printf("%s", sup.Name)
10641064
} else {
10651065
prots = append(prots, sup.Name)
10661066
}

bind/genobjcw.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,13 @@ func (g *ObjcWrapper) genCFuncDecl(prefix, name string, f *objc.Func) {
286286
case ret != nil && returnsErr:
287287
g.Printf("ret_%s", strings.Replace(g.cType(ret), " ", "_", -1))
288288
case ret != nil:
289-
g.Printf(g.cType(ret))
289+
g.Printf("%s", g.cType(ret))
290290
case returnsErr:
291291
g.Printf("int")
292292
default:
293293
g.Printf("void")
294294
}
295-
g.Printf(" ")
296-
g.Printf(prefix)
295+
g.Printf(" %s", prefix)
297296
if f.Static {
298297
g.Printf("_s")
299298
}
@@ -397,8 +396,7 @@ func (g *ObjcWrapper) genFuncBody(n *objc.Named, f *objc.Func, prefix string) {
397396
if ret != nil || errParam != nil {
398397
g.Printf("res := ")
399398
}
400-
g.Printf("C.")
401-
g.Printf(prefix)
399+
g.Printf("C.%s", prefix)
402400
if f.Static {
403401
g.Printf("_s")
404402
}
@@ -575,7 +573,7 @@ func (g *ObjcWrapper) genInterface(n *objc.Named) {
575573
if !g.isFuncSupported(f) {
576574
continue
577575
}
578-
g.Printf(f.GoName)
576+
g.Printf("%s", f.GoName)
579577
g.genFuncDecl(true, f)
580578
g.Printf("\n")
581579
}

cmd/gomobile/bind_iosapp.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"strconv"
1616
"strings"
1717
"text/template"
18+
"time"
1819

1920
"golang.org/x/sync/errgroup"
2021
"golang.org/x/tools/go/packages"
@@ -233,9 +234,11 @@ func goAppleBind(gobind string, pkgs []*packages.Package, targets []targetInfo)
233234
return err
234235
}
235236
err = writeFile(filepath.Join(frameworkInfoPlistDir, "Info.plist"), func(w io.Writer) error {
237+
fmVersion := fmt.Sprintf("0.0.%d", time.Now().Unix())
236238
infoFrameworkPlistlData := infoFrameworkPlistlData{
237239
BundleID: escapePlistValue(rfc1034Label(title)),
238240
ExecutableName: escapePlistValue(title),
241+
Version: escapePlistValue(fmVersion),
239242
}
240243
infoplist := new(bytes.Buffer)
241244
if err := infoFrameworkPlistTmpl.Execute(infoplist, infoFrameworkPlistlData); err != nil {
@@ -333,6 +336,7 @@ func frameworkLayoutForTarget(t targetInfo, title string) (*frameworkLayout, err
333336
type infoFrameworkPlistlData struct {
334337
BundleID string
335338
ExecutableName string
339+
Version string
336340
}
337341

338342
// infoFrameworkPlistTmpl is a template for the Info.plist file in a framework.
@@ -348,6 +352,10 @@ var infoFrameworkPlistTmpl = template.Must(template.New("infoFrameworkPlist").Pa
348352
<string>{{.BundleID}}</string>
349353
<key>MinimumOSVersion</key>
350354
<string>100.0</string>
355+
<key>CFBundleShortVersionString</key>
356+
<string>{{.Version}}</string>
357+
<key>CFBundleVersion</key>
358+
<string>{{.Version}}</string>
351359
<key>CFBundlePackageType</key>
352360
<string>FMWK</string>
353361
</dict>

cmd/gomobile/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func runBuildImpl(cmd *command) (*packages.Package, error) {
160160
return pkg, nil
161161
}
162162
if buildBundleID == "" {
163-
return nil, fmt.Errorf("-target=ios requires -bundleid set")
163+
return nil, fmt.Errorf("-target=%s requires -bundleid set", buildTarget)
164164
}
165165
nmpkgs, err = goAppleBuild(pkg, buildBundleID, targets)
166166
if err != nil {

cmd/gomobile/env.go

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ func platformOS(platform string) string {
6363
case "macos", "maccatalyst":
6464
// For "maccatalyst", Go packages should be built with GOOS=darwin,
6565
// not GOOS=ios, since the underlying OS (and kernel, runtime) is macOS.
66+
// But, using GOOS=darwin with build-tag ios leads to corrupt builds: https://go.dev/issue/52299
67+
// => So we use GOOS=ios for now.
6668
// We also apply a "macos" or "maccatalyst" build tag, respectively.
6769
// See below for additional context.
68-
return "darwin"
70+
return "ios"
6971
default:
7072
panic(fmt.Sprintf("unexpected platform: %s", platform))
7173
}
@@ -82,17 +84,17 @@ func platformTags(platform string) []string {
8284
case "maccatalyst":
8385
// Mac Catalyst is a subset of iOS APIs made available on macOS
8486
// designed to ease porting apps developed for iPad to macOS.
85-
// See https://developer.apple.com/mac-catalyst/.
86-
// Because of this, when building a Go package targeting maccatalyst,
87-
// GOOS=darwin (not ios). To bridge the gap and enable maccatalyst
88-
// packages to be compiled, we also specify the "ios" build tag.
87+
// See
88+
// https://developer.apple.com/mac-catalyst/.
89+
// https://stackoverflow.com/questions/12132933/preprocessor-macro-for-os-x-targets/49560690#49560690
90+
//
91+
// Historically gomobile used GOOS=darwin with build tag ios when
92+
// targeting Mac Catalyst. However, this configuration is not officially
93+
// supported and leads to corrupt builds after go1.18: https://go.dev/issues/52299
94+
// Use GOOS=ios.
8995
// To help discriminate between darwin, ios, macos, and maccatalyst
9096
// targets, there is also a "maccatalyst" tag.
91-
// Some additional context on this can be found here:
92-
// https://stackoverflow.com/questions/12132933/preprocessor-macro-for-os-x-targets/49560690#49560690
93-
// TODO(ydnar): remove tag "ios" when cgo supports Catalyst
94-
// See golang.org/issues/47228
95-
return []string{"ios", "macos", "maccatalyst"}
97+
return []string{"macos", "maccatalyst"}
9698
default:
9799
panic(fmt.Sprintf("unexpected platform: %s", platform))
98100
}
@@ -217,17 +219,11 @@ func envInit() (err error) {
217219
cflags += " -mios-simulator-version-min=" + buildIOSVersion
218220
cflags += " -fembed-bitcode"
219221
case "maccatalyst":
220-
// Mac Catalyst is a subset of iOS APIs made available on macOS
221-
// designed to ease porting apps developed for iPad to macOS.
222-
// See https://developer.apple.com/mac-catalyst/.
223-
// Because of this, when building a Go package targeting maccatalyst,
224-
// GOOS=darwin (not ios). To bridge the gap and enable maccatalyst
225-
// packages to be compiled, we also specify the "ios" build tag.
226-
// To help discriminate between darwin, ios, macos, and maccatalyst
227-
// targets, there is also a "maccatalyst" tag.
228-
// Some additional context on this can be found here:
229-
// https://stackoverflow.com/questions/12132933/preprocessor-macro-for-os-x-targets/49560690#49560690
230-
goos = "darwin"
222+
// See the comment about maccatalyst's GOOS, build tags configuration
223+
// in platformOS and platformTags.
224+
// Using GOOS=darwin with build-tag ios leads to corrupt builds: https://go.dev/issue/52299
225+
// => So we use GOOS=ios for now.
226+
goos = "ios"
231227
sdk = "macosx"
232228
clang, cflags, err = envClang(sdk)
233229
// TODO(ydnar): the following 3 lines MAY be needed to compile
@@ -436,15 +432,21 @@ func envClang(sdkName string) (clang, cflags string, err error) {
436432
return sdkName + "-clang", "-isysroot " + sdkName, nil
437433
}
438434
cmd := exec.Command("xcrun", "--sdk", sdkName, "--find", "clang")
439-
out, err := cmd.CombinedOutput()
435+
out, err := cmd.Output()
440436
if err != nil {
437+
if ee := (*exec.ExitError)(nil); errors.As(err, &ee) {
438+
out = append(out, ee.Stderr...)
439+
}
441440
return "", "", fmt.Errorf("xcrun --find: %v\n%s", err, out)
442441
}
443442
clang = strings.TrimSpace(string(out))
444443

445444
cmd = exec.Command("xcrun", "--sdk", sdkName, "--show-sdk-path")
446-
out, err = cmd.CombinedOutput()
445+
out, err = cmd.Output()
447446
if err != nil {
447+
if ee := (*exec.ExitError)(nil); errors.As(err, &ee) {
448+
out = append(out, ee.Stderr...)
449+
}
448450
return "", "", fmt.Errorf("xcrun --show-sdk-path: %v\n%s", err, out)
449451
}
450452
sdk := strings.TrimSpace(string(out))

example/ivy/tools.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build ignore
5+
//go:build tools
66

77
package dummy
88

exp/sensor/android.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int GoAndroid_readQueue(int n, int32_t* types, int64_t* timestamps, float* vecto
6161
// Try n times read from the event queue.
6262
// If anytime timeout occurs, don't retry to read and immediately return.
6363
// Consume the event queue entirely between polls.
64-
while (i < n && (id = ALooper_pollAll(GO_ANDROID_READ_TIMEOUT_MS, NULL, &events, NULL)) >= 0) {
64+
while (i < n && (id = ALooper_pollOnce(GO_ANDROID_READ_TIMEOUT_MS, NULL, &events, NULL)) >= 0) {
6565
if (id != GO_ANDROID_SENSOR_LOOPER_ID) {
6666
continue;
6767
}

0 commit comments

Comments
 (0)