Skip to content

Commit

Permalink
ENH: Add wasm configuration
Browse files Browse the repository at this point in the history
Build javascript, typescript, cli, packages, documentation via ITK-Wasm.

A few tests added for the CLI, javascript, typescript to ensure they
run. Other testing is left to the module.

CI for build/test of everything and build / deploy of the documentation
to GitHub Pages.
  • Loading branch information
thewtex committed Feb 15, 2024
1 parent a31fbf7 commit 50ffe15
Show file tree
Hide file tree
Showing 21 changed files with 3,603 additions and 1 deletion.
101 changes: 101 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Documentation

on:
push:
branches:
- master

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:


# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
build-wasm-documentation:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4

- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main

- uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install
uses: pnpm/action-setup@v2
with:
version: 8
run_install: true

- uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Build
run: |
pnpm build
- name: Build package typescript documentation
run: |
mkdir -p docs/ts/docs
mkdir -p docs//ts/app
sed "s% basePath:.*% basePath: '/ITKMorphologicalContourInterpolation/ts/docs',%" wasm/typescript/index.html > docs/ts/docs/index.html
cp wasm/typescript/README.md docs/ts/docs/
mkdir -p docs/ts/docs/test/browser/demo-app
cp wasm/typescript/test/browser/demo-app/logo.svg docs/ts/docs/test/browser/demo-app/
pushd wasm/typescript
rm -rf demo-app node_modules/.vite
export VITE_BASE_URL="/ITKMorphologicalContourInterpolation/ts/app/"
pnpm build
popd
rsync -a wasm/typescript/demo-app/ docs/ts/app/
- name: Build package python documentation
run: |
mkdir -p docs/py/docs
mkdir -p docs/py/app
export SPHINX_BASE_URL="/ITKMorphologicalContourInterpolation/py/docs/"
pushd wasm/python/itkwasm-morphological-contour-interpolation/docs
pip install -r requirements.txt
make html
popd
rsync -a wasm/python/itkwasm-morphological-contour-interpolation/docs/_build/html/ docs/py/docs/
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs
retention-days: 7

deploy-gh-pages:
needs: build-wasm-documentation
runs-on: ubuntu-22.04

# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
contents: read
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source

# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
# with:
# preview: true <-> currently not available to the public
36 changes: 36 additions & 0 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: WebAssembly

on: [push,pull_request]

jobs:
build-wasm:
name: "Build WebAssembly"
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4

- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main

- uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install
uses: pnpm/action-setup@v2
with:
version: 8
run_install: true

- uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Build
run: |
pnpm build
- name: Test
run: |
pnpm test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@
*.exe
*.out
*.app

# wasm build
node_modules/
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ if(CMAKE_CXX_STANDARD EQUAL "11" )
endif()

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14) # Supported values are ``14``, ``17``, and ``20``.
if (WASI OR EMSCRIPTEN)
set(CMAKE_CXX_STANDARD 20) # Supported values are ``14``, ``17``, and ``20``.
else()
set(CMAKE_CXX_STANDARD 17) # Supported values are ``14``, ``17``, and ``20``.
endif()
endif()
if(NOT CMAKE_CXX_STANDARD_REQUIRED)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -20,6 +24,10 @@ if(NOT ITK_SOURCE_DIR)
find_package(ITK 4.9 REQUIRED)
list(APPEND CMAKE_MODULE_PATH ${ITK_CMAKE_DIR})
include(ITKModuleExternal)
if(WASI OR EMSCRIPTEN)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(wasm)
endif()
else()
set(ITK_DIR ${CMAKE_BINARY_DIR})
itk_module_impl()
Expand Down
10 changes: 10 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: morphological-contour-interpolation
channels:
- conda-forge
dependencies:
- pytest
- python=3.11
- pip
- pip:
- hatch
- itkwasm-image-io
4 changes: 4 additions & 0 deletions include/itkMorphologicalContourInterpolator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -713,13 +713,17 @@ MorphologicalContourInterpolator< TImage >::Interpolate1to1( int axis, TImage* o
}
}

#if !defined(__wasi__) && !defined(__EMSCRIPTEN__)
static std::mutex mutexLock;
#endif
if ( withinReq ) // else we should not write it
{
seqIt.GoToBegin();
// writing through one RLEImage iterator invalidates all the others
// so this whole writing loop needs to be serialized
#if !defined(__wasi__) && !defined(__EMSCRIPTEN__)
std::lock_guard< std::mutex > mutexHolder( mutexLock );
#endif
ImageRegionIterator< TImage > outIt( out, outRegion );
while ( !outIt.IsAtEnd() )
{
Expand Down
45 changes: 45 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "@itk-wasm/morphological-contour-interpolation-build",
"version": "1.0.0",
"description": "npm scripts to generate itk-wasm artifacts.",
"private": true,
"type": "module",
"itk-wasm": {
"typescript-package-name": "@itk-wasm/morphological-contour-interpolation",
"typescript-output-dir": "wasm/typescript",
"python-package-name": "itkwasm-morphological-contour-interpolation",
"python-output-dir": "wasm/python",
"package-description": "Morphology-based approach for interslice interpolation of anatomical slices from volumetric images.",
"repository": "https://github.com/KitwareMedical/ITKMorphologicalContourInterpolation"
},
"scripts": {
"build": "pnpm build:gen:typescript && pnpm -r build && pnpm build:gen:python",
"build:emscripten": "itk-wasm pnpm-script build:emscripten",
"build:emscripten:debug": "itk-wasm pnpm-script build:emscripten:debug",
"build:wasi": "itk-wasm pnpm-script build:wasi",
"build:wasi:debug": "itk-wasm pnpm-script build:wasi:debug",
"build:python:wasi": "itk-wasm pnpm-script build:python:wasi",
"bindgen:typescript": "itk-wasm pnpm-script bindgen:typescript",
"bindgen:python": "itk-wasm pnpm-script bindgen:python",
"build:gen:typescript": "itk-wasm pnpm-script build:gen:typescript",
"build:gen:python": "itk-wasm pnpm-script build:gen:python",
"build:micromamba": "itk-wasm pnpm-script build:micromamba",
"build:python:versionSync": "itk-wasm pnpm-script build:python:versionSync",
"publish:python": "itk-wasm pnpm-script publish:python",
"test": "pnpm test:data:download && pnpm -r test && pnpm test:python",
"test:data:download": "echo \"not needed\"",
"test:data:pack": "dam pack test/data test/data.tar.gz",
"test:python:wasi": "itk-wasm pnpm-script test:python:wasi",
"test:python:emscripten": "itk-wasm pnpm-script test:python:emscripten",
"test:python:dispatch": "itk-wasm pnpm-script test:python:dispatch",
"test:python": "itk-wasm pnpm-script test:python",
"test:wasi": "itk-wasm pnpm-script test:wasi -- -V",
"clean": "git clean -fdx -e node_modules"
},
"license": "Apache-2.0",
"devDependencies": {
"@itk-wasm/dam": "^1.1.0",
"@thewtex/setup-micromamba": "^1.9.7",
"itk-wasm": "^1.0.0-b.166"
}
}
Loading

0 comments on commit 50ffe15

Please sign in to comment.