Skip to content

Commit 241c015

Browse files
zivyArtur-man
andcommitted
Add support for Windows
Add support for building and testing on Windows OS in a consistent manner to Linux and macOS. On Windows, this uses RTools to provide the necessary build tools. Testing is performed in CircleCI as it offers a more powerful build machine under the free plan. Co-authored-by: Artur-man <artur-man@hotmail.com>
1 parent 6a6e48a commit 241c015

5 files changed

Lines changed: 149 additions & 27 deletions

File tree

.circleci/config.yml

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ executors:
1818
environment:
1919
RUNNER_OS: macos
2020
resource_class: m4pro.medium
21+
windows:
22+
machine:
23+
image: windows-server-2022-gui:current
24+
environment:
25+
RUNNER_OS: windows
26+
resource_class: windows.large
2127

2228
jobs:
2329
r-build:
@@ -32,8 +38,12 @@ jobs:
3238
steps:
3339
- checkout
3440
- run:
35-
name: Set environment
41+
name: Set library for default R package installation
3642
command: |
43+
# All packages will be installed into the directory
44+
# referenced by the R_LIBS environment variable.
45+
mkdir -p $HOME/Rlibs
46+
ls -la ${R_LIBS}
3747
echo "export R_LIBS=$HOME/Rlibs" >> $BASH_ENV
3848
- run:
3949
name: Install R << parameters.r-version >>
@@ -44,18 +54,18 @@ jobs:
4454
brew tap r-lib/rig
4555
brew install --cask rig
4656
rig add $R_VERSION
47-
# on macOS the R package is installed into a MAJOR.MINOR directory
48-
# the PATCH is ignored (only one patch version supported) the
49-
# architecture is added as a suffix (arm64, x86_64) to allow for
50-
# installations to coexist
51-
rig default "${R_VERSION%.*}-arm64"
5257
elif [ "$RUNNER_OS" == "linux" ]; then
5358
`which sudo` curl -L https://rig.r-pkg.org/deb/rig.gpg -o /etc/apt/trusted.gpg.d/rig.gpg
5459
`which sudo` sh -c 'echo "deb http://rig.r-pkg.org/deb rig main" > /etc/apt/sources.list.d/rig.list'
5560
`which sudo` apt update
5661
`which sudo` apt install r-rig
5762
sudo rig add $R_VERSION
58-
sudo rig default $R_VERSION
63+
elif [ "$RUNNER_OS" == "windows" ]; then
64+
choco install rig -y
65+
export PATH="$PATH:/c/Program Files/rig"
66+
rig add $R_VERSION
67+
echo "export PATH=\"/c/Program Files/R/R-$R_VERSION/bin:\${PATH}\"" >> $BASH_ENV
68+
echo "export R_HOME=\"/c/Program Files/R/R-$R_VERSION/\"" >> $BASH_ENV
5969
fi
6070
- run:
6171
name: System Dependencies
@@ -66,25 +76,31 @@ jobs:
6676
sudo rm -rf /var/lib/apt/lists/*
6777
elif [ "$RUNNER_OS" == "macos" ]; then
6878
brew install cmake
79+
elif [ "$RUNNER_OS" == "windows" ]; then
80+
choco install rtools -y
81+
echo "RTOOLS_HOME=$(ls -d /c/rtools* | head -n 1)" >> $BASH_ENV
6982
fi
7083
- run:
7184
name: Configuration Information
7285
command: |
73-
mkdir -p ${R_LIBS}
74-
c++ --version
86+
if [ "$RUNNER_OS" == "windows" ]; then
87+
export PATH="${RTOOLS_HOME}/usr/bin:${RTOOLS_HOME}/x86_64-w64-mingw32.static.posix/bin:${R_HOME}/bin:${PATH}"
88+
fi
89+
echo "R_LIBS is: ${R_LIBS}"
90+
c++ --version || gcc --version || echo "no c++ compiler found"
7591
cmake --version || echo "cmake not found"
76-
which R
77-
R --version
92+
make --version || echo "make not found"
93+
R --version || echo "R not found"
7894
- run:
7995
name: Install R packages
8096
command: |
81-
R -e "install.packages(c('remotes'), lib=c('${R_LIBS}'), repo='https://cloud.r-project.org/')"
97+
R -e "install.packages(c('remotes'), repo='https://cloud.r-project.org/')"
8298
- run:
8399
name: Build and test
84100
no_output_timeout: 30m
85101
command: |
86102
set -x
87-
R -e "remotes::install_git(c('.'), lib=c('${R_LIBS}'), configure.vars=c('MAKEJ=3'))"
103+
R -e "remotes::install_git(c('.'), configure.vars=c('MAKEJ=3'))"
88104
89105
workflows:
90106
r-build-test:
@@ -94,7 +110,7 @@ workflows:
94110
matrix:
95111
parameters:
96112
r-version: ['4.3.1', '4.4.1']
97-
os: ["macos-arm"]
113+
os: ["macos-arm", "windows"]
98114
filters:
99115
branches:
100116
only:

DESCRIPTION

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
Package: SimpleITK
2-
Version: 2.0.0
3-
Date: 2020-09-17
4-
Title: Bindings to SimpleITK Image segmentation and registration toolkit
2+
Version: 2.5.3
3+
Date: 2025-11-20
4+
Title: SimpleITK: A Simplified Interface to the Insight Toolkit
55
Authors@R: c(person("Richard", "Beare", role = c("aut", "cre"),
66
email = "Richard.Beare@ieee.org"),
77
person("Bradley", "Lowekamp", role = "aut",
88
email = "blowekamp@mail.nih.gov"),
99
person("Ziv", "Yaniv", role="aut",
10-
email = "zivrafael.yaniv@nih.gov"))
11-
Author: Richard Beare, Bradley Lowekamp, plus loads of others
10+
email = "zivyaniv@nih.gov"))
11+
Author: Richard Beare, Bradley Lowekamp, Ziv Yaniv plus loads of others
1212
Depends: R (>= 3.4)
13-
Imports: methods
13+
Imports: methods,
14+
desc
1415
Description: This package is an interface to SimpleITK, which is a simplified
1516
interface to the Insight Toolkit (ITK) for medical image segmentation
1617
and registration.
1718
License: Apache License 2.0
18-
URL: http://www.simpleitk.org, http://www.itk.org
19-
BugReports: http://issues.itk.org
19+
Note: The first url in the URL field below is the SimpleITK repository, and is used
20+
by the config script under the assumption that it is the first in the list.
21+
URL: https://github.com/SimpleITK/SimpleITK, https://www.simpleitk.org, https://www.itk.org
22+
BugReports: https://github.com/SimpleITK/SimpleITK/issues
2023
Maintainer: Richard Beare <Richard.Beare@ieee.org>

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ Use multicore compilation and build additional modules not included in the defau
2626
remotes::install_github("SimpleITK/SimpleITKRInstaller", configure.vars=c("MAKEJ=6", "ADDITIONAL_SITK_MODULES=-DSimpleITK_USE_ELASTIX=ON\\ -DModule_ITKIODCMTK:BOOL=ON"))
2727
```
2828

29+
Note:
30+
On Linux and Mac requires [CMake](https://cmake.org/) and [git](https://git-scm.com/) in the path.
2931

30-
Requires _cmake_ and _git_ in the path.
31-
32-
Tested on Linux and Mac.
32+
On Windows requires [rtools](https://cran.r-project.org/bin/windows/Rtools/) installation and setting the `RTOOLS_HOME` environment variable. For example:
33+
```R
34+
Sys.setenv(RTOOLS_HOME = "C:/rtools45")
35+
```
3336

3437
# How to Cite
3538

configure

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#
77
# Requires git and cmake
88
#
9-
export SimpleITKGit=https://github.com/SimpleITK/SimpleITK
10-
export SITKTAG=v2.5.3
9+
export SimpleITKGit=$(Rscript -e "d <- desc::desc(file='DESCRIPTION'); urls <- strsplit(d\$get_field('URL'), ',')[[1]]; cat(trimws(urls[1]))")
10+
export SITKTAG=v$(Rscript -e "cat(desc::desc_get_field('Version', file='DESCRIPTION'))")
1111

1212
export PKGBASED=$(pwd)
1313
echo ${PKGBASED}

configure.win

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env sh
2+
set -e
3+
4+
# configure script that will fetch and build SimpleITK, then move the results
5+
# to somewhere that R can install. It takes a long time and uses
6+
# a substantial amount of disk space
7+
#
8+
# Requires rtools (https://cran.r-project.org/bin/windows/Rtools/)
9+
#
10+
11+
# --- Settings ---
12+
# Load shared configuration for all OS (SimpleITK repository URL and tag)
13+
export SimpleITKGit=$(Rscript -e "d <- desc::desc(file='DESCRIPTION'); urls <- strsplit(d\$get_field('URL'), ',')[[1]]; cat(trimws(urls[1]))")
14+
export SITKTAG=v$(Rscript -e "cat(desc::desc_get_field('Version', file='DESCRIPTION'))")
15+
16+
PKGBASED=$(pwd)
17+
echo "$PKGBASED"
18+
19+
# --- Check R_HOME and RTOOLS_HOME---
20+
if [ -z "$R_HOME" ]; then
21+
echo "Environment variable \"R_HOME\" is not set!" 1>&2
22+
exit 1
23+
fi
24+
25+
if [ -z "$RTOOLS_HOME" ]; then
26+
echo "Environment variable \"RTOOLS_HOME\" is not set!" 1>&2
27+
exit 1
28+
fi
29+
30+
export PATH="${RTOOLS_HOME}/usr/bin:${RTOOLS_HOME}/x86_64-w64-mingw32.static.posix/bin:${PATH}"
31+
32+
# Use Rscript on Windows
33+
RCALL="${R_HOME}/bin/Rscript.exe"
34+
export RCALL
35+
36+
# --- Build location: short path to avoid ITK limit ---
37+
BUILDDIR="C:/bld"
38+
echo "Using short build directory: $BUILDDIR"
39+
mkdir -p "$BUILDDIR"
40+
41+
# Pull compiler flags from R (optional but kept for parity)
42+
CC="$("${R_HOME}/bin/R.exe" CMD config CC)"
43+
CXX="$("${R_HOME}/bin/R.exe" CMD config CXX)"
44+
CFLAGS="$("${R_HOME}/bin/R.exe" CMD config CFLAGS)"
45+
CXXFLAGS="$("${R_HOME}/bin/R.exe" CMD config CXX11FLAGS)"
46+
CPPFLAGS="$("${R_HOME}/bin/R.exe" CMD config CPPFLAGS)"
47+
export CC CXX CFLAGS CXXFLAGS CPPFLAGS
48+
49+
# Parallelism (default 1 if not provided)
50+
: "${MAKEJ:=1}"
51+
export MAKEJ
52+
53+
# --- Build in SITK directory ---
54+
(
55+
cd "$BUILDDIR"
56+
57+
if [ ! -d SimpleITK ]; then
58+
git clone "$SimpleITKGit"
59+
cd SimpleITK
60+
git checkout "$SITKTAG"
61+
else
62+
cd SimpleITK
63+
git fetch --tags
64+
git checkout "$SITKTAG"
65+
fi
66+
67+
SITK_SRC="$(pwd)"
68+
69+
mkdir -p ../Build
70+
cd ../Build
71+
72+
echo "Path:"
73+
echo $PWD
74+
75+
# Configure with Unix Makefiles (Rtools toolchain)
76+
cmake -G "Unix Makefiles" \
77+
-DWRAP_DEFAULT=OFF \
78+
-DWRAP_R=ON \
79+
-DSimpleITK_BUILD_DISTRIBUTE=ON \
80+
-DBUILD_EXAMPLES=OFF \
81+
-DBUILD_TESTING=OFF \
82+
-DITK_SKIP_PATH_LENGTH_CHECK=ON \
83+
-DCMAKE_BUILD_TYPE=MinSizeRel \
84+
-DITK_USE_BUILD_DIR:BOOL=ON \
85+
${ADDITIONAL_SITK_MODULES} \
86+
"${BUILDDIR}/SimpleITK/SuperBuild/"
87+
88+
echo "Parallel build using -j${MAKEJ}"
89+
echo $PWD
90+
# Build the specific target with parallel jobs
91+
cmake --build . --target SimpleITK-build -- -j"${MAKEJ}"
92+
93+
# Remove ITK-build to save space (if present)
94+
[ -d ITK-build ] && rm -rf ITK-build
95+
96+
# Move wrapped R package into the package root using R
97+
"${RCALL}" -f "${PKGBASED}/sitkmove.R" --args \
98+
"SimpleITK-build/Wrapping/R/Packaging/SimpleITK" \
99+
"${PKGBASED}"
100+
)

0 commit comments

Comments
 (0)