From 67d7504643b21fe75d3a19cfa823fda2cacc839d Mon Sep 17 00:00:00 2001 From: Rushil Kapoor Date: Tue, 16 Jul 2024 13:17:32 +0530 Subject: [PATCH 1/2] feat: add Dockerfile and Makefile So that Mac M1 users can run wasm-pack successfully, otherwise it throws error. BTC-1317 --- packages/wasm-miniscript/.dockerignore | 1 + packages/wasm-miniscript/Dockerfile | 25 +++++++++++++++++++++++++ packages/wasm-miniscript/Makefile | 22 ++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 packages/wasm-miniscript/.dockerignore create mode 100644 packages/wasm-miniscript/Dockerfile create mode 100644 packages/wasm-miniscript/Makefile diff --git a/packages/wasm-miniscript/.dockerignore b/packages/wasm-miniscript/.dockerignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/packages/wasm-miniscript/.dockerignore @@ -0,0 +1 @@ +node_modules/ diff --git a/packages/wasm-miniscript/Dockerfile b/packages/wasm-miniscript/Dockerfile new file mode 100644 index 0000000..dc53885 --- /dev/null +++ b/packages/wasm-miniscript/Dockerfile @@ -0,0 +1,25 @@ +# Start from a Node.js base image +FROM node:20 + +# Install Rust +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y +ENV PATH="/root/.cargo/bin:${PATH}" + +# Install wasm-pack +RUN cargo install wasm-pack + +# Install clang +RUN apt-get update && apt-get install -y clang + +# Create app directory +WORKDIR /usr/src/app + +# Install app dependencies +COPY package*.json ./ +RUN npm install + +# Bundle app source +COPY . . + +# Build the project +RUN npm run build diff --git a/packages/wasm-miniscript/Makefile b/packages/wasm-miniscript/Makefile new file mode 100644 index 0000000..d91f03f --- /dev/null +++ b/packages/wasm-miniscript/Makefile @@ -0,0 +1,22 @@ +.PHONY: build-image build-wasm enter-image clean-container clean-image + +CONTAINER_ENGINE ?= docker + +build-image: + $(CONTAINER_ENGINE) build --tag wasm-builder . + +build-wasm: + $(CONTAINER_ENGINE) run -v $(shell pwd)/src:/usr/src/app/src \ + --name wasm-builder-container wasm-builder \ + npm run build + $(CONTAINER_ENGINE) cp wasm-builder-container:/usr/src/app/dist . + $(CONTAINER_ENGINE) cp wasm-builder-container:/usr/src/app/js/wasm ./js/wasm + +enter-image: + $(CONTAINER_ENGINE) run -it wasm-builder /bin/bash + +clean-container: + $(CONTAINER_ENGINE) rm wasm-builder-container + +clean-image: + $(CONTAINER_ENGINE) rmi wasm-builder From fc4d49f6c589ccb6299ad3a3f79145842e9b38c4 Mon Sep 17 00:00:00 2001 From: Rushil Kapoor Date: Tue, 16 Jul 2024 15:04:23 +0530 Subject: [PATCH 2/2] docs: update README BTC-1333 --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2a1c361..8d3f5b6 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,13 @@ to WebAssembly. It allows you to use Miniscript in NodeJS and in the browser. - [Rust](https://www.rust-lang.org/) nightly - [wasm-pack](https://rustwasm.github.io/wasm-pack/) (install with `cargo install wasm-pack`) -- [NodeJS](https://nodejs.org/en/) \ No newline at end of file +- [NodeJS](https://nodejs.org/en/) + +# Building + +You can use the Docker image / Makefile to build the wasm files: + +```bash +make build-image +make build-wasm +```