2
0
mirror of synced 2025-02-24 15:28:28 +00:00

281 Commits

Author SHA1 Message Date
Daniel Skinner
eed0461ac2 cmd/gomobile: icon support for android
Provides support for resources.arsc generation enabling
the setting of an application icon.

If an asset/icon.png is encountered during build, then
the resources.arsc is generated to identify a single
xxxhdpi resource and the manifest will be updated to
reference resource as app icon.

References golang/go#9985

Change-Id: I9ef59fff45dcd612a41c479b2c679d22c094ab36
Reviewed-on: https://go-review.googlesource.com/30019
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2017-10-17 01:04:57 +00:00
Elias Naur
3ef91fec25 cmd/gomobile, internal/mobileinit: update to the NDK unified headers
From r16, the legacy headers no longer ship with the NDK. Update
the gomobile build system to use the unified headers instead.
They're available from r14.

Based on a patch by Steeve Morin.

Fixes golang/go#21802

Change-Id: I098330962c737edb833e968fe82558e15837f23f
Reviewed-on: https://go-review.googlesource.com/69950
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-10-11 16:08:37 +00:00
Elias Naur
9bd992d065 bind,cmd/gomobile: fix follow ups to doc generator CL (52330)
Also, add tests for blank, anonymous and multiple struct fields.

Change-Id: I15e6fff8d1684f2a31e99e1adf023b92f1f3cb48
Reviewed-on: https://go-review.googlesource.com/59550
Reviewed-by: Alan Donovan <adonovan@google.com>
2017-09-05 18:43:28 +00:00
Elias Naur
05f1abc543 bind,cmd: generate ObjC and Java documentation
Convert Go documentation to JavaDoc tags (/** ... */).

Since the .aar file format doesn't support source files, gomobile
will create a package-sources.jar along with the main package.aar.

For Objective-C, JavaDoc-style comments seems to work as well,
judging by manual inspection of Xcode quick help.

Change-Id: I47fe5b6804681d459a873be37a44610d392166ef
Reviewed-on: https://go-review.googlesource.com/52330
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2017-08-25 16:30:26 +00:00
Elias Naur
dedec14c61 cmd/gomobile: update documentation to reflect Go 1.7 requirement
CL 35953 bumped the minimum required version to Go 1.7. Update the
gomobile documentation to reflect that.

Change-Id: I7cd7937471eb16456a51e8f41bae331344860888
Reviewed-on: https://go-review.googlesource.com/40919
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2017-04-18 12:40:40 +00:00
Elias Naur
57e7952fd5 cmd/gomobile: fix openal init test
Updates golang/go#19046

Change-Id: I0fc8fedc179d24ec9691528cab98857f3f9a4291
Reviewed-on: https://go-review.googlesource.com/37327
Reviewed-by: Jaana Burcu Dogan <jbd@google.com>
2017-03-03 23:32:52 +00:00
Elias Naur
f3e28d5ad0 cmd/gomobile: clean package paths
Clean the package paths so gomobile use the same directory for the
export data (*.a) files as the go tool.

Fixes golang/go#18876.

Change-Id: I40285f9203f04dbb80b21bd74d9b24212b677533
Reviewed-on: https://go-review.googlesource.com/37323
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2017-02-21 20:01:09 +00:00
Elias Naur
44ced21510 bind,cmd/gomobile: require Go 1.7
Bump the minimum required version of Go to 1.7.

This removes version specific code and makes sure users have the
latest mobile related fixes to Go applied. Also, this change is
necessary when runtime.KeepAlive is introduced in a later CL.

Change-Id: I8441a28aef7f645379fbd8f00edabe3c3fb219de
Reviewed-on: https://go-review.googlesource.com/35953
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-30 19:32:33 +00:00
Elias Naur
e7109766ab cmd/gomobile: test for XCode in gomobile init
Previously, gomobile init assumed that the XCode developer tools
were available when running on darwin. That is not always the case,
in particular for Android developers on macOS.

Replace the GOOS check with an explicit check for the xcrun binary.

