Skip to content

Commit

Permalink
Merge pull request #1201 from thewtex/native-pixi
Browse files Browse the repository at this point in the history
native pixi
  • Loading branch information
thewtex authored Aug 19, 2024
2 parents 5e8ae1a + 50a8c8e commit 9d2a2c6
Show file tree
Hide file tree
Showing 13 changed files with 3,459 additions and 171 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# GitHub syntax highlighting
pixi.lock linguist-language=YAML linguist-generated=true
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,9 @@ CMakePresets.json

packages/core/typescript/itk-wasm/test/data/cow.iwm
packages/transform-io/typescript/demo-app/
# pixi environments
.pixi
*.egg-info

native/

68 changes: 0 additions & 68 deletions dev-utils/itk-wasm-native-build.sh

This file was deleted.

43 changes: 0 additions & 43 deletions dev-utils/itk-wasm-native-get-source.sh

This file was deleted.

64 changes: 5 additions & 59 deletions docs/development/hacking_itk_wasm.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,66 +36,12 @@ ITK-Wasm's [C++ core](../introduction/parts.md#cxx-core) can be developed with n
2. Build the `WebAssemblyInterface` module from this module against ITK
3. Run the tests

We recommend using the scripts provided in [dev-utils](../../dev-utils/) folder
to [grab the source code](../../dev-utils/itk-wasm-native-get-source.sh) and run [native build commands](../../dev-utils/itk-wasm-native-build.sh).
Note that you will need to include certain CXX compiler flags for the native windows build as shown in the script.
The build script also demonstrates how to native build sub-packages such as @itk-wasm/dicom with additional ITK dependencies turned on.
We recommend using [pixi](https://pixi.sh) with a bash shell (including on Windows).
The steps to build and test the C++ core with a native toolchain are:

From a command line, these steps in brief are:

```sh
# For Windows build (with mingw-bash or git-bash terminal)
export CXXFLAGS="/Zc:__cplusplus /DNOMINMAX"

# Build ITK
git clone https://github.com/InsightSoftwareConsortium/ITK --branch=itkwasm-main-mutable
# cmake -BITK-build -SITK -DBUILD_TESTING=OFF -DModule_MeshToPolyData=ON -DITK_MSVC_STATIC_RUNTIME_LIBRARY=ON
cmake -BITK-build -SITK \
-DBUILD_TESTING=OFF \
-DCMAKE_CXX_STANDARD:STRING=17 \
-DCMAKE_BUILD_TYPE:STRING=Debug \
-DCMAKE_CONFIGURATION_TYPES:STRING=Debug \
-DBUILD_EXAMPLES:BOOL=OFF \
-DBUILD_TESTING:BOOL=OFF \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_STATIC_LIBS=ON \
-DDCMTK_LINK_STATIC=ON \
-DITK_LEGACY_REMOVE:BOOL=ON \
-DITK_BUILD_DEFAULT_MODULES:BOOL=ON \
-DModule_MeshToPolyData=ON \
-DDO_NOT_BUILD_ITK_TEST_DRIVER:BOOL=ON \
-DOPJ_USE_THREAD:BOOL=OFF \
-DDCMTK_WITH_THREADS:BOOL=OFF \
-DDCMTK_BUILD_APPS:BOOL=OFF \
-DNO_FLOAT_EXCEPTIONS:BOOL=ON \
-DITK_MSVC_STATIC_RUNTIME_LIBRARY=ON
cmake --build ITK-build --config Debug -j16

# Build the WebAssemblyInterface module from this module against ITK
git clone https://github.com/InsightSoftwareConsortium/ITK-Wasm
cmake -BITK-Wasm-build \
-SITK-Wasm \
-DBUILD_TESTING=ON \
-DCMAKE_CXX_STANDARD:STRING=20 \
-DCMAKE_BUILD_TYPE:STRING=Debug \
-DCMAKE_CONFIGURATION_TYPES:STRING=Debug \
-DBUILD_SHARED_LIBS=OFF \
-DITK_DIR=$PWD/ITK-build
cmake --build ITK-Wasm-build --config Debug -j16

# Run the tests
ctest --test-dir itk-wasm-build

cmake -Bpackages-dicom \
-SITK-Wasm/packages/dicom \
-DBUILD_TESTING=ON \
-DCMAKE_CXX_STANDARD:STRING=20 \
-DCMAKE_BUILD_TYPE:STRING=Debug \
-DCMAKE_CONFIGURATION_TYPES:STRING=Debug \
-DITK_DIR=$PWD/ITK-build

cmake --build packages-dicom --config Debug -j16
```
1. Install pixi: `curl -fsSL https://pixi.sh/install.sh | bash`
2. Clone [the ITK-Wasm GitHub repository](https://github.com/InsightSoftwareConsortium/ITK-Wasm)
3. Run `pixi run test-itk-wasm`

For additional guidance on C++ development, see the [ITK Software Guide].

Expand Down
30 changes: 30 additions & 0 deletions itk_wasm_env.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

function die() {
echo "$1"
exit 1
}

if [$OSTYPE == "cygwin"] || [$OSTYPE == "msys"] || [$OSTYPE =="win32"]; then
echo "Windows platform detected ... adding \"/Zc:__cplusplus /DNOMINMAX\" to \$CXXFLAGS"
export CXXFLAGS="/Zc:__cplusplus /DNOMINMAX"
fi

export ITK_WASM_DCMTK_REPOSITORY=${ITK_WASM_DCMTK_REPOSITORY:-"https://github.com/InsightSoftwareConsortium/DCMTK"}
export ITK_WASM_DCMTK_GIT_TAG=${ITK_WASM_DCMTK_GIT_TAG:-"fe7cff5de40b67ae0490d476ddf17689c06bcaf4"}

export ITK_WASM_ITK_REPOSITORY=${ITK_WASM_ITK_REPOSITORY:-"https://github.com/KitwareMedical/ITK"}
export ITK_WASM_ITK_BRANCH=${ITK_WASM_ITK_BRANCH:-"itkwasm-2024-05-20-5db055d7ad3b-1"}

export ITK_WASM_NATIVE_WORKSPACE=${ITK_WASM_NATIVE_WORKSPACE:-$(pwd)/native}

export ITK_WASM_ITK_SOURCE_DIR=${ITK_WASM_ITK_SOURCE_DIR:-${ITK_WASM_NATIVE_WORKSPACE}/ITK}
export ITK_WASM_ITK_BUILD_DIR=${ITK_WASM_ITK_BUILD_DIR:-${ITK_WASM_NATIVE_WORKSPACE}/ITK-build}
mkdir -p ${ITK_WASM_ITK_BUILD_DIR} || die "Could not create ITK build directory"


export ITK_WASM_DICOM_TEST_DATA_HASH=${ITK_WASM_DICOM_TEST_DATA_HASH:-$(cat packages/dicom/package.json | jq -e -r '."itk-wasm"."test-data-hash"')}
export ITK_WASM_DICOM_TEST_DATA_URLS=${ITK_WASM_DICOM_TEST_DATA_URLS:-$(cat packages/dicom/package.json | jq -e -r '."itk-wasm"."test-data-urls" | join(" ")')}

export ITK_WASM_MESH_IO_TEST_DATA_HASH=${ITK_WASM_MESH_IO_TEST_DATA_HASH:-$(cat packages/mesh-io/package.json | jq -e -r '."itk-wasm"."test-data-hash"')}
export ITK_WASM_MESH_IO_TEST_DATA_URLS=${ITK_WASM_MESH_IO_TEST_DATA_URLS:-$(cat packages/mesh-io/package.json | jq -e -r '."itk-wasm"."test-data-urls" | join(" ")')}
3 changes: 2 additions & 1 deletion packages/dicom/dcmtk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ include(${ITK_USE_FILE})
add_executable(structured-report-to-text structured-report-to-text.cxx)
target_link_libraries(structured-report-to-text PUBLIC ${ITK_LIBRARIES})

add_executable(apply-presentation-state-to-image apply-presentation-state-to-image.cxx)
add_executable(apply-presentation-state-to-image
apply-presentation-state-to-image.cxx dcostrmb.cc)
target_link_libraries(apply-presentation-state-to-image PUBLIC cpp-base64 ${ITK_LIBRARIES})
#add_test(NAME apply-presentation-state-to-image-test
#COMMAND apply-presentation-state-to-image
Expand Down
118 changes: 118 additions & 0 deletions packages/dicom/dcmtk/dcostrmb.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
*
* Copyright (C) 2002-2023, OFFIS e.V.
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation were developed by
*
* OFFIS e.V.
* R&D Division Health
* Escherweg 2
* D-26121 Oldenburg, Germany
*
*
* Module: dcmdata
*
* Author: Marco Eichelberg
*
* Purpose: DcmOutputBufferStream and related classes,
* implements output to blocks of memory as needed in the dcmnet module.
*
*/

#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dcostrmb.h"
#include "dcmtk/dcmdata/dcerror.h"


DcmBufferConsumer::DcmBufferConsumer(void *buf, offile_off_t bufLen)
: DcmConsumer()
, buffer_(OFstatic_cast(unsigned char *, buf))
, bufSize_(bufLen)
, filled_(0)
, status_(EC_Normal)
{
if (buffer_ == NULL) status_ = EC_IllegalCall;
}

DcmBufferConsumer::~DcmBufferConsumer()
{
}

OFBool DcmBufferConsumer::good() const
{
return status_.good();
}

OFCondition DcmBufferConsumer::status() const
{
return status_;
}

OFBool DcmBufferConsumer::isFlushed() const
{
return (filled_ == 0);
}

offile_off_t DcmBufferConsumer::avail() const
{
return bufSize_ - filled_;
}

offile_off_t DcmBufferConsumer::write(const void *buf, offile_off_t buflen)
{
offile_off_t result = 0;
if (buflen && buf && status_.good())
{
result = bufSize_ - filled_;
if (result > buflen) result = buflen;
memcpy(buffer_+ filled_, buf, OFstatic_cast(size_t, result));
filled_ += result;
}
return result;
}

void DcmBufferConsumer::flush()
{
// nothing to flush
}

void DcmBufferConsumer::flushBuffer(void *& buffer, offile_off_t& length)
{
buffer = buffer_;
length = filled_;
filled_ = 0;
}

offile_off_t DcmBufferConsumer::filled()
{
return filled_;
}

/* ======================================================================= */

DcmOutputBufferStream::DcmOutputBufferStream(void *buf, offile_off_t bufLen)
: DcmOutputStream(&consumer_) // safe because DcmOutputStream only stores pointer
, consumer_(buf, bufLen)
{
}

DcmOutputBufferStream::~DcmOutputBufferStream()
{
#ifdef DEBUG
if (! isFlushed())
{
DCMDATA_WARN("DcmOutputBufferStream: Closing unflushed DcmOutputBufferStream, loss of data!");
}
#endif
}

void DcmOutputBufferStream::flushBuffer(void *& buffer, offile_off_t& length)
{
consumer_.flushBuffer(buffer, length);
}

offile_off_t DcmOutputBufferStream::filled()
{
return consumer_.filled();
}
8 changes: 8 additions & 0 deletions packages/dicom/gdcm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ else()
set(Iconv_BUILD_COMMAND make)
endif()

if(${CMAKE_VERSION} VERSION_LESS 3.24)
set(download_extract_timestamp_flag)
else()
set(download_extract_timestamp_flag
DOWNLOAD_EXTRACT_TIMESTAMP TRUE)
endif()

ExternalProject_Add(${Iconv_LIBRARY}
PREFIX ${Iconv_DIR}
URL "https://bafybeid2yl6aeunciy5rynjmaoxkhhau3jgjpv7x25pylby7hq6n23c57i.ipfs.dweb.link/libiconv-1.16.tar.gz"
Expand All @@ -52,6 +59,7 @@ ExternalProject_Add(${Iconv_LIBRARY}
BUILD_COMMAND ${Iconv_BUILD_COMMAND}
# needed for ninja generator
BUILD_BYPRODUCTS ${Iconv_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}iconv${CMAKE_STATIC_LIBRARY_SUFFIX}
${download_extract_timestamp_flag}
)

add_library(${Iconv} STATIC IMPORTED)
Expand Down
5 changes: 5 additions & 0 deletions packages/dicom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
"description": "scripts to generate @itk-wasm/dicom itk-wasm artifacts.",
"type": "module",
"itk-wasm": {
"test-data-hash": "bafybeicskxufnvuem6342pkfwgeo3siiozgzmfo5f34woge6aptuzuwzzu ",
"test-data-urls": [
"https://github.com/InsightSoftwareConsortium/ITK-Wasm/releases/download/itk-wasm-v1.0.0-b.119/dicom-test-data.tar.gz",
"https://w3s.link/ipfs/bafybeiby67winzvozowf4moqthwunuxxscssitnb6wahxv4ugvfxhu2vki/data.tar.gz"
],
"emscripten-docker-image": "itkwasm/emscripten:latest",
"wasi-docker-image": "itkwasm/wasi:latest",
"typescript-package-name": "@itk-wasm/dicom",
Expand Down
Loading

0 comments on commit 9d2a2c6

Please sign in to comment.