Build ITK Wasm not yet possible from official InsightSoftwareConsortium/ITK trunk?

Hi all,

maybe a question for @matt.mccormick: Is there a reason that compiling ITK for wasm using emscripten is not possible from the main ITK repository InsightSoftwareConsortium/ITK?

There is an ITK-Wasm repository with build scripts, but its environment variables in ITK-Wasm/itk_wasm_env.bash at 60223904ebb3f385c8e572defd5d8f3af97fa28a · InsightSoftwareConsortium/ITK-Wasm point to an ITK branch from May 2024 in a forked Kitware repo and the build scripts additionally contain a few patches.

I think it would greatly simplify building custom Wasm applications that use ITK as static libraries built with emscripten if it would be possible from the main trunk.

Thanks,

Sophonet

Hi @Sophonet ,

I have merged many of the patches for ITK-Wasm into upstream ITK.

Most of the remaining patches were temporary and are related to a lack of threading and related parallelism support in WASI. However, I have been resolving this recently,

They will be removed after support has been finalized.

Best,
Matt

1 Like

Hi @matt.mccormick

This is great news, thanks! So which recent revision from which branch in which repository (upstream vs. kitware) should currently be used for wasm builds?

Also is there a current list of cmake flags that need to be applied? In my recent activities often ITK itself could be built successfully but the final wasm application utilizing ITK as a library could not be linked due to some emscripten error (“attempting to pop from empty stack” or something similar - which is difficult to debug).

Thanks,

Sophonet

Hi @Sophonet ,

It is recommended to use the quay.io/itkwasm/emscripten and quay.io/itkwasm/wasi docker images. These contain pre-built ITK and a CMake toolchain file that specifies all the flags. And other tooling that improves performance and debugging capabilities. Builds can be driven through the itk-wasm npm package.

To get started, follow the create-itk-wasm instructions here.

Hi @matt.mccormick

one more question on this topic. I have built my own ITK WASM based on the flags and revisions in the ITK-Wasm Dockerfile and related environment variables. However, after successfully compiling this for a threading environment (with an additional -pthread compile/link flag), the workers in my app crash on initialization (console shows __emscripten_thread_crashed is not defined. If I remove the ITK dependency, the web app starts (with limited functionality). Likewise, if I remove the thread compile/link flag for everything, the web app starts as well.

Where can I find compile flags or revisions for a thread build of ITK for WASM that does not cause this crash? Or is it something else that my app needs to do in order to fix the problem?

You have mentioned earlier that the quay.io images should be used, but I am a bit lost with respect to tags - is there an image supporting threads?

Thanks,

sophonet

Hi @Sophonet ,

Subscribe to this issue for updates on thread support:

Hi @matt.mccormick,

thanks - this was quick :slightly_smiling_face:. In the meantime I have noticed that my application starts when it has been compiled with -O2 instead of -O3. Likewise it starts when -sASSERTIONS has been set, so this seems to be an emscripten problem?

However it does not use multi-threaded processing functionality so far, so the mismatch between a WorkerPool and pthread has not come up (my application uses pthreads).

Best,

sophonet