Change-Id: Ie5ae917288932cc641a17f904ed9822a105367cc
Reviewed-on: https://go-review.googlesource.com/35852
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2017-01-28 13:36:49 +00:00
Elias Naur
c243211167 bind,internal/importers: add Unwrap methods to unwrap Java wrappers
For Java classes implemented in Go, it is useful to take a Java instance
and extract its wrapped Go instance. For example, consider the
java.lang.Runnable implementation wrapping a Go function:

package somepkg

type GoRunnable struct {
    lang.Runnable
    f func()
}

Java methods that take a java.lang.Runnable cannot directly take a
*GoRunnable, so this CL adds a Unwrap method:

import gorun "Java/somepkg/GoRunnable"

...

r := gorun.New()
r.Unwrap().(*GoRunnable).f = func() { ... }
javapkg.Run(r)

The extra interface conversion is unfortunately needed to avoid
import cycles.

Change-Id: Ib775a5712cd25aa75a19d364a55d76b1e11dce77
Reviewed-on: https://go-review.googlesource.com/35295
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-18 20:31:42 +00:00
Elias Naur
226c1c8284 cmd/gomobile: avoid header guard clash in iOS headers
Fix manually verified; none of our tests or the hello example fails
without this fix.

While we're here, update the hello iOS example to actually include the
Hello.framework and to use module @import syntax.

Fixes golang/go#18693

Change-Id: Id2edf80e2ed9ed8060ec825369a64f276a3b3c1d
Reviewed-on: https://go-review.googlesource.com/35330
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-18 01:06:16 +00:00
Elias Naur
3212b34dba cmd/gomobile: replace stripped NDK with external NDK
Gomobile has up until now used stripped NDKs hosted by Google. This
arrangement adds maintenance overhead and blocks the use of custom
NDKs or custom API levels. Also, as noted in issue 16211, the stripped
NDK is no longer tiny because Gomobile supports more platforms.

This CL removed the code for generating and packaging stripped NDKs and
adds support for using external NDKs to the gomobile tool.

gomobile init will now use the NDK installed by the Android SDK manager,
if present, or a user specified NDK if the -ndk flag is given. If no
NDK was found or specified, Android initialization is skipped. gomobile
will instruct the user to run init with a valid NDK if bind or build is
invoked without Android initialization.

gomobile init will also attempt to build OpenAL for Android if the -openal
flag specifies a source directory. It needs cmake and, on Windows, nmake
installed. If gomobile build is run on an app that requires
golang.org/x/mobile/exp/audio/al and OpenAL wasn't built by init, the user
is instructed to do so.

Tested on Linux, macOS, Windows.

Fixes golang/go#16211
Fixes golang/go#18522

Change-Id: Ia38f6e43e671a207dad562678c65225b426e7e3e
Reviewed-on: https://go-review.googlesource.com/35173
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-17 21:04:41 +00:00
Elias Naur
9ec2d17db2 cmd: fix handling of (multiple) tags
The gomobile tool mishandled build tags in two ways, first by
ignoring tags for iOS, second by passing multiple tags along to
the go tool incorrectly. This CL fixes both.

Fixes golang/go#18523
Fixes golang/go#18515

Change-Id: I28a49c1e23670adb085617d9f5fb5cd5e22a4b65
Reviewed-on: https://go-review.googlesource.com/34955
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-12 22:00:16 +00:00
Elias Naur
82c03f1188 cmd/gomobile: document the GOMOBILEFLAGS, GOARCH, GOBIND plugin settings
Change-Id: I681ac02869e137f67880416743352951960f7d8a
Reviewed-on: https://go-review.googlesource.com/33950
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-12 21:57:09 +00:00
Elias Naur
6f0c9f6df9 bind: generate wrappers for generated ObjC types
This is the Objective-C equivalent of CL 34776, generating reverse
wrappers for generated ObjC types. The implementation follows the same
strategy as the Java implementation: use the Go ast package to find
exported structs with embedded Objective-C types and synthesize their
types as if they were imported through clang.

In turn, the handling of the implicit "self" parameter changes in the
same way as well: the type of self parameters must be the wrapped type
for the generated type. For example:

func (d *GoNSDate) Description(self Foundation.NSDate) string

becomes

import gopkg "ObjC/Objcpkg"

