From f0d18e39501c8ab03d9c004627e77157586dabf9 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Fri, 3 Feb 2023 15:32:48 -0500 Subject: [PATCH 1/2] ENH: Add Emscripten Wasm build configuration Update to the latest itk-wasm add package.json driver. --- .gitignore | 5 +++++ CMakeLists.txt | 7 ++++++- package.json | 16 ++++++++++++++++ {examples => wasm}/CMakeLists.txt | 6 +++--- {examples => wasm}/ITKCleaverWasm.cxx | 6 +++--- 5 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 package.json rename {examples => wasm}/CMakeLists.txt (86%) rename {examples => wasm}/ITKCleaverWasm.cxx (92%) diff --git a/.gitignore b/.gitignore index c2daaba..062d03f 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,8 @@ Cleaver2 examples/.ipynb_checkpoints/ examples/triangle_mesh.vtk + +wasi-build +pnpm-lock.yaml +node_modules/ +emscripten-build/ diff --git a/CMakeLists.txt b/CMakeLists.txt index a261a41..66ab9ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,9 @@ endif() include(FetchContent) set(_itk_build_testing ${BUILD_TESTING}) -#set(BUILD_TESTING OFF) +if(WASI OR EMSCRIPTEN) + set(BUILD_TESTING OFF CACHE BOOL "Build testing code" FORCE) +endif() if (CMAKE_CXX_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-maybe-uninitialized") endif() @@ -42,6 +44,9 @@ if(NOT ITK_SOURCE_DIR) find_package(ITK REQUIRED) list(APPEND CMAKE_MODULE_PATH ${ITK_CMAKE_DIR}) include(ITKModuleExternal) + if(WASI OR EMSCRIPTEN) + add_subdirectory(wasm) + endif() else() set(ITK_DIR ${CMAKE_BINARY_DIR}) itk_module_impl() diff --git a/package.json b/package.json new file mode 100644 index 0000000..2dbaaed --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "itk-cleaver", + "version": "1.0.0", + "description": "npm scripts to generate itk-wasm artifacts.", + "type": "module", + "scripts": { + "build": "npm run build:emscripten && npm run bindgen:typescript", + "build:emscripten": "npx itk-wasm -b emscripten-build build", + "bindgen:typescript": "npx itk-wasm -b emscripten-build bindgen --output-dir wasm/typescript --package-name itk-cleaver --package-description \"The Cleaver multimaterial tetrahedral meshing tool.\" --repository 'https://github.com/SCIInstitute/Cleaver2'", + "clean": "git clean -fdx -e node_modules" + }, + "license": "Apache-2.0", + "devDependencies": { + "itk-wasm": "^1.0.0-b.70" + } +} diff --git a/examples/CMakeLists.txt b/wasm/CMakeLists.txt similarity index 86% rename from examples/CMakeLists.txt rename to wasm/CMakeLists.txt index eb05dd0..efa3845 100644 --- a/examples/CMakeLists.txt +++ b/wasm/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(ITKCleaverWebAssembly) +project(ITKCleaverWasm) set(CMAKE_CXX_STANDARD 17) @@ -25,8 +25,8 @@ find_package(ITK REQUIRED ) include(${ITK_USE_FILE}) -add_executable(ITKCleaverWasm ITKCleaverWasm.cxx) -target_link_libraries(ITKCleaverWasm PUBLIC ${ITK_LIBRARIES}) +add_executable(itk-cleaver ITKCleaverWasm.cxx) +target_link_libraries(itk-cleaver PUBLIC ${ITK_LIBRARIES}) enable_testing() add_test(NAME ITKCleaverWasmLabelImageTest diff --git a/examples/ITKCleaverWasm.cxx b/wasm/ITKCleaverWasm.cxx similarity index 92% rename from examples/ITKCleaverWasm.cxx rename to wasm/ITKCleaverWasm.cxx index 444aab2..95a4275 100644 --- a/examples/ITKCleaverWasm.cxx +++ b/wasm/ITKCleaverWasm.cxx @@ -19,7 +19,7 @@ #include "itkPipeline.h" #include "itkInputImage.h" #include "itkOutputMesh.h" -#include "itkSupportInputImageTypesNoVectorImage.h" +#include "itkSupportInputImageTypes.h" #include "itkMesh.h" template @@ -98,9 +98,9 @@ class PipelineFunctor int main( int argc, char * argv[] ) { - itk::wasm::Pipeline pipeline("Create a multi-material mesh suitable for simulation/modeling from an input label image or indicator function images", argc, argv); + itk::wasm::Pipeline pipeline("itk-cleaver-wasm", "Create a multi-material mesh suitable for simulation/modeling from an input label image or indicator function images", argc, argv); - return itk::wasm::SupportInputImageTypesNoVectorImage Date: Fri, 10 Feb 2023 14:06:03 -0500 Subject: [PATCH 2/2] ENH: Add WebAssembly CI build --- .github/workflows/wasm.yml | 23 +++++++++++++++++++++++ wasm/ITKCleaverWasm.cxx | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/wasm.yml diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml new file mode 100644 index 0000000..2dbd2e2 --- /dev/null +++ b/.github/workflows/wasm.yml @@ -0,0 +1,23 @@ +name: WebAssembly + +on: [push,pull_request] + +jobs: + Build WebAssembly: + name: Build WebAssembly + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: '18' + + - name: Install + run: | + npm install + + - name: Build + run: | + npm run build diff --git a/wasm/ITKCleaverWasm.cxx b/wasm/ITKCleaverWasm.cxx index 95a4275..5ca95a2 100644 --- a/wasm/ITKCleaverWasm.cxx +++ b/wasm/ITKCleaverWasm.cxx @@ -98,7 +98,7 @@ class PipelineFunctor int main( int argc, char * argv[] ) { - itk::wasm::Pipeline pipeline("itk-cleaver-wasm", "Create a multi-material mesh suitable for simulation/modeling from an input label image or indicator function images", argc, argv); + itk::wasm::Pipeline pipeline("itk-cleaver", "Create a multi-material mesh suitable for simulation/modeling from an input label image or indicator function images", argc, argv); return itk::wasm::SupportInputImageTypes