Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also provide binaries for Android ARM #1578

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion Makefile
Expand Up @@ -113,6 +113,7 @@ platform-all: cmd/esbuild/version.go test-all
platform-windows-32 \
platform-windows-arm64 \
platform-android-arm64 \
platform-android-arm \
platform-darwin \
platform-darwin-arm64 \
platform-freebsd \
Expand Down Expand Up @@ -150,6 +151,9 @@ platform-unixlike:
platform-android-arm64:
make GOOS=android GOARCH=arm64 NPMDIR=npm/esbuild-android-arm64 platform-unixlike

platform-android-arm:
make GOOS=android GOARCH=arm NPMDIR=npm/esbuild-android-arm platform-unixlike
Copy link
Owner

@evanw evanw Sep 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unable to run this on my computer. I get this:

$ make GOOS=android GOARCH=arm NPMDIR=npm/esbuild-android-arm platform-unixlike
test -n "android" && test -n "arm" && test -n "npm/esbuild-android-arm"
mkdir -p "npm/esbuild-android-arm/bin"
cd "npm/esbuild-android-arm" && npm version "0.12.25" --allow-same-version
v0.12.25
CGO_ENABLED=0 GOOS="android" GOARCH="arm" go build "-ldflags=-s -w" -trimpath -o "npm/esbuild-android-arm/bin/esbuild" ./cmd/esbuild
# github.com/evanw/esbuild/cmd/esbuild
loadinternal: cannot find runtime/cgo
/usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: warning: option -s is obsolete and being ignored
ld: unknown option: -z
clang: error: linker command failed with exit code 1 (use -v to see invocation)

make: *** [platform-unixlike] Error 2

This is on macOS 11.5.1. I don't understand why cgo is apparently enabled despite CGO_ENABLED=0. Here is a reduced reproduction:

$ cat main.go 
package main

import "runtime/debug"

func main() {
	debug.SetGCPercent(-1)
}

$ CGO_ENABLED=0 GOOS="android" GOARCH="arm" go build main.go
# command-line-arguments
loadinternal: cannot find runtime/cgo
/usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: unknown option: -z
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This appears to be a bug in Go.

Edit: I have filed this bug as golang/go#48246.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try compiling with older Golang versions?

Don't know why but I feel it's somehow related to wrong dynamic linker path when cross compiling issue (not mentioning the issue here since it may be unrelated)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Go team said that "internal linking" is unsupported with Android ARM and building this requires a C toolchain to build. Maybe this means I need to build this on a 32-bit Android ARM device?

Are you able to build esbuild using this command? If so, what OS version, CPU architecture, and Go version are you on?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to build on Android ARM 7.0 using on Termux using

go build ./cmd/esbuild

The Golang version I had was the latest in official Termux repository as of writing this comment.

go version output

go version go1.16.7 android/arm

and I have a esbuild binary.

And about cross compiling, you need to get the C compiler from Android SDK.

If you need some example on how to do it see termux/termux-packages

Under scripts/build/termux_step_setup_toolchain.sh, you can see how it's setting up CC, CXX and other environment variables (along with some other changes which might not be needed here)


platform-darwin:
make GOOS=darwin GOARCH=amd64 NPMDIR=npm/esbuild-darwin-64 platform-unixlike

Expand Down Expand Up @@ -239,7 +243,8 @@ publish-all: cmd/esbuild/version.go test-prepublish
@read OTP && OTP="$$OTP" make -j2 \
publish-neutral \
publish-deno \
publish-wasm
publish-wasm \
publish-android-arm

git commit -am "publish $(ESBUILD_VERSION) to npm"
git tag "v$(ESBUILD_VERSION)"
Expand All @@ -257,6 +262,9 @@ publish-windows-arm64: platform-windows-arm64
publish-android-arm64: platform-android-arm64
test -n "$(OTP)" && cd npm/esbuild-android-arm64 && npm publish --otp="$(OTP)"

publish-android-arm: platform-android-arm
test -n "$(OTP)" && cd npm/esbuild-android-arm && npm publish --otp="$(OTP)"

publish-darwin: platform-darwin
test -n "$(OTP)" && cd npm/esbuild-darwin-64 && npm publish --otp="$(OTP)"

Expand Down Expand Up @@ -313,6 +321,7 @@ clean:
rm -f npm/esbuild-windows-64/esbuild.exe
rm -f npm/esbuild-windows-arm64/esbuild.exe
rm -rf npm/esbuild-android-arm64/bin
rm -rf npm/esbuild-freebsd-arm/bin
rm -rf npm/esbuild-darwin-64/bin
rm -rf npm/esbuild-darwin-arm64/bin
rm -rf npm/esbuild-freebsd-64/bin
Expand Down
1 change: 1 addition & 0 deletions lib/npm/install.ts
Expand Up @@ -282,6 +282,7 @@ const knownWindowsPackages: Record<string, string> = {
};
const knownUnixlikePackages: Record<string, string> = {
'android arm64 LE': 'esbuild-android-arm64',
'android arm LE': 'esbuild-android-arm',
'darwin arm64 LE': 'esbuild-darwin-arm64',
'darwin x64 LE': 'esbuild-darwin-64',
'freebsd arm64 LE': 'esbuild-freebsd-arm64',
Expand Down
3 changes: 3 additions & 0 deletions npm/esbuild-android-arm/README.md
@@ -0,0 +1,3 @@
# esbuild

This is the Android ARM binary for esbuild, a JavaScript bundler and minifier. See https://github.com/evanw/esbuild for details.
16 changes: 16 additions & 0 deletions npm/esbuild-android-arm/package.json
@@ -0,0 +1,16 @@
{
"name": "esbuild-android-arm",
"version": "0.12.25",
"description": "The Android ARM binary for esbuild, a JavaScript bundler.",
"repository": "https://github.com/evanw/esbuild",
"license": "MIT",
"os": [
"android"
],
"cpu": [
"arm"
],
"directories": {
"bin": "bin"
}
}