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

Fails to fallback to js/wasm on Android x64 and no binary available #2068

Closed
FossPrime opened this issue Feb 28, 2022 · 7 comments
Closed

Fails to fallback to js/wasm on Android x64 and no binary available #2068

FossPrime opened this issue Feb 28, 2022 · 7 comments

Comments

@FossPrime
Copy link

Describe the bug

The issue is esbuild has a binary and supports Android, but it does not make a build for Intel based Android, so it both requires the binary code and can't provide it.

    "optionalDependencies": {
        "esbuild-android-arm64": "0.14.23",
        "esbuild-darwin-64": "0.14.23",
        "esbuild-darwin-arm64": "0.14.23",
        "esbuild-freebsd-64": "0.14.23",
        "esbuild-freebsd-arm64": "0.14.23",
        "esbuild-linux-32": "0.14.23",
        "esbuild-linux-64": "0.14.23",
        "esbuild-linux-arm": "0.14.23",
        "esbuild-linux-arm64": "0.14.23",
        "esbuild-linux-mips64le": "0.14.23",
        "esbuild-linux-ppc64le": "0.14.23",
        "esbuild-linux-riscv64": "0.14.23",
        "esbuild-linux-s390x": "0.14.23",
        "esbuild-netbsd-64": "0.14.23",
        "esbuild-openbsd-64": "0.14.23",
        "esbuild-sunos-64": "0.14.23",
        "esbuild-windows-32": "0.14.23",
        "esbuild-windows-64": "0.14.23",
        "esbuild-windows-arm64": "0.14.23"
      }

System Info

HP Chromebook 14c

$ npx envinfo --system --npmPackages '{vite,@vitejs/*}' --binaries --browsers
  System:
    OS: android
    CPU: Unknown
    Memory: 293.26 MB / 6.44 GB
  Binaries:
    Node: 16.13.2 - /data/data/com.termux/files/usr/bin/node
    npm: 8.1.2 - /data/data/com.termux/files/usr/bin/npm
  npmPackages:
    vite: ^2.7.13 => 2.7.13

Logs

Error in Vite which depends on esbuild:

npx vite build
failed to load config from /data/data/com.termux/files/home/my-app/vite.config.ts
error during build:
Error: Unsupported platform: android x64 LE
    at pkgAndSubpathForCurrentPlatform (/data/data/com.termux/files/home/my-app/node_modules/esbuild/lib/main.js:1621:11)
    at generateBinPath (/data/data/com.termux/files/home/my-app/node_modules/esbuild/lib/main.js:1633:28)
    at esbuildCommandAndArgs (/data/data/com.termux/files/home/my-app/node_modules/esbuild/lib/main.js:1699:11)
    at ensureServiceIsRunning (/data/data/com.termux/files/home/my-app/node_modules/esbuild/lib/main.js:1856:25)
    at Object.build (/data/data/com.termux/files/home/my-app/node_modules/esbuild/lib/main.js:1749:26)
    at bundleConfigFile (/data/data/com.termux/files/home/my-app/node_modules/vite/dist/node/chunks/dep-f5552faa.js:75118:34)
    at loadConfigFromFile (/data/data/com.termux/files/home/my-app/node_modules/vite/dist/node/chunks/dep-f5552faa.js:75095:35)
    at resolveConfig (/data/data/com.termux/files/home/my-app/node_modules/vite/dist/node/chunks/dep-f5552faa.js:74656:34)
    at doBuild (/data/data/com.termux/files/home/my-app/node_modules/vite/dist/node/chunks/dep-f5552faa.js:37652:26)
    at build (/data/data/com.termux/files/home/my-app/node_modules/vite/dist/node/chunks/dep-f5552faa.js:37640:22)

Used Package Manager

npm

@FossPrime FossPrime changed the title Esbuild fails to fallback to js/wasm on Android x64 Fails to fallback to js/wasm on Android x64 Feb 28, 2022
@FossPrime FossPrime changed the title Fails to fallback to js/wasm on Android x64 Fails to fallback to js/wasm on Android x64 and no binary available Feb 28, 2022
@evanw
Copy link
Owner

evanw commented Mar 3, 2022

For the record: I'm not going to support this platform natively as the Go compiler doesn't support cross-compiling for this platform. This is the same situation as in #1556, which was Android for ARM 32-bit. The specific error message is loadinternal: cannot find runtime/cgo. I'm not sure why this is the case because Android and Go are both made by Google, but I have asked the Go team about this and lack of support for this is intentional: golang/go#48246 (comment).

I think falling back to WebAssembly in this case could be a good alternative. Or, rather, it's a bad alternative because it's 10x slower but at least it'll work.

@evanw
Copy link
Owner

evanw commented Mar 3, 2022

I gave this a shot in version 0.14.24. Can you try it out and see if it works? It's untested because I don't have an Android x64 device but it should work in theory.

@FossPrime
Copy link
Author

ARM32 is going thw way of the Dodo... Android x64 LE refers to android running x86_64, yes Intel. His comment did not suggest Intel x64 wasn't supported

@FossPrime
Copy link
Author

FossPrime commented Mar 3, 2022

Works great. Speed is good. I believe the Android studio emulator can easily spin up tablet with Android x64 and sideload F-Droid to install the latest Termux terminal emulator. This might actually be a reasonable way to run Linux programs, if Docker is not already in the workflow.

@evanw
Copy link
Owner

evanw commented Mar 4, 2022

Oh wow. I didn't expect it to work the first time since it's never been tested. Glad it works!

@FossPrime
Copy link
Author

It looks like Intel x86_64 support wasn't an official thing until a few months ago with Android 12. The recommended Android emulator images do not attempt to QEMU the ARM... It just runs x86 or x86_64. Which is good news for testing and development.
Screenshot from 2022-03-03 21-27-25

@FossPrime
Copy link
Author

FossPrime commented Mar 4, 2022

UPDATE

I ran the esbuild-linux-64 package on Android amd64, it compiles in 28 seconds!!

Do with that what you will... this is no surprise as Google has been working to upstream more of Android to Linux.

It's probably faster than what I got with my compiled version because of my gcc version, parameters or deoptimizations Golang puts in place when you target Android specifically

$ gcc --version
clang version 13.0.1
Target: x86_64-unknown-linux-android24
Thread model: posix
InstalledDir: /data/data/com.termux/files/usr/bin

It was a whole one second faster to use the 19M Android amd64 binary... compiled on Android using GOOS=android GOARCH=amd64 go build ./cmd/esbuild. All I had to do was build it, set lib/main.js's isWASM=true to false, and drop the binary in esbuild-android-64... yes I deleted to the wasm to be sure the numbers are accurate. This is a 3 year old Vue2 project that builds to 6MiB of css and javascript.

$ date && npx vite build > /dev/null 2>&1 && date
Fri Mar  4 17:10:13 CST 2022
Fri Mar  4 17:10:43 CST 2022
$ vim node_modules/esbuild/lib/main.js
$ mv node_modules/esbuild-android-64 node_modules/esbuild-android-64-native
$ mv node_modules/esbuild-android-69 node_modules/esbuild-android-64
$ date && npx vite build > /dev/null 2>&1 && date
Fri Mar  4 17:13:45 CST 2022
Fri Mar  4 17:14:26 CST 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants