Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
930275e
fix: improve Windows support for npm scripts
dougwithseismic Dec 14, 2025
2fe9b25
feat: migrate WASM build system from Make to CMake for Windows support
dougwithseismic Dec 14, 2025
fc60c4e
fix: improve error handling in build script and remove legacy Makefiles
dougwithseismic Dec 14, 2025
b9408f7
fix(setup-and-dependencies.md): better styles
Ryan-Millard Dec 15, 2025
53c9ef5
remove(pnpm file): Not relevant in this PR
Ryan-Millard Dec 16, 2025
785c3ed
update(CMakeLists.txt files): Ensure consistency & clarity
Ryan-Millard Dec 18, 2025
2e5fa81
feat(docker compose): Set up basic docker usage with CLI script
Ryan-Millard Dec 19, 2025
c4f1696
feat(img2num CLI): Add bat & ps1 scripts for windows users
Ryan-Millard Dec 19, 2025
f84c076
feat(img2num script): Add disclaimer comment for Windows users
Ryan-Millard Dec 19, 2025
26a0832
fix(img2num scripts): Handle args to npm scripts properly
Ryan-Millard Dec 19, 2025
7689a9f
fix(img2num bash script, docs): Forward ports properly & add disclaimer
Ryan-Millard Dec 20, 2025
9776dde
fix(img2num windows scripts): align with bash counterpart, fix commen…
Ryan-Millard Dec 20, 2025
98544a5
fix(img2num bash script): Make executable & add to tracking
Ryan-Millard Dec 20, 2025
1a65ab6
fix(Dockerfile): switch to node:22-bullseye, the latest stable release
Ryan-Millard Dec 20, 2025
c83644c
docs(Makefile references): Switch to CMake where appropriate
Ryan-Millard Dec 20, 2025
eb8584f
docs(setup & dependencies): Update node version to most accurate for …
Ryan-Millard Dec 20, 2025
c71f672
fix(img2num scripts): Duplicate clean arg removed
Ryan-Millard Dec 20, 2025
b5498e0
fix(imng2num scripts): Provide proper exit codes for success and fail…
Ryan-Millard Dec 20, 2025
09695ca
docs(setup & deps): Fix header & code block - use ## instead of #, sp…
Ryan-Millard Dec 20, 2025
1248d8d
chore(img2num.bat): remove duplicate comment
Ryan-Millard Dec 20, 2025
a051603
chore(build-wasm.js): Add helpful log regarding rm -rf
Ryan-Millard Dec 20, 2025
bdda9a0
chore(img2num sh script): Fix wording
Ryan-Millard Dec 20, 2025
2ee0b07
fix(img2num scripts): stop hiding docker errors - allows users to tro…
Ryan-Millard Dec 20, 2025
caff168
refactor(img2num scripts): add purge arg, better container management
Ryan-Millard Dec 20, 2025
49891ef
feat(.editorconfig): Add bash, batch, powershell support
Ryan-Millard Dec 20, 2025
5ea0721
feat(docker-compose.yml): add remote image ryanmillard/img2num-dev:la…
Ryan-Millard Dec 20, 2025
0b745d8
docs(getting-started): update comprehensive installation and first-ru…
Ryan-Millard Dec 21, 2025
0de2ac7
docs(getting-started): add tip on help args for img2num script
Ryan-Millard Dec 21, 2025
9c30b94
docs(getting-started): add tip on help npm script for local users
Ryan-Millard Dec 21, 2025
002802b
docs(intro page): fix grammatical error
Ryan-Millard Dec 21, 2025
0e9fae5
Merge remote-tracking branch 'origin/main' into feat/docker-docker-co…
Ryan-Millard Dec 22, 2025
80ac27e
docs(README.md): update README.md disclaimer comment for better PR re…
Ryan-Millard Dec 22, 2025
9a24995
docs(fix intro links): remove redundant, use HTTPS for Blank Issue link
Ryan-Millard Dec 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .devcontainer/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail

# Source emsdk environment
if [ -f "${EMSDK_ROOT}/emsdk_env.sh" ]; then
source "${EMSDK_ROOT}/emsdk_env.sh"
fi

# Go to workdir
cd /usr/src/app

