From c1312c4444ad71ff87998fe66305e2e441e97a3b Mon Sep 17 00:00:00 2001 From: Olivier Chafik Date: Mon, 23 Dec 2024 01:38:28 +0000 Subject: [PATCH] Support & document using custom wasm build (#67) --- Makefile | 19 +++++++++---------- README.md | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index e37856f..ca0e5f1 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,11 @@ SINGLE_BRANCH=--branch master --single-branch SHALLOW=--depth 1 SHELL:=/usr/bin/env bash +WASM_BUILD=Release all: public -.PHONY: public +.PHONY: public wasm public: \ src/wasm \ public/openscad.js \ @@ -41,7 +42,7 @@ public: \ clean: rm -fR libs build rm -fR public/openscad.{js,wasm} - rm -fR public/libraries + rm -fR public/libraries/*.zip rm -fR src/wasm dist/index.js: public @@ -54,13 +55,11 @@ src/wasm: libs/openscad-wasm rm -f src/wasm ln -sf "$(shell pwd)/libs/openscad-wasm" src/wasm -# libs/openscad/build/openscad.js: libs/openscad -# ( cd libs/openscad && ./scripts/wasm-base-docker-run.sh emcmake cmake -B build -DCMAKE_BUILD_TYPE=Release -DEXPERIMENTAL=1 ) -# ( cd libs/openscad && ./scripts/wasm-base-docker-run.sh /bin/bash -c "cmake --build build -j || cmake --build build -j2 || cmake --build build" ) - -# libs/openscad-wasm: libs/openscad/build/openscad.js -# mkdir -p libs/openscad-wasm -# cp libs/openscad/build/openscad.* libs/openscad-wasm/ +wasm: libs/openscad + ( cd libs/openscad && ./scripts/wasm-base-docker-run.sh emcmake cmake -B build -DCMAKE_BUILD_TYPE=$(WASM_BUILD) -DEXPERIMENTAL=1 ) + ( cd libs/openscad && ./scripts/wasm-base-docker-run.sh /bin/bash -c "cmake --build build -j || cmake --build build -j2 || cmake --build build" ) + mkdir -p libs/openscad-wasm + cp libs/openscad/build/openscad.* libs/openscad-wasm/ libs/openscad-wasm: mkdir -p libs/openscad-wasm @@ -143,7 +142,7 @@ libs/openscad: public/libraries/openscad.zip: libs/openscad mkdir -p public/libraries - ( cd libs/openscad ; zip -r ../../public/libraries/openscad.zip `find examples -name '*.scad' | grep -v tests` ) + ( cd libs/openscad ; zip -r - `find examples -name '*.scad' | grep -v tests` ) > public/libraries/openscad.zip libs/BOSL2: git clone --recurse https://github.com/BelfrySCAD/BOSL2.git ${SHALLOW} ${SINGLE_BRANCH} $@ diff --git a/README.md b/README.md index 9352962..70dee01 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,33 @@ rm -fR ../ochafik.github.io/openscad2 && cp -R dist ../ochafik.github.io/opensca # Now commit and push changes, wait for site update and enjoy! ``` +## Build your own WASM binary + +[Makefile](./Makefile) fetches a prebuilt OpenSCAD web WASM binary, but you can build your own in a couple of minutes: + +- **Optional**: use your own openscad fork / branch: + + ```bash + rm -fR libs/openscad + ln -s $PWD/../absolute/path/to/your/openscad libs/openscad + + # If you had a native build directory, delete it. + rm -fR libs/openscad/build + ``` + +- Build WASM binary (add `WASM_BUILD=Debug` argument if you'd like to debug any cryptic crashes): + + ```bash + make wasm + ``` + +- Then continue the build: + + ```bash + make public + npm start + ``` + ## Adding OpenSCAD libraries You'll need to update 3 files (search for BOSL2 for an example):