From b73e714678f1f185f28b2d08423b7a8ce7b4b0a0 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Fri, 9 Sep 2022 19:32:04 +0800 Subject: [PATCH] fix #2526: add a wasm shim for "android arm" --- CHANGELOG.md | 8 ++++++++ Makefile | 8 ++++++++ lib/npm/node-platform.ts | 1 + npm/@esbuild/android-arm/README.md | 3 +++ npm/@esbuild/android-arm/bin/esbuild | 2 ++ npm/@esbuild/android-arm/package.json | 20 ++++++++++++++++++++ scripts/esbuild.js | 11 +++++++++++ 7 files changed, 53 insertions(+) create mode 100644 npm/@esbuild/android-arm/README.md create mode 100755 npm/@esbuild/android-arm/bin/esbuild create mode 100644 npm/@esbuild/android-arm/package.json diff --git a/CHANGELOG.md b/CHANGELOG.md index e8b46078276..3e93af371ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,14 @@ That bug is fixed in this release. The code generated by esbuild no longer contains a name collision. +* Fall back to WebAssembly on Android ARM ([#1556](https://github.com/evanw/esbuild/issues/1556), [#1578](https://github.com/evanw/esbuild/issues/1578), [#2335](https://github.com/evanw/esbuild/issues/2335), [#2526](https://github.com/evanw/esbuild/issues/2526)) + + Go's compiler supports trivial cross-compiling to almost all platforms without installing any additional software other than the Go compiler itself. This has made it very easy for esbuild to publish native binary executables for many platforms. However, it strangely doesn't support cross-compiling to Android ARM without installing the Android build tools. + + So instead of publishing a native esbuild binary executable to npm, this release publishes a WebAssembly fallback build. This is essentially the same as the `esbuild-wasm` package but it's installed automatically when you install the `esbuild` package on Android ARM. So packages that depend on the `esbuild` package should now work on Android ARM. This change has not yet been tested end-to-end because I don't have a 32-bit Android ARM device myself, but in theory it should work. + + This inherits the drawbacks of WebAssembly including significantly slower performance than native as well as potentially also more severe memory usage limitations. If you want to use a native binary executable of esbuild on Android ARM, you may be able to build it yourself from source after installing the Android build tools. + ## 0.15.7 * Add `--watch=forever` to allow esbuild to never terminate ([#1511](https://github.com/evanw/esbuild/issues/1511), [#1885](https://github.com/evanw/esbuild/issues/1885)) diff --git a/Makefile b/Makefile index fe34a826f28..c0bd65d77a0 100644 --- a/Makefile +++ b/Makefile @@ -255,6 +255,7 @@ wasm-napi-exit0-windows: platform-all: @$(MAKE) --no-print-directory -j4 \ platform-android \ + platform-android-arm \ platform-android-arm64 \ platform-darwin \ platform-darwin-arm64 \ @@ -301,6 +302,9 @@ platform-unixlike: version-go platform-android: platform-wasm node scripts/esbuild.js npm/esbuild-android-64/package.json --version +platform-android-arm: + node scripts/esbuild.js npm/@esbuild/android-arm/package.json --version + platform-android-arm64: @$(MAKE) --no-print-directory GOOS=android GOARCH=arm64 NPMDIR=npm/esbuild-android-arm64 platform-unixlike @@ -402,6 +406,7 @@ publish-all: check-go-version @echo Enter one-time password: @read OTP && OTP="$$OTP" $(MAKE) --no-print-directory -j4 \ publish-android \ + publish-android-arm \ publish-android-arm64 \ publish-darwin \ publish-darwin-arm64 @@ -442,6 +447,9 @@ publish-windows-arm64: platform-windows-arm64 publish-android: platform-android test -n "$(OTP)" && cd npm/esbuild-android-64 && npm publish --otp="$(OTP)" +publish-android-arm: platform-android-arm + test -n "$(OTP)" && cd npm/@esbuild/android-arm && npm publish --otp="$(OTP)" + publish-android-arm64: platform-android-arm64 test -n "$(OTP)" && cd npm/esbuild-android-arm64 && npm publish --otp="$(OTP)" diff --git a/lib/npm/node-platform.ts b/lib/npm/node-platform.ts index bbc1c212d0d..b4dbccba509 100644 --- a/lib/npm/node-platform.ts +++ b/lib/npm/node-platform.ts @@ -36,6 +36,7 @@ export const knownUnixlikePackages: Record = { }; export const knownWebAssemblyFallbackPackages: Record = { + 'android arm LE': '@esbuild/android-arm', 'android x64 LE': 'esbuild-android-64', }; diff --git a/npm/@esbuild/android-arm/README.md b/npm/@esbuild/android-arm/README.md new file mode 100644 index 00000000000..d8cc415dcff --- /dev/null +++ b/npm/@esbuild/android-arm/README.md @@ -0,0 +1,3 @@ +# esbuild + +This is a WebAssembly shim for esbuild on Android ARM. See https://github.com/evanw/esbuild for details. diff --git a/npm/@esbuild/android-arm/bin/esbuild b/npm/@esbuild/android-arm/bin/esbuild new file mode 100755 index 00000000000..5e1c875667e --- /dev/null +++ b/npm/@esbuild/android-arm/bin/esbuild @@ -0,0 +1,2 @@ +#!/usr/bin/env node +require('esbuild-wasm/bin/esbuild') diff --git a/npm/@esbuild/android-arm/package.json b/npm/@esbuild/android-arm/package.json new file mode 100644 index 00000000000..368a539183d --- /dev/null +++ b/npm/@esbuild/android-arm/package.json @@ -0,0 +1,20 @@ +{ + "name": "@esbuild/android-arm", + "version": "0.15.7", + "description": "A WebAssembly shim for esbuild on Android ARM.", + "repository": "https://github.com/evanw/esbuild", + "license": "MIT", + "preferUnplugged": false, + "engines": { + "node": ">=12" + }, + "dependencies": { + "esbuild-wasm": "0.15.7" + }, + "os": [ + "android" + ], + "cpu": [ + "arm" + ] +} diff --git a/scripts/esbuild.js b/scripts/esbuild.js index 8bd5d9de0d4..f53e252bbb9 100644 --- a/scripts/esbuild.js +++ b/scripts/esbuild.js @@ -305,8 +305,19 @@ exports.removeRecursiveSync = path => { const updateVersionPackageJSON = pathToPackageJSON => { const version = fs.readFileSync(path.join(path.dirname(__dirname), 'version.txt'), 'utf8').trim() const json = JSON.parse(fs.readFileSync(pathToPackageJSON, 'utf8')) + let changed = false + if (json.version !== version) { json.version = version + changed = true + } + + if ('dependencies' in json && 'esbuild-wasm' in json.dependencies && json.dependencies['esbuild-wasm'] !== version) { + json.dependencies['esbuild-wasm'] = version + changed = true + } + + if (changed) { fs.writeFileSync(pathToPackageJSON, JSON.stringify(json, null, 2) + '\n') } }