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

Add native builds for ARM-based Macs #820

Merged
merged 3 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.15.7
go-version: 1.16.0
id: go

- name: Setup Node.js environment
Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test-all:
test-prepublish: check-go-version test-all test-preact-splitting test-sucrase bench-rome-esbuild test-esprima test-rollup

check-go-version:
@go version | grep 'go1\.15\.7' || (echo 'Please install Go version 1.15.7' && false)
@go version | grep 'go1\.16\.0' || (echo 'Please install Go version 1.16.0' && false)

test-go:
go test ./internal/...
Expand Down Expand Up @@ -92,6 +92,7 @@ platform-all: cmd/esbuild/version.go test-all
platform-windows \
platform-windows-32 \
platform-darwin \
platform-darwin-arm64 \
platform-freebsd \
platform-freebsd-arm64 \
platform-linux \
Expand Down Expand Up @@ -120,6 +121,9 @@ platform-unixlike:
platform-darwin:
make GOOS=darwin GOARCH=amd64 NPMDIR=npm/esbuild-darwin-64 platform-unixlike

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

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

Expand Down Expand Up @@ -169,6 +173,7 @@ publish-all: cmd/esbuild/version.go test-prepublish
@echo Enter one-time password:
@read OTP && OTP="$$OTP" make -j4 \
publish-darwin \
publish-darwin-arm64 \
publish-linux \
publish-linux-32
@echo Enter one-time password:
Expand All @@ -195,6 +200,9 @@ publish-windows-32: platform-windows-32
publish-darwin: platform-darwin
test -n "$(OTP)" && cd npm/esbuild-darwin-64 && npm publish --otp="$(OTP)"

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

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

Expand Down Expand Up @@ -230,6 +238,7 @@ clean:
rm -f npm/esbuild-windows-32/esbuild.exe
rm -f npm/esbuild-windows-64/esbuild.exe
rm -rf npm/esbuild-darwin-64/bin
rm -rf npm/esbuild-darwin-arm64/bin
rm -rf npm/esbuild-freebsd-64/bin
rm -rf npm/esbuild-freebsd-amd64/bin
rm -rf npm/esbuild-linux-32/bin
Expand Down
17 changes: 2 additions & 15 deletions lib/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,7 @@ async function installBinaryFromPackage(name: string, fromPath: string, toPath:
}

function validateBinaryVersion(binaryPath: string): void {
let stdout;
try {
stdout = child_process.execFileSync(binaryPath, ['--version']).toString().trim();
} catch (err) {
if (platformKey === 'darwin arm64 LE')
throw new Error(`${err && err.message || err}

This install script is trying to install the x64 esbuild executable because the
arm64 esbuild executable is not available yet. Running this executable requires
the Rosetta 2 binary translator. Please make sure you have Rosetta 2 installed
before installing esbuild.
`);
throw err;
}
const stdout = child_process.execFileSync(binaryPath, ['--version']).toString().trim();
if (stdout !== version) {
throw new Error(`Expected ${JSON.stringify(version)} but got ${JSON.stringify(stdout)}`);
}
Expand Down Expand Up @@ -289,7 +276,7 @@ const knownWindowsPackages: Record<string, string> = {
};
const knownUnixlikePackages: Record<string, string> = {
'darwin x64 LE': 'esbuild-darwin-64',
'darwin arm64 LE': 'esbuild-darwin-64',
'darwin arm64 LE': 'esbuild-darwin-arm64',
'freebsd arm64 LE': 'esbuild-freebsd-arm64',
'freebsd x64 LE': 'esbuild-freebsd-64',
'linux arm LE': 'esbuild-linux-arm',
Expand Down
3 changes: 1 addition & 2 deletions npm/esbuild-darwin-64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"darwin"
],
"cpu": [
"x64",
"arm64"
"x64"
],
"directories": {
"bin": "bin"
Expand Down
3 changes: 3 additions & 0 deletions npm/esbuild-darwin-arm64/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# esbuild

This is the macOS ARM 64-bit binary for esbuild, a JavaScript bundler and minifier. See https://github.com/evanw/esbuild for details.
16 changes: 16 additions & 0 deletions npm/esbuild-darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "esbuild-darwin-arm64",
"version": "0.8.46",
"description": "The macOS ARM 64-bit binary for esbuild, a JavaScript bundler.",
"repository": "https://github.com/evanw/esbuild",
"license": "MIT",
"os": [
"darwin"
],
"cpu": [
"arm64"
],
"directories": {
"bin": "bin"
}
}
2 changes: 1 addition & 1 deletion npm/esbuild-wasm/bin/esbuild
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ fs.read = function () {
};

const argv = ['node', wasm_exec, esbuild_wasm].concat(process.argv.slice(2));
wrapper(require, require.main, Object.assign(Object.create(process), { argv }), { instantiate });
wrapper(require, require.main, Object.assign(Object.create(process), { argv }), Object.assign(Object.create(WebAssembly), { instantiate }));
Copy link
Contributor Author

@rtsao rtsao Feb 16, 2021

Choose a reason for hiding this comment

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

As of Golang 1.16.0, the wasm_exec.js run function now has this check:

if (!(instance instanceof WebAssembly.Instance)) {
  throw new Error("Go.run: WebAssembly.Instance expected");
}

This seemed like the simplest solution as opposed to patching the generated code like in

wasm_exec_js = wasm_exec_js.replace(toReplace, `