Repository navigation
Feat: Add Docker setup, CMake and cross-platform build scripts #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 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 2fe9b25
feat: migrate WASM build system from Make to CMake for Windows support
dougwithseismic fc60c4e
fix: improve error handling in build script and remove legacy Makefiles
dougwithseismic b9408f7
fix(setup-and-dependencies.md): better styles
Ryan-Millard 53c9ef5
remove(pnpm file): Not relevant in this PR
Ryan-Millard 785c3ed
update(CMakeLists.txt files): Ensure consistency & clarity
Ryan-Millard 2e5fa81
feat(docker compose): Set up basic docker usage with CLI script
Ryan-Millard c4f1696
feat(img2num CLI): Add bat & ps1 scripts for windows users
Ryan-Millard f84c076
feat(img2num script): Add disclaimer comment for Windows users
Ryan-Millard 26a0832
fix(img2num scripts): Handle args to npm scripts properly
Ryan-Millard 7689a9f
fix(img2num bash script, docs): Forward ports properly & add disclaimer
Ryan-Millard 9776dde
fix(img2num windows scripts): align with bash counterpart, fix commenβ¦
Ryan-Millard 98544a5
fix(img2num bash script): Make executable & add to tracking
Ryan-Millard 1a65ab6
fix(Dockerfile): switch to node:22-bullseye, the latest stable release
Ryan-Millard c83644c
docs(Makefile references): Switch to CMake where appropriate
Ryan-Millard eb8584f
docs(setup & dependencies): Update node version to most accurate for β¦
Ryan-Millard c71f672
fix(img2num scripts): Duplicate clean arg removed
Ryan-Millard b5498e0
fix(imng2num scripts): Provide proper exit codes for success and failβ¦
Ryan-Millard 09695ca
docs(setup & deps): Fix header & code block - use ## instead of #, spβ¦
Ryan-Millard 1248d8d
chore(img2num.bat): remove duplicate comment
Ryan-Millard a051603
chore(build-wasm.js): Add helpful log regarding rm -rf
Ryan-Millard bdda9a0
chore(img2num sh script): Fix wording
Ryan-Millard 2ee0b07
fix(img2num scripts): stop hiding docker errors - allows users to troβ¦
Ryan-Millard caff168
refactor(img2num scripts): add purge arg, better container management
Ryan-Millard 49891ef
feat(.editorconfig): Add bash, batch, powershell support
Ryan-Millard 5ea0721
feat(docker-compose.yml): add remote image ryanmillard/img2num-dev:laβ¦
Ryan-Millard 0b745d8
docs(getting-started): update comprehensive installation and first-ruβ¦
Ryan-Millard 0de2ac7
docs(getting-started): add tip on help args for img2num script
Ryan-Millard 9c30b94
docs(getting-started): add tip on help npm script for local users
Ryan-Millard 002802b
docs(intro page): fix grammatical error
Ryan-Millard 0e9fae5
Merge remote-tracking branch 'origin/main' into feat/docker-docker-coβ¦
Ryan-Millard 80ac27e
docs(README.md): update README.md disclaimer comment for better PR reβ¦
Ryan-Millard 9a24995
docs(fix intro links): remove redundant, use HTTPS for Blank Issue link
Ryan-Millard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,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 "$@" |
This file contains hidden or 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,8 @@ | ||
| node_modules/* | ||
| dist/* | ||
| build/* | ||
| docs/build/* | ||
| .vscode | ||
| .git | ||
| .gitignore | ||
| .DS_Store |
This file contains hidden or 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 hidden or 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,42 @@ | ||
| # ------------------------ | ||
| # Img2Num Dockerfile.dev | ||
| # ------------------------ | ||
| FROM node:23-bullseye | ||
|
|
||
| ENV EMSDK_VERSION=4.0.10 | ||
| 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"] | ||
This file contains hidden or 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,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: |
This file contains hidden or 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 hidden or 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,42 +1,148 @@ | ||
| --- | ||
| id: wasm-setup-depencenciess | ||
| id: wasm-setup-dependencies | ||
| title: Setup & Dependencies | ||
| sidebar_position: 2 | ||
| --- | ||
|
|
||
| import Tabs from '@theme/Tabs'; | ||
| import TabItem from '@theme/TabItem'; | ||
|
|
||
| # Prerequisites | ||
|
|
||
| To build the WASM modules you will need a working Emscripten toolchain (emsdk) available on your `PATH` and a Unix-y shell environment (bash / WSL / macOS). Steps in brief: | ||
| ### Frontend-Only Development | ||
|
|
||
|
Ryan-Millard marked this conversation as resolved.
Resolved
|
||
| If you are working on the React/TypeScript frontend, documentation, or any non-WASM features, simply install Node.js and run `npm install` or `pnpm install`. The following npm scripts work cross-platform: | ||
|
|
||
| - **Development**: `dev`, `dev:all`, `preview` | ||
| - **Building**: `build-js` (JavaScript/React build only) | ||
| - **Code Quality**: `lint`, `lint:fix`, `lint:style`, `format`, `format-js`, `format-wasm` | ||
| - **Documentation**: `docs` (all docs scripts) | ||
| - **Utilities**: `help`, `clean-js`, `release` | ||
|
|
||
| ### Full Development (Including WASM) | ||
|
|
||
| WASM development now works natively on **all platforms** including Windows. You need: | ||
|
|
||
| 1. **Node.js** (v18+) | ||
| 2. **CMake** (v3.16+) | ||
| 3. **Emscripten SDK** (emsdk) | ||
|
Ryan-Millard marked this conversation as resolved.
Resolved
|
||
|
|
||
| **WASM scripts** (cross-platform): | ||
|
|
||
| - `build-wasm`, `build-wasm:debug` | ||
| - `clean-wasm` | ||
| - `build`, `clean` (these chain WASM builds) | ||
| - `dev:debug`, `dev:all:debug` | ||
|
|
||
| ## WASM Build Setup | ||
|
|
||
| ### Step 1: Install CMake | ||
|
|
||
| <Tabs groupId="operating-systems" queryString> | ||
| <TabItem value="windows" label="Windows" default> | ||
| ```cmd | ||
| winget install Kitware.CMake | ||
| ``` | ||
| </TabItem> | ||
| <TabItem value="linux" label="Linux"> | ||
| ```bash | ||
| sudo apt install cmake | ||
| ``` | ||
| </TabItem> | ||
| <TabItem value="macos" label="macOS"> | ||
| ```bash | ||
| brew install cmake | ||
| ``` | ||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| ### Step 2: Install Emscripten | ||
|
|
||
| ```bash | ||
| # Clone emsdk | ||
| git clone https://github.com/emscripten-core/emsdk.git | ||
| cd emsdk | ||
|
|
||
| # Install and activate latest | ||
| ./emsdk install latest | ||
| ./emsdk activate latest | ||
|
|
||
| 1. Install Emscripten (emsdk) β follow the official Emscripten docs for your OS. | ||
| 2. Activate emsdk and ensure `emcc`/`em++` are available in the shell used by `npm`/`make`. | ||
| 3. Optionally install `clang-format` and `cmake` if module Makefiles rely on them. | ||
|
|
||
| ``` | ||
|
|
||
| <Tabs groupId="operating-systems" queryString> | ||
| <TabItem value="windows" label="Windows" default> | ||
| ```cmd title="CMD" | ||
| emsdk_env.bat | ||
| ``` | ||
| ```PowerShell title="PowerShell" | ||
| ./emsdk_env.ps1 | ||
| ``` | ||
| </TabItem> | ||
| <TabItem value="linux" label="Linux"> | ||
| ```bash title="Add to PATH (run this in each new terminal, or add to your shell profile)" | ||
| source ./emsdk_env.sh | ||
| ``` | ||
| </TabItem> | ||
| <TabItem value="macos" label="macOS"> | ||
| ```bash title="Add to PATH (run this in each new terminal, or add to your shell profile)" | ||
| source ./emsdk_env.sh | ||
| ``` | ||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| :::tip | ||
| For Windows development we recommend WSL2 + Ubuntu and activating emsdk inside WSL for consistent results. | ||
| Add the emsdk environment script to your shell profile (`.bashrc`, `.zshrc`, or Windows equivalent) so `emcc` is always available. | ||
| ::: | ||
|
|
||
| :::danger Help Wanted! | ||
| The support for developers on Windows for this repository is not great. Thus, we need **your help**! | ||
| [Issue #80](https://github.com/Ryan-Millard/Img2Num/issues/80) is up for grabs for anyone will to take on this task. | ||
| ::: | ||
| ### Step 3: Verify Installation | ||
|
|
||
| ```bash | ||
| cmake --version # Should show 3.16+ | ||
| emcc --version # Should show Emscripten version | ||
| ``` | ||
|
|
||
| ## How package.json ties into builds | ||
|
|
||
| The repo ships npm scripts that call `make` in the `src/wasm` directory. Example snippets from `package.json`: | ||
| The repo ships npm scripts that use a cross-platform Node.js build script with CMake: | ||
|
|
||
| ```json | ||
| "scripts": { | ||
| "build-wasm": "make -C src/wasm build", | ||
| "build-wasm:debug": "make -C src/wasm debug", | ||
| "clean-wasm": "make -C src/wasm clean" | ||
| "build-wasm": "node scripts/build-wasm.js", | ||
| "build-wasm:debug": "node scripts/build-wasm.js --debug", | ||
| "clean-wasm": "node scripts/build-wasm.js --clean" | ||
| } | ||
| ``` | ||
|
|
||
| Use the `npm` scripts when developing locally or in CI; they make the JS side independent from the exact make command. | ||
| The build script: | ||
| 1. Verifies Emscripten is installed | ||
| 2. Runs `emcmake cmake` to configure the build | ||
| 3. Runs `cmake --build` to compile all WASM modules | ||
| 4. Outputs to each module's `build/` directory | ||
|
|
||
| :::note | ||
| Use the `npm` scripts when developing locally or in CI; they abstract away the build system details. | ||
| ::: | ||
|
|
||
| ## Environment variables | ||
|
|
||
| * `NODE_ENV=production` β some parts of `vite.config.js` only trigger a WASM build when building for production; during dev the plugin also triggers builds but only as configured. | ||
| * `EMSDK` / `EMCC` β if you maintain multiple SDK installs, ensure the correct one is on `PATH` when running `npm run build-wasm`. | ||
| - `NODE_ENV=production` β some parts of `vite.config.js` only trigger a WASM build when building for production; during dev the plugin also triggers builds but only as configured. | ||
| - `EMSDK` / `EMCC` β if you maintain multiple SDK installs, ensure the correct one is on `PATH` when running `npm run build-wasm`. | ||
|
|
||
| ## Build System Architecture | ||
|
|
||
| The WASM modules use CMake for cross-platform compatibility: | ||
|
|
||
| ``` | ||
| src/wasm/ | ||
| βββ CMakeLists.txt # Root orchestrator (auto-discovers modules) | ||
| βββ cmake-build/ # CMake build artifacts (gitignored) | ||
| βββ modules/ | ||
| βββ image/ | ||
| βββ CMakeLists.txt # Module build configuration | ||
| βββ src/ # C++ source files | ||
| βββ include/ # Header files | ||
| βββ build/ # Output (index.js + index.wasm) | ||
| ``` | ||
|
Ryan-Millard marked this conversation as resolved.
Resolved
|
||
|
|
||
| This replaces the previous Makefile-based system (before [#93](https://github.com/Ryan-Millard/Img2Num/pull/93)) and works identically on Windows, macOS, and Linux. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.