func (d *GoNSDate) Description(self gopkg.GoNSDate) string

Change-Id: I26f838b06a622864be463f81dbb4dcae76f70f20
Reviewed-on: https://go-review.googlesource.com/34780
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-11 20:07:46 +00:00
Elias Naur
c90c4f7c8a bind,internal: change the default Java package to the empty string
The Objective-C bindings was recently changed to support the empty
name prefix and to use that as the default. This CLs changed the Java
generators in the same way, supporting the empty Java package and using
it as the default.

Change-Id: I857affce686c67638a2b6c4e1da5d6a88d7ba560
Reviewed-on: https://go-review.googlesource.com/34778
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-11 19:15:09 +00:00
Elias Naur
ff6f6e8d8e bind,cmd,internal: generate reverse bindings for exported Go structs
Before this CL, the type of the implicit "this" parameter to Java methods
implemented in Go could only be a super class of the generated Java
class. For example, the following GoRunnable type is an implementation of
the Java interface java.lang.Runnable with a toString method:

package somepkg

import "Java/java/lang"

type GoRunnable struct {
    lang.Runnable
}

func (r *GoRunnable) ToString(this lang.Runnable) string {
    ...
}

The "this" parameter is implicit in the sense that the reverse generator
automatically fills it with a reference to the Java instance of
GoRunnable.

Note that "this" has the type Java/java/lang.Runnable, not
Java/go/somepkg.GoRunnable, which renders it impossible to call Java
methods and functions that expect GoRunnable. The most practical example
of this is the Android databinding libraries.

This CL changes the implicit this parameter to always match the exact
type. In the example, the toString implementation becomes:

import gopkg "Java/go/somepkg"

func (r *GoRunnable) ToString(this gopkg.GoRunnable) string {
    ...
}

One strategy would be to simply treat the generated Java classes
(GoRunnable in our example) as any other Java class and import it
through javap. However, since the Java classes are generated after
importing, this present a chicken-and-egg problem.

Instead, use the newly added support for structs with embedded prefixed types
and synthesize class descriptors for every exported Go struct type.

Change-Id: Ic5ce4a151312bd89f91798ed4088c9959225b448
Reviewed-on: https://go-review.googlesource.com/34776
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2017-01-11 19:06:53 +00:00
Elias Naur
6a96d4c7cf bind: make the default name prefix empty on ObjC
Since generated names now have their package names prefixed, the
extra prefix, "Go", is both confusing and counter-productive to
making the generated ObjC code look like any other native code.

Change the default to the empty prefix, while preserving support
for an explicit prefix if needed.

This is a backwards incompatible change; to keep the old behaviour,
specify "-prefix Go" to the gobind or gomobile command.

While we're here, fix the Ivy example for the recent change in
error returns.

Change-Id: I7fef4a92a18ddadee972ccf359652e3b31624f33
Reviewed-on: https://go-review.googlesource.com/34643
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-12-24 13:37:27 +00:00
Elias Naur
60feeb77f4 bind,cmd: support the empty ObjC prefix
Since the Go package name is already prefixed to generated ObjC
names, the empty extra prefix is useful. Support that by not reverting
to the default extra prefix, "Go", if -prefix "" is specified.

To avoid file name clashes with the Go header files, add ".objc" to
the ObjC-facing header names.

Change-Id: I559fe60d7474521617f23894af247c6019ff2a21
Reviewed-on: https://go-review.googlesource.com/33954
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-12-23 09:44:24 +00:00
Elias Naur
b8794a2669 cmd: update documentation and add pure Go Android app example
Update outdated documentation and add documentation and references
for the the new reverse binding support.

Add a new example, reverse, that demonstrates how to use Android
API directly from Go and thereby implement an Android app in pure
Go.

Change-Id: Iac054dbc015d00a37c0cc234931f9bd90172848e
Reviewed-on: https://go-review.googlesource.com/31170
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-11-03 14:40:43 +00:00
Elias Naur
1c49d29d1c bind,cmd: accept ObjC wrapper types in bound packages
Accept ObjC API wrapper types as arguments and return values from
bound Go package functions and methods. Also, allow Go structs
to extend ObjC classes and implement ObjC protocols as well as override
and implement methods.

