-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "fix: update to use common wasm builder"
This reverts commit bb0e131.
- Loading branch information
1 parent
4e8839f
commit 22351de
Showing
5 changed files
with
150 additions
and
132 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,4 +3,3 @@ | |
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 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
FROM rust:latest | ||
|
||
ARG UID=1000 | ||
ARG GID=1000 | ||
|
||
SHELL ["/bin/bash", "-c"] | ||
|
||
# nvm environment variables | ||
ENV NVM_VERSION 0.39.7 | ||
ENV NVM_DIR /usr/local/nvm | ||
ENV NODE_VERSION 20.15.1 | ||
|
||
# install nvm | ||
RUN mkdir -p $NVM_DIR \ | ||
&& curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v${NVM_VERSION}/install.sh | bash | ||
|
||
# install node and npm | ||
RUN source ${NVM_DIR}/nvm.sh \ | ||
&& nvm install $NODE_VERSION \ | ||
&& nvm alias default $NODE_VERSION \ | ||
&& nvm use default | ||
|
||
# add node and npm to path so the commands are available | ||
ENV NODE_PATH ${NVM_DIR}/v${NODE_VERSION}/lib/node_modules | ||
ENV PATH ${NVM_DIR}/versions/node/v${NODE_VERSION}/bin:$PATH | ||
|
||
# confirm installation | ||
RUN node -v | ||
RUN npm -v | ||
|
||
WORKDIR /usr/src/amaro | ||
|
||
COPY deps/swc . | ||
|
||
WORKDIR /usr/src/amaro/bindings/binding_typescript_wasm | ||
|
||
RUN apt-get update && apt-get -y install cmake | ||
|
||
RUN cargo install --locked wasm-pack | ||
|
||
RUN ./scripts/build.sh | ||
|
||
RUN mkdir -p /usr/src/amaro/swc | ||
|
||
RUN cp -r pkg/* /usr/src/amaro/swc | ||
|
||
# USER node |
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,56 +1,29 @@ | ||
const WASM_BUILDER_CONTAINER = | ||
"ghcr.io/nodejs/wasm-builder@sha256:975f391d907e42a75b8c72eb77c782181e941608687d4d8694c3e9df415a0970"; // v0.0.9 | ||
|
||
const { execSync, execFileSync } = require("node:child_process"); | ||
const { execFileSync } = 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 = execFileSync("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") { | ||
const args = []; | ||
args.push("run"); | ||
args.push("--rm"); | ||
args.push("--platform"); | ||
args.push(`${platform.toString().trim()}`); | ||
if (process.platform === "linux") { | ||
args.push("--user"); | ||
args.push(`${process.getuid()}:${process.getegid()}`); | ||
} | ||
args.push("--mount"); | ||
args.push( | ||
`type=bind,source=${ROOT}/deps/swc/bindings,target=/home/node/build/bindings`, | ||
); | ||
args.push("--mount"); | ||
args.push(`type=bind,source=${ROOT}/lib,target=/home/node/build/lib`); | ||
args.push("--mount"); | ||
args.push(`type=bind,source=${ROOT}/tools,target=/home/node/build/tools`); | ||
args.push("--mount"); | ||
args.push(`type=bind,source=${ROOT}/deps,target=/home/node/build/deps`); | ||
args.push("-t"); | ||
args.push(`${WASM_BUILDER_CONTAINER}`); | ||
args.push("node"); | ||
args.push("./tools/build-wasm.js"); | ||
console.log(`> docker ${args}\n\n`); | ||
execFileSync("docker", args, { stdio: "inherit" }); | ||
process.exit(0); | ||
} | ||
// Removes the Docker image. | ||
execFileSync("docker", ["rm", name], { stdio: "inherit" }); | ||
|
||
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" }, | ||
); | ||
process.exit(0); |