exec "$@"
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/*
dist/*
build/*
docs/build/*
.vscode
.git
.gitignore
.DS_Store
21 changes: 18 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,25 @@ insert_final_newline = true
max_line_length = 120

# -------------------------
# Makefile
# CMake
# -------------------------
[Makefile]
indent_style = tab
[CMakeLists.txt]
indent_style = space
indent_size = 2
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 120

[*.cmake]
indent_style = space
indent_size = 2
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 120

# -------------------------
# JavaScript / React
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ dist-ssr
*:Zone.Identifier

src/data/contributor-credits.json

# CMake build artifacts
src/wasm/cmake-build/
src/wasm/**/CMakeCache.txt
src/wasm/**/CMakeFiles/
42 changes: 42 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# ------------------------
# Img2Num Dockerfile.dev
# ------------------------
FROM node:22-bullseye

ENV EMSDK_VERSION=4.0.10
Comment thread
Ryan-Millard marked this conversation as resolved.
Resolved
ENV EMSDK_DIR=/opt/emsdk

RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
cmake \
python3 \
git \
curl \
unzip \
pkg-config \
bash \
ca-certificates \
libvips-dev \
&& rm -rf /var/lib/apt/lists/*

# Install EMSDK once, cached by Docker layers
RUN git clone --depth 1 https://github.com/emscripten-core/emsdk.git $EMSDK_DIR \
&& cd $EMSDK_DIR \
&& git fetch --tags \
&& git checkout $EMSDK_VERSION \
&& ./emsdk install $EMSDK_VERSION \
&& ./emsdk activate $EMSDK_VERSION

ENV PATH=$EMSDK_DIR:$EMSDK_DIR/upstream/emscripten:$PATH
ENV EMSDK=$EMSDK_DIR

RUN npm install -g npm@11

WORKDIR /usr/src/app

ENV CHOKIDAR_USEPOLLING=true
ENV CHOKIDAR_INTERVAL=100

EXPOSE 5173 3000

CMD ["bash"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--TODO: Remove the section below after #93 is merged on 22 Dec 2025-->
<!--TODO: Remove the section below after #93 is merged on 22 Dec 2025 - wait 2 weeks, so remove this on 5 Jan 2026 -->
Comment thread
Ryan-Millard marked this conversation as resolved.
Resolved
> [!CAUTION]
> ⚠️⚠️⚠️ **Breaking Change in [PR #93](https://github.com/Ryan-Millard/Img2Num/pull/93)** ⚠️⚠️⚠️
>
Expand Down Expand Up @@ -52,7 +52,7 @@
| Build Tool | Vite 7 |
| Styling | CSS (basic) |
| Linting | ESLint |
| Scripting | Makefile for WASM builds |
| Scripting | CMake for WASM builds |

---

Expand Down
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
services:
dev:
build:
context: .
dockerfile: Dockerfile.dev
container_name: img2num-dev
working_dir: /usr/src/app
volumes:
- .:/usr/src/app:cached
- node_modules:/usr/src/app/node_modules
- docs_node_modules:/usr/src/app/docs/node_modules
environment:
CHOKIDAR_USEPOLLING: "true"
CHOKIDAR_INTERVAL: "100"
ports:
- "5173:5173" # Vite dev
- "4173:4173" # Vite preview
- "3000:3000" # Docusaurus dev
stdin_open: true
tty: true

volumes:
node_modules:
docs_node_modules:
2 changes: 1 addition & 1 deletion docs/docs/guidelines/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The [Project Scripts](../project-scripts/overview.md) section shows all of the a
## Additional Resources

- [README](https://github.com/Ryan-Millard/Img2Num/blob/main/README.md)
- [Orchestrator Makefile](https://github.com/Ryan-Millard/Img2Num/blob/main/src/wasm/Makefile)
- [Orchestrator CMakeLists.txt](https://github.com/Ryan-Millard/Img2Num/blob/main/src/wasm/CMakeLists.txt)
- [Vite Config](https://github.com/Ryan-Millard/Img2Num/blob/main/vite.config.js)
- [ESLint Config](https://github.com/Ryan-Millard/Img2Num/blob/main/eslint.config.js)

Expand Down
5 changes: 1 addition & 4 deletions docs/docs/guidelines/coding-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sidebar_position: 3

## 🌐General Rules
- **Follow `.editorconfig`** exactly:
- Indent: **2 spaces** (except Makefile: tabs)
- Indent: **2 spaces**
- Charset: **UTF-8**
- Line endings: **LF**
- Max line length: 120 (off for JSON, Markdown, lock files, images)
Expand Down Expand Up @@ -93,9 +93,6 @@ namespace exampleNamespace
- Final newline: true (lock files: false)
- Max line length: off

## πŸ“ Makefiles
- Indent: **tabs only**

## πŸ–Ό Images / Binary Assets
- Charset: binary
- Do not trim trailing whitespace
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/project-scripts/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Runs the WASM release build:
make -C src/wasm build
```

Creates an optimized WebAssembly module using the `build` script available in the [orchestrator Makefile](https://github.com/Ryan-Millard/Img2Num/blob/main/src/wasm/Makefile).
Creates an optimized WebAssembly module using the `build` script available in the [orchestrator CMakeLists.txt](https://github.com/Ryan-Millard/Img2Num/blob/main/src/wasm/CMakeLists.txt).

## `npm run build-wasm:debug`

Expand All @@ -55,4 +55,4 @@ Runs the debug build:
make -C src/wasm debug
```

Includes debug symbols and no optimizations. Recommended for debugging logic issues inside C++ code. Also uses a script from the [orchestrator Makefile](https://github.com/Ryan-Millard/Img2Num/blob/main/src/wasm/Makefile).
Includes debug symbols and no optimizations. Recommended for debugging logic issues inside C++ code. Also uses a script from the [orchestrator CMakeLists.txt](https://github.com/Ryan-Millard/Img2Num/blob/main/src/wasm/CMakeLists.txt).
8 changes: 5 additions & 3 deletions docs/docs/project-scripts/clean.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ Ensures the project returns to a β€œfresh” state.
Removes the Vite build output directory:

```bash
rm -rf dist
rimraf dist
```

## `npm run clean-wasm`

Delegates to:

```bash
make -C src/wasm clean
node scripts/build-wasm.js --clean
```

This calls the [orchestrator Makefile's](https://github.com/Ryan-Millard/Img2Num/blob/main/src/wasm/Makefile) `clean` script, which calls the `clean` script in every WASM module.
`scripts/build-wasm.js` handles the deletion of build files.

This calls the [orchestrator CMakeLists.txt's](https://github.com/Ryan-Millard/Img2Num/blob/main/src/wasm/CMakeLists.txt) `clean` script, which calls the `clean` script in every WASM module.
2 changes: 1 addition & 1 deletion docs/docs/project-scripts/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Img2Num provides several `npm scripts` that help with development, building, for
This section explains each script category in detail:

- Development scripts
- WASM build scripts (handled by the [orchestrator Makefile](https://github.com/Ryan-Millard/Img2Num/blob/main/src/wasm/Makefile), but wrapped by `npm` in `package.json`)
- WASM build scripts (handled by the [orchestrator CMakeLists.txt](https://github.com/Ryan-Millard/Img2Num/blob/main/src/wasm/CMakeLists.txt), but wrapped by `npm` in `package.json`)
- Build & preview scripts
- Cleanup scripts
- Formatting scripts
Expand Down
127 changes: 84 additions & 43 deletions docs/docs/reference/wasm/development-workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,94 @@ This repository configures a Vite plugin (`watch-cpp-and-build-wasm`) that watch
Important points:

* The watcher registers `src/wasm/**/*.{cpp,h}` with Vite's watcher so edits trigger rebuilds.
* The build uses the root `src/wasm/Makefile` which iterates modules and calls each module's `Makefile`.
* The build uses the root `src/wasm/CMakeLists.txt` which iterates through the modules and calls each module's `CMakeLists.txt`.
* For faster local iteration use `npm run dev:debug` β€” this runs `make debug` and launches the dev server.

## Root Makefile contract

The root `src/wasm/Makefile` (provided in the repo) implements three main targets:

```makefile
.PHONY: build debug clean

build:
# for each module with a Makefile => make -C $$module

debug:
# same but pass `debug` target to sub-makefiles

clean:
# invoke `make clean` in each module
## Root CMakeLists.txt contract

The root `src/wasm/CMakeLists.txt` (provided in the repo) implements two main targets, `build` & `debug`.
Submodule CMakeLists.txt must therefore support at least `build` (default) & `debug` targets.

## Example submodule CMakeLists.txt template (recommended)

```CMakeLists.txt
# =================================================================
# <ModuleName> WASM Module - CMake Build Configuration
# =================================================================

# Get module name from directory
get_filename_component(MODULE_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)

# Capitalize first letter for export name (e.g., "example" -> "Example")
string(SUBSTRING ${MODULE_NAME} 0 1 FIRST_LETTER)
string(TOUPPER ${FIRST_LETTER} FIRST_LETTER_UPPER)
string(SUBSTRING ${MODULE_NAME} 1 -1 REST_OF_NAME)
set(CAP_MODULE_NAME "${FIRST_LETTER_UPPER}${REST_OF_NAME}")

# Collect source files (recursively)
file(GLOB_RECURSE SRC_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
)

# Output directory
set(BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/build")
set(OUT_JS "${BUILD_DIR}/index.js")

# Create executable target (Emscripten produces .js + .wasm)
add_executable(${MODULE_NAME}_wasm ${SRC_FILES})

# Include directories
target_include_directories(${MODULE_NAME}_wasm PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
)

# Shared Emscripten options
set(COMMON_FLAGS
"SHELL:-s MODULARIZE=1"
"SHELL:-s EXPORT_ES6=1"
"SHELL:-s EXIT_RUNTIME=1"
"SHELL:-s ENVIRONMENT=web"
"SHELL:-s EXPORTED_FUNCTIONS=['_malloc','_free']"
"SHELL:-s EXPORTED_RUNTIME_METHODS=['ccall','cwrap','getValue','setValue','HEAPU8']"
"SHELL:-s INITIAL_MEMORY=1024MB"
"SHELL:-s MAXIMUM_MEMORY=2048MB"
"SHELL:-s ALLOW_MEMORY_GROWTH=1"
"SHELL:-s EXPORT_NAME=create${CAP_MODULE_NAME}Module"
)

# Apply common flags
target_link_options(${MODULE_NAME}_wasm PRIVATE ${COMMON_FLAGS})

# Build-type specific flags
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(${MODULE_NAME}_wasm PRIVATE -O0 -g4)
target_link_options(${MODULE_NAME}_wasm PRIVATE
"SHELL:-s ASSERTIONS=2"
-g4
)
else()
target_compile_options(${MODULE_NAME}_wasm PRIVATE -O3)
target_link_options(${MODULE_NAME}_wasm PRIVATE
"SHELL:-s SINGLE_FILE=0"
)
endif()

# Set output location and name
set_target_properties(${MODULE_NAME}_wasm PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${BUILD_DIR}"
OUTPUT_NAME "index"
SUFFIX ".js"
)

message(STATUS "Module '${MODULE_NAME}' configured (export: create${CAP_MODULE_NAME}Module)")
```