This is the third and final part of the implementation of the golang/go#17102
proposal.

Fixes golang/go#17102

Change-Id: I601d90fb6d22b8d6f8b7d5fe0130daa1a4dd4734
Reviewed-on: https://go-review.googlesource.com/29175
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-17 10:37:16 +00:00
Alex Brainman
eb6d6dca20 cmd/gomobile: use correct version of clang on windows/386
Fixes golang/go#16823
Fixes golang/go#17376

Change-Id: Ia9c15242cce66eca1d36a5e1dc6106b3549c251d
Reviewed-on: https://go-review.googlesource.com/31110
Reviewed-by: Elias Naur <elias.naur@gmail.com>
2016-10-17 00:13:54 +00:00
Elias Naur
6ecf8eedb8 bind,cmd: add generator for ObjC API wrappers
Using the new ObjC type analyzer API, scan the bound packages for
references to ObjC classes and protocols and generate Go wrappers for them.

This is the second part of the implementation of proposal golang/go#17102.

For golang/go#17102

Change-Id: I773db7b0362a7ff526d0a0fd6da5b2fa33301144
Reviewed-on: https://go-review.googlesource.com/29174
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-16 10:25:40 +00:00
Elias Naur
a82bb3c8ba cmd/gobind,bind: generate complete Java interface with gobind
Output every Java class, including the support classes, from gobind
-lang=java. In addition, replace Go package export data parsing with
converting from go/ast to go/types. That way, gobind can tolerate
unknown imports as long as the exported Go API doesn't use them.

In a follow-up CL, the gobind gradle plugin will use gobind for a first
pass to expose the generated Java classes to the android plugin.

Change-Id: I8134899ec818c7fee79e4d9df8afcae9dd679add
Reviewed-on: https://go-review.googlesource.com/30093
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-14 13:14:45 +00:00
Elias Naur
e04a76eb64 cmd/gomobile,internal: add bootclasspath and classpath flags to gomobile
Add -bootclasspath and -classpath flags to the gomobile tool. In a
follow-up CL, the gobind gradle plugin will use them to support R and
databinding classes from Go.

Change-Id: Id33acf0c3fe1ec3908740b2a736ed241fa6391c2
Reviewed-on: https://go-review.googlesource.com/30092
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-09-30 20:31:20 +00:00
Elias Naur
bdf873ed8f bind,cmd: accept Java API in bound packages
Accept Java API interface types as arguments and return values from
bound Go package functions and methods. Also, allow Go structs
to extend Java classes and implement Java interfaces as well as override
and implement methods.

This is the third and final part of the implementation of the golang/go#16876
proposal.

Fixes golang/go#16876

Change-Id: I6951dd87235553ce09abe5117a39a503466163c0
Reviewed-on: https://go-review.googlesource.com/28597
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-22 10:16:33 +00:00
Elias Naur
bf31dd1a5e bind,cmd/gomobile: add a new generator for Java API wrappers
Using the new Java class analyzer API, scan the bound packages
for references to Java classes and interfaces and generate Go
wrappers for them.

This is the second part of the implementation of proposal golang/go#16876.

For golang/go#16876

Change-Id: I59ec0ebdae0081a615dc34d450f344c20c03f871
Reviewed-on: https://go-review.googlesource.com/28596
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-16 17:25:25 +00:00
Elias Naur
f52baf9a56 mobile/cmd/gomobile: fix test
Change-Id: I4c790d2156e6b167244ce3e4f5a37c1253e6e152
Reviewed-on: https://go-review.googlesource.com/28590
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-09-07 12:53:10 +00:00
Elias Naur
80e11ad074 mobile/bind: move generated Java classes to package level
Before this CL, generated Java classes or interfaces were inner
classes to the top package class. That is both unnecessary and creates
ugly class names. Instead, move every generated class and interface to its
own package level class.

NOTE: This is a backwards incompatible change and requires every client
of gomobile APIs to be updated to leave out the package class in the
type names. For example, the Go type

package pkg

type S struct {
}

