Skip to content

Commit

Permalink
fix #2526: add a wasm shim for "android arm"
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Sep 9, 2022
1 parent 0394cef commit b73e714
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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))
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Expand Up @@ -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 \
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)"

Expand Down
1 change: 1 addition & 0 deletions lib/npm/node-platform.ts
Expand Up @@ -36,6 +36,7 @@ export const knownUnixlikePackages: Record<string, string> = {
};

export const knownWebAssemblyFallbackPackages: Record<string, string> = {
'android arm LE': '@esbuild/android-arm',
'android x64 LE': 'esbuild-android-64',
};

Expand Down
3 changes: 3 additions & 0 deletions 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.
2 changes: 2 additions & 0 deletions npm/@esbuild/android-arm/bin/esbuild
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('esbuild-wasm/bin/esbuild')
20 changes: 20 additions & 0 deletions 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"
]
}
11 changes: 11 additions & 0 deletions scripts/esbuild.js
Expand Up @@ -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')
}
}
Expand Down

0 comments on commit b73e714

Please sign in to comment.