From 20b9c834b1c15b807f93995c02ee29eb6998e38c Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Thu, 7 Nov 2024 05:30:45 -0500 Subject: [PATCH] chore: use common WASM builder (#3791) --- build/Dockerfile | 25 ------------------------- build/wasm.js | 30 +++++++----------------------- package.json | 1 - 3 files changed, 7 insertions(+), 49 deletions(-) delete mode 100644 build/Dockerfile diff --git a/build/Dockerfile b/build/Dockerfile deleted file mode 100644 index bd330c61c81..00000000000 --- a/build/Dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -FROM node:22-alpine3.19@sha256:f1b43157ce277feaed97088f4d1bbf6b209148d49d98cea592e0af6637657baf - -ARG UID=1000 -ARG GID=1000 -ARG BINARYEN_VERSION=116 - -RUN apk add -U clang lld wasi-sdk -RUN mkdir /home/node/undici - -WORKDIR /home/node/undici - -RUN wget https://github.com/WebAssembly/binaryen/releases/download/version_$BINARYEN_VERSION/binaryen-version_$BINARYEN_VERSION-x86_64-linux.tar.gz && \ - tar -zxvf binaryen-version_$BINARYEN_VERSION-x86_64-linux.tar.gz binaryen-version_$BINARYEN_VERSION/bin/wasm-opt && \ - mv binaryen-version_$BINARYEN_VERSION/bin/wasm-opt ./ && \ - rm binaryen-version_$BINARYEN_VERSION-x86_64-linux.tar.gz && \ - rm -rf binaryen-version_$BINARYEN_VERSION && \ - chmod +x ./wasm-opt - -COPY package.json . - -COPY build build -COPY deps deps -COPY lib lib - -USER node diff --git a/build/wasm.js b/build/wasm.js index 3ed9460ab09..46cd273a3a2 100644 --- a/build/wasm.js +++ b/build/wasm.js @@ -1,5 +1,7 @@ 'use strict' +const WASM_BUILDER_CONTAINER = 'ghcr.io/nodejs/wasm-builder@sha256:975f391d907e42a75b8c72eb77c782181e941608687d4d8694c3e9df415a0970' // v0.0.9 + const { execSync } = require('node:child_process') const { writeFileSync, readFileSync } = require('node:fs') const { join, resolve } = require('node:path') @@ -7,7 +9,6 @@ const { join, resolve } = require('node:path') const ROOT = resolve(__dirname, '../') const WASM_SRC = resolve(__dirname, '../deps/llhttp') const WASM_OUT = resolve(__dirname, '../lib/llhttp') -const DOCKERFILE = resolve(__dirname, './Dockerfile') // These are defined by build environment const WASM_CC = process.env.WASM_CC || 'clang' @@ -52,33 +53,16 @@ if (!platform && process.argv[2]) { platform = execSync('docker info -f "{{.OSType}}/{{.Architecture}}"').toString().trim() } -if (process.argv[2] === '--rm') { - const cmd = 'docker image rm llhttp_wasm_builder' - - console.log(`> ${cmd}\n\n`) - try { - execSync(cmd, { stdio: 'inherit' }) - } catch (e) {} - - process.exit(0) -} - -if (process.argv[2] === '--prebuild') { - const cmd = `docker build --platform=${platform.toString().trim()} -t llhttp_wasm_builder -f ${DOCKERFILE} ${ROOT}` - - console.log(`> ${cmd}\n\n`) - execSync(cmd, { stdio: 'inherit' }) - - process.exit(0) -} - if (process.argv[2] === '--docker') { - let cmd = `docker run --rm -t --platform=${platform.toString().trim()}` + let cmd = `docker run --rm --platform=${platform.toString().trim()} ` if (process.platform === 'linux') { cmd += ` --user ${process.getuid()}:${process.getegid()}` } - cmd += ` --mount type=bind,source=${ROOT}/lib/llhttp,target=/home/node/undici/lib/llhttp llhttp_wasm_builder node build/wasm.js` + cmd += ` --mount type=bind,source=${ROOT}/lib/llhttp,target=/home/node/build/lib/llhttp \ + --mount type=bind,source=${ROOT}/build,target=/home/node/build/build \ + --mount type=bind,source=${ROOT}/deps,target=/home/node/build/deps \ + -t ${WASM_BUILDER_CONTAINER} node build/wasm.js` console.log(`> ${cmd}\n\n`) execSync(cmd, { stdio: 'inherit' }) process.exit(0) diff --git a/package.json b/package.json index fb7b4181fa9..6656a1e9316 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,6 @@ "types": "index.d.ts", "scripts": { "build:node": "esbuild index-fetch.js --bundle --platform=node --outfile=undici-fetch.js --define:esbuildDetection=1 --keep-names && node scripts/strip-comments.js", - "prebuild:wasm": "node build/wasm.js --prebuild", "build:wasm": "node build/wasm.js --docker", "generate-pem": "node scripts/generate-pem.js", "lint": "eslint --cache",