-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update to use common wasm builder
Signed-off-by: Michael Dawson <[email protected]>
- Loading branch information
Showing
5 changed files
with
114 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
node_modules | ||
dist | ||
package-lock.json | ||
deps/swc/bindings/target/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,39 @@ | ||
const { execFileSync } = require("node:child_process"); | ||
const WASM_BUILDER_CONTAINER = | ||
"ghcr.io/nodejs/wasm-builder@sha256:975f391d907e42a75b8c72eb77c782181e941608687d4d8694c3e9df415a0970"; // v0.0.9 | ||
|
||
const { execSync } = require("node:child_process"); | ||
const { resolve } = require("node:path"); | ||
|
||
const ROOT = resolve(__dirname, "../"); | ||
const DOCKERFILE = resolve(__dirname, "./Dockerfile"); | ||
|
||
const name = `swc_build_wasm-${Date.now()}`; | ||
|
||
const buildArgs = [ | ||
"build", | ||
"-t", | ||
"swc_wasm_typescript", | ||
"-f", | ||
DOCKERFILE, | ||
ROOT, | ||
]; | ||
execFileSync("docker", buildArgs, { stdio: "inherit" }); | ||
|
||
const runArgs = ["run", "-d", "--name", name, "swc_wasm_typescript"]; | ||
execFileSync("docker", runArgs, { stdio: "inherit" }); | ||
let platform = process.env.WASM_PLATFORM; | ||
if (!platform && process.argv[2]) { | ||
platform = execSync('docker info -f "{{.OSType}}/{{.Architecture}}"') | ||
.toString() | ||
.trim(); | ||
} | ||
|
||
// Copies the new directory inside the Docker image to the host. | ||
const copyArgs = ["cp", `${name}:/usr/src/amaro/swc/.`, `${ROOT}/lib/`]; | ||
execFileSync("docker", copyArgs, { stdio: "inherit" }); | ||
if (process.argv[2] === "--docker") { | ||
let cmd = `docker run --rm --platform=${platform.toString().trim()} `; | ||
if (process.platform === "linux") { | ||
cmd += ` --user ${process.getuid()}:${process.getegid()}`; | ||
} | ||
|
||
// Removes the Docker image. | ||
execFileSync("docker", ["rm", name], { stdio: "inherit" }); | ||
cmd += ` --mount type=bind,source=${ROOT}/deps/swc/bindings,target=/home/node/build/bindings \ | ||
--mount type=bind,source=${ROOT}/lib,target=/home/node/build/lib \ | ||
--mount type=bind,source=${ROOT}/tools,target=/home/node/build/tools \ | ||
--mount type=bind,source=${ROOT}/deps,target=/home/node/build/deps \ | ||
-t ${WASM_BUILDER_CONTAINER} node tools/build-wasm.js`; | ||
console.log(`> ${cmd}\n\n`); | ||
execSync(cmd, { stdio: "inherit" }); | ||
Check warning Code scanning / CodeQL Shell command built from environment values Medium
This shell command depends on an uncontrolled
absolute path Error loading related location Loading This shell command depends on an uncontrolled absolute path Error loading related location Loading |
||
process.exit(0); | ||
} | ||
|
||
process.exit(0); | ||
execSync( | ||
`cd bindings/binding_typescript_wasm && \ | ||
cargo install --locked wasm-pack && \ | ||
PATH=/home/node/.cargo/bin:$PATH && \ | ||
./scripts/build.sh && \ | ||
cp -r pkg/* ../../lib`, | ||
{ stdio: "inherit" }, | ||
); |