Submodule Makefiles must therefore support at least `build` (default), `debug`, and `clean` targets.

## Example submodule Makefile template (recommended)

```makefile
# src/wasm/modules/<your-module>/Makefile
EMCC ?= emcc
CXXFLAGS_RELEASE = -O3 -s ALLOW_MEMORY_GROWTH=1 -s WASM=1
CXXFLAGS_DEBUG = -g -O0 -s ASSERTIONS=1 -s DEMANGLE_SUPPORT=1
SRC = $(wildcard src/*.cpp)
OUT_DIR = build

.PHONY: all build debug clean

all: build

build:
mkdir -p $(OUT_DIR)
$(EMCC) $(SRC) -o $(OUT_DIR)/index.js $(CXXFLAGS_RELEASE) --bind

debug:
mkdir -p $(OUT_DIR)
$(EMCC) $(SRC) -o $(OUT_DIR)/index.js $(CXXFLAGS_DEBUG) --bind

clean:
rm -rf $(OUT_DIR)
```
:::note
1. Place your C++ headers in include/ and sources in src/
2. Use exported functions via ccall/cwrap in JS
3. Adjust memory flags if your module needs more/less WASM memory
4. For module-specific Emscripten options, add them before target_link_options
:::

This template compiles all `.cpp` files under `src/` into `build/index.js` + `build/index.wasm` using simple flags. Tailor flags and link-time options to your needs.

Expand Down
Loading