cmd/gomobile: invoke the NDK Clang directly

envInit pointed CC and CXX at the NDK's <triple><API>-clang wrapper
scripts. On Windows os/exec resolves the extension-less path through
PATHEXT to the .cmd form of the wrapper, which runs under cmd.exe,
whose command line limit is 8191 characters. The link step of an
Android c-shared build already produces a command line of roughly
8.2 KB, so it fails with "The command line is too long." cmd/link
switches to a response file only above 30 KB, well past the point
where cmd.exe gives up, so that fallback never engages.

Point CC and CXX at the clang and clang++ binaries in the NDK's bin
directory instead, appending the --target= that the wrapper would have
supplied. Naming the binary means CreateProcess runs it directly rather
than through cmd.exe, which raises the ceiling to 32767 characters.
Google documents clang --target= as the preferred way to invoke the
toolchain and offers the wrapper scripts only as a fallback.

The wrappers for 32-bit x86 below API level 24 pass -mstackrealign as
well, and that is reproduced. Their -cc1 special case is not: it keeps
the wrapper from adding a driver option to a frontend invocation, which
cannot arise once the binary is named directly. Wrappers in older NDKs
also passed -fno-addrsig for the benefit of GNU binutils; the NDK no
longer does.

The Windows-only clang++.cmd stat was a proxy for telling NDK r19b from
r19c apart. The .cmd wrappers are still shipped, but gomobile no longer
runs them, so the toolchain check now covers exactly the two binaries
that are executed.

Updates golang/go#80862

Change-Id: I5f93d7440f1e9018ea64d6220babbd96b9d3c7b0
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/814500
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
3 files changed
tree: 70ba12d296c9b9d71b6ed376d246948ea28deb54
  1. app/
  2. asset/
  3. bind/
  4. cmd/
  5. doc/
  6. event/
  7. example/
  8. exp/
  9. geom/
  10. gl/
  11. internal/
  12. testdata/
  13. .gitattributes
  14. .gitignore
  15. codereview.cfg
  16. CONTRIBUTING.md
  17. go.mod
  18. go.sum
  19. LICENSE
  20. PATENTS
  21. README.md
README.md

Go support for Mobile devices

Go Reference

The Go mobile repository holds packages and build tools for using Go on mobile platforms.

Package documentation as a starting point:

Caution image

The Go Mobile project is experimental. Use this at your own risk. While we are working hard to improve it, neither Google nor the Go team can provide end-user support.

This is early work and installing the build system requires Go 1.5. Follow the instructions on golang.org/wiki/Mobile to install the gomobile command, build the basic and the bind example apps.


Contributions to Go are appreciated. See https://go.dev/doc/contribute.

The git repository is https://go.googlesource.com/mobile.