now generates (with the default java package name go) a Java class named
go.pkg.S. The name before this CL was go.pkg.Pkg.S.

Also, change the custom java package to specify the package prefix and
not the full package as before. This is an unfortunate change needed
to avoid name clashes between two bound packages. On the plus side,
the change brings the custom package case closer to the default behaviour,
which is a commen prefix, "go.", and a distinct java package for every
Go package bound.

Change-Id: Iadfaad56e101d1caf7e2a05006f4d384859a20fe
Reviewed-on: https://go-review.googlesource.com/27436
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-08-22 07:41:35 +00:00
Elias Naur
0ba4e6463d mobile/cmd/gomobile: remove explicit -p argument to the go cmd
Now that darwin/arm no longer use an explicit -p=1 in the go command
remove the explicit -p=<num cpus> from gomobile as well.

While we're here, fix the init test templates to reflect the new
clang based build.

Fixes golang/go#10477

Change-Id: I29a179e628466ae0c591620f485194b80e310811
Reviewed-on: https://go-review.googlesource.com/21186
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-08-16 10:53:25 +00:00
Elias Naur
efd7eed289 mobile/cmd/gomobile: upgrade to NDK r12b and add nm
gomobile build uses the nm tool which was missing from the NDK r12
upgrade. I missed it because gomobile bind works without it.

Make release.go include nm and upgrade to NDK r12b to make avoid
name clashes with the already released, but inadequate, NDK r12
files.

Finally, update the cmd/gomobile tests to match the new clang
reality.

Fixes golang/go#16268

Change-Id: Ic0cbf75785baace1fe6e88c8dc72d83ce2e13b35
Reviewed-on: https://go-review.googlesource.com/24724
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-07-11 14:34:23 +00:00
Hana Kim
f229b06003 cmd/gomobile: update doc and specify the min android API level
Change-Id: Ia065722ba3f6c793d19ecd05953f840beb0bdafb
Reviewed-on: https://go-review.googlesource.com/24791
Reviewed-by: Elias Naur <elias.naur@gmail.com>
2016-07-07 16:20:36 +00:00
Elias Naur
8d3035464e mobile/cmd/gomobile: fix gomobile init on Windows
My previous CL, 24490, broke gomobile init for Windows users because
it failed to take the Windows ".exe" postfix into account everywhere.
Fix it by copying the entire "bin" directory from the llvm toolchain
instead of picking out certain named binaries.

Also, symlink (or, in Windows, copy) the clang lib64 directory into
each target platform where clang expects it.

Fixes golang/go#16233

Change-Id: I8d966ca76bd22403ac2eacef3da7aae59e698059
Reviewed-on: https://go-review.googlesource.com/24720
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
2016-07-07 08:58:53 +00:00
Elias Naur
34d472ecb6 mobile/cmd/gomobile: use NDK r12
Also:

- Replace GCC with Clang. GCC is slated for removal in future NDK
releases.
- Replace the deprecated obsoleted make-standalone-toolchain.sh
script with the new make_standalone_toolchain.py script.
- Add the NDK version to OpenAL tarball name, to avoid name clashes
with previous builds of the same OpenAL version.
- Removed obsolete workaround for a linker problem with NDK r10c.
- Update the URLs and unpack logic for the full NDK mode.

Change-Id: Ifeec6fee624862ba2ff2d4520dab42f800414f7b
Reviewed-on: https://go-review.googlesource.com/24490
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-06-29 15:33:04 +00:00
Elias Naur
a3e0621280 mobile/bind: use objects to pass errors across the language barrier
Gobind uses strings for passing errors across the language barrier.
However, since Gobind doesn't have a concept of a nil string, it
can't separate an empty native string from a nil string.

In turn, that means that empty errors, exceptions or NSError * with
an empty description are treated as no error. With ObjC, empty errors
are replaced with a default string to workaround the issue, while
with Java empty errors are silently ignored.

Fix this by replacing strings with actual error objects, wrapping
the Go error, Java Throwable or ObjC NSError *, and letting the
existing bind machinery take care of passing the references across.

It's a large change for a small corner case, but I believe objects
are a better fit for exception that strings. Error objects also
naturally leads to future additions, for example accessing the
exception class name or chained exception.

Change-Id: Ie03b47cafcb231ad1e12a80195693fa7459c6265
Reviewed-on: https://go-review.googlesource.com/24100
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-06-23 18:55:48 +00:00
Hana Kim
6837d85185 cmd/gomobile: introduce the 'clean' command
The command deletes all files under $GOPATH/pkg/gomobile dir
that keeps downloaded files and precompiled objects during the
last gomobile init run.

'gomobile clean' will be suggested in case of gomobile init
failures due to downloaded file hash mismatch.

For golang/go#15973

Change-Id: Ie9d3cfa7aef9d68931fd68f7b58d1a18c9d4b3b8
Reviewed-on: https://go-review.googlesource.com/24074
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-06-14 16:05:07 +00:00
Hana Kim
1decf4c941 cmd/gomobile: mention how to specify target arch for bind
Change-Id: I7c2dd984e810165dc126ae1f65d72d8bba804e04
Reviewed-on: https://go-review.googlesource.com/24072
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-06-14 15:08:02 +00:00
Elias Naur
d6153aa12b mobile/cmd/gomobile: upgrade to ndk-r11c
Update gcc version to 4.9 everywhere. NDK r11 stopped support
for gcc 4.8.

Switch from bin/exe format to zip format.

Drop support for linux/x86, since r11c no longer supports it.

Change the NDK URLs from http://dl.google.com/android/ndk/ to
https://dl.google.com/android/repository/.

Add a flag, -ndkdir, to specify where the downloaded NDK files for
processing are found and downloaded.

Check the status code from the http.Get that fetches the NDK files.

Change-Id: I836de6611bd04f5220e01937a3288a91604b8999
Reviewed-on: https://go-review.googlesource.com/23592
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-06-06 18:19:59 +00:00
Jaana Burcu Dogan
6b7a416f79 cmd/gomobile: be consistent about how the target flag is spelled
Change-Id: Ic9b66152c4cdc18e843a41818ac3319157ce11ca
Reviewed-on: https://go-review.googlesource.com/23305
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-05-25 21:53:16 +00:00
Jaana Burcu Dogan
7c31375cc4 cmd/gomobile: find a better name for the app if import path is "."
Fixes golang/go#15779.

Change-Id: I762e5ce12b8b76da80af73ddae26dbd46241f134
Reviewed-on: https://go-review.googlesource.com/23307
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-05-25 21:29:40 +00:00
Hyang-Ah (Hana) Kim
2922272407 cmd/gomobile: error when attempting to bind main package
Fixes golang/go#15515

Change-Id: Idc831d4691f6c983d37622bb30c238015542cfdf
Reviewed-on: https://go-review.googlesource.com/22802
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-05-05 18:37:30 +00:00
Elias Naur
5b96314b59 mobile/bind: implement interfaces from imported bound packages
Java classes must explicitly declare implemented interfaces. Bind
already declares all such interfaces within each package. Expand
the set of interfaces to include all bound packages.

In addition, let Java interfaces extend all possible interfaces in
the same way as Java classes. To avoid circular references, only
let interfaces extend compatible interfaces with fewer methods.

Before, each package was imported in its own importer, breaking the
assumption of types.AssignableTo that identical packages have
identical *types.Package. Fix that by using one importer for all
bound packages, replacing package path equality checks with direct
equality checks.

While we're here, add missing arguments to a few error messages.

Change-Id: I5eb58972a3abe918862ca99d5a203809699a3433
Reviewed-on: https://go-review.googlesource.com/20987
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-03-29 08:36:18 +00:00
Elias Naur
5496692b9e mobile/cmd/gomobile: fix tests
Change-Id: I99514f73a0c9783e01921e1ba9f2aa79d44c65f7
Reviewed-on: https://go-review.googlesource.com/21134
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-03-25 14:33:59 +00:00
Elias Naur
45290c0217 mobile/cmd/gomobile: pass minimum iphoneos version to linker
A minimum version is already specified for building for the
simulator (darwin/amd64). Pass the same version when building for
darwin/arm{,64}.

Fixes golang/go#13153

