From 463ef956abad75ff95e0b6f605865090aa794d30 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Wed, 25 Sep 2024 11:32:50 -0400 Subject: [PATCH] chore: use common WASM builder Fixes: https://github.com/nodejs/undici/issues/3714 --- 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 ebf7a3fcffe..00000000000 --- a/build/Dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -FROM node:22-alpine3.19@sha256:3cb4748ed93c45cf4622c3382a5ce063af1fcbc5f3da6d2b669352ebace9f76d - -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 12c47f46824..9b874ecc540 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,6 @@ "types": "index.d.ts", "scripts": { "build:node": "npx esbuild@0.19.10 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",