Change-Id: Id16c247b86877a07ee39013454868fccfd63b112
Reviewed-on: https://go-review.googlesource.com/21105
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-03-25 00:59:32 +00:00
Hyang-Ah Hana Kim
65e8f02f00 cmd/gomobile: update doc to mention android/arm64
Change-Id: I7c0a8df3fcdd2a16d4acb096264ef6f19c5f8482
Reviewed-on: https://go-review.googlesource.com/20715
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-03-15 16:42:19 +00:00
Hyang-Ah Hana Kim
74ee969d3f cmd/gomobile: add support for android/arm64
forked from https://golang.org/cl/20434

- added app/internal/callfn package update.

- changed hashes.go because -for some reason- the generated hashes don't match.

- build_androidapp.go had to be changed to deal with openal package.

Fixes golang/go#10743

Change-Id: Iaa3f55d80c5fd184338d27832dc5c90cb772bd6a
Reviewed-on: https://go-review.googlesource.com/20707
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Elias Naur <elias.naur@gmail.com>
2016-03-14 23:00:38 +00:00
Elias Naur
7df33f4a5c mobile/bind: allow bound packages to refer to imported bound packages
Multiple packages are already supported, but only as if each packages
were bound in isolation. This CL lets a bound package refer to other
bound packages in its exported functions, types and fields.

In Java, the JNI class jclass and constructor jmethodID are exported
so other packages can construct proxies of other packages' interfaces.

In ObjC, the class @interface declarations are moved from the package
.m file to its .h file to allow other packages to constructs its
interface proxies.

Add a supporting test package, secondpkg, and add Java and ObjC tests
for the new cross package functionality. Also add simplepkg for
testing corner cases where the generated Go file must not include its
bound package.

While we're here, stop generating Go proxy types for struct types;
only Go interfaces can be implemented in the foreign language.

Change-Id: Icbfa739c893703867d38a9100ed0928fbd7a660d
Reviewed-on: https://go-review.googlesource.com/20575
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-03-12 06:23:01 +00:00
Daniel Skinner
4e994ac070 internal/binres: use pkg binres for manifest encode
Current output byte-for-byte of pkg binres is close,
but not exact, to output of aapt.
The current exceptions to this are as follows:
 * sort order of certain attributes
 * typed value of minSdkVersion
These differences do not appear to affect the encoded
manifest from working correctly. Further details on
the byte differences can be seen in TestEncode.

Fixes golang/go#13109

Change-Id: Ibfb7731143f0e2baeeb7dd5b04aa649566606a53
Reviewed-on: https://go-review.googlesource.com/20030
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-03-05 06:30:01 +00:00
Elias Naur
6fca37c69e mobile/bind: replace seq serialization with direct calls
The seq serialization machinery is a historic artifact from when Go
mobile code had to run in a separate process. Now that Go code is running
in-process, replace the explicit serialization with direct calls and pass
arguments on the stack.

The benefits are a much smaller bind runtime, much less garbage (and, in
Java, fewer objects with finalizers), less argument copying, and faster
cross-language calls.
The cost is a more complex generator, because some of the work from the
bind runtime is moved to generated code. Generated code now handles
conversion between Go and Java/ObjC types, multiple return values and memory
management of byte slice and string arguments.

To overcome the lack of calling C code between Go packages, all bound
packages now end up in the same (fake) package, "gomobile_bind", instead of
separate packages (go_<pkgname>). To avoid name clashes, the package name is
added as a prefix to generated functions and types.

Also, don't copy byte arrays passed to Go, saving call time and
allowing read([]byte)-style interfaces to foreign callers (#12113).

Finally, add support for nil interfaces and struct pointers to objc.

This is a large CL, but most of the changes stem from changing testdata.

The full benchcmp output on the CL/20095 benchmarks on my Nexus 5 is
reproduced below. Note that the savings for the JavaSlice* benchmarks are
skewed because byte slices are no longer copied before passing them to Go.

benchmark                                 old ns/op     new ns/op     delta
BenchmarkJavaEmpty                        26.0          19.0          -26.92%
BenchmarkJavaEmptyDirect                  23.0          22.0          -4.35%
BenchmarkJavaNoargs                       7685          2339          -69.56%
BenchmarkJavaNoargsDirect                 17405         8041          -53.80%
BenchmarkJavaOnearg                       26887         2366          -91.20%
BenchmarkJavaOneargDirect                 34266         7910          -76.92%
BenchmarkJavaOneret                       38325         2245          -94.14%
BenchmarkJavaOneretDirect                 46265         7708          -83.34%
BenchmarkJavaManyargs                     41720         2535          -93.92%
BenchmarkJavaManyargsDirect               51026         8373          -83.59%
BenchmarkJavaRefjava                      38139         21260         -44.26%
BenchmarkJavaRefjavaDirect                42706         28150         -34.08%
BenchmarkJavaRefgo                        34403         6843          -80.11%
BenchmarkJavaRefgoDirect                  40193         16582         -58.74%
BenchmarkJavaStringShort                  32366         9323          -71.20%
BenchmarkJavaStringShortDirect            41973         19118         -54.45%
BenchmarkJavaStringLong                   127879        94420         -26.16%
BenchmarkJavaStringLongDirect             133776        114760        -14.21%
BenchmarkJavaStringShortUnicode           32562         9221          -71.68%
BenchmarkJavaStringShortUnicodeDirect     41464         19094         -53.95%
BenchmarkJavaStringLongUnicode            131015        89401         -31.76%
BenchmarkJavaStringLongUnicodeDirect      134130        90786         -32.31%
BenchmarkJavaSliceShort                   42462         7538          -82.25%
BenchmarkJavaSliceShortDirect             52940         17017         -67.86%
BenchmarkJavaSliceLong                    138391        8466          -93.88%
BenchmarkJavaSliceLongDirect              205804        15666         -92.39%
BenchmarkGoEmpty                          3.00          3.00          +0.00%
BenchmarkGoEmptyDirect                    3.00          3.00          +0.00%
BenchmarkGoNoarg                          40342         13716         -66.00%
BenchmarkGoNoargDirect                    46691         13569         -70.94%
BenchmarkGoOnearg                         43529         13757         -68.40%
BenchmarkGoOneargDirect                   44867         14078         -68.62%
BenchmarkGoOneret                         45456         13559         -70.17%
BenchmarkGoOneretDirect                   44694         13442         -69.92%
BenchmarkGoRefjava                        55111         28071         -49.06%
BenchmarkGoRefjavaDirect                  60883         26872         -55.86%
BenchmarkGoRefgo                          57038         29223         -48.77%
BenchmarkGoRefgoDirect                    56153         27812         -50.47%
BenchmarkGoManyargs                       67967         17398         -74.40%
BenchmarkGoManyargsDirect                 60617         16998         -71.96%
BenchmarkGoStringShort                    57538         22600         -60.72%
BenchmarkGoStringShortDirect              52627         22704         -56.86%
BenchmarkGoStringLong                     128485        52530         -59.12%
BenchmarkGoStringLongDirect               138377        52079         -62.36%
BenchmarkGoStringShortUnicode             57062         22994         -59.70%
BenchmarkGoStringShortUnicodeDirect       62563         22938         -63.34%
BenchmarkGoStringLongUnicode              139913        55553         -60.29%
BenchmarkGoStringLongUnicodeDirect        150863        57791         -61.69%
BenchmarkGoSliceShort                     59279         20215         -65.90%
BenchmarkGoSliceShortDirect               60160         21136         -64.87%
BenchmarkGoSliceLong                      411225        301870        -26.59%
BenchmarkGoSliceLongDirect                399029        298915        -25.09%

Fixes golang/go#12619
Fixes golang/go#12113
Fixes golang/go#13033

Change-Id: I2b45e9e98a1248e3c23a5137f775f7364908bec7
Reviewed-on: https://go-review.googlesource.com/19821
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-03-03 15:03:45 +00:00
Hyang-Ah (Hana) Kim
52e0785361 cmd/gomobile: enable android/386, android/amd64 support
Change-Id: I044c6f773cb91b75b00171db688c6b4fbe8ec86e
Reviewed-on: https://go-review.googlesource.com/19600
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-02-19 04:52:18 +00:00