Skip to content

Commit 59b2716

Browse files
zivyArtur-man
andcommitted
WIP: Add support for Windows
Add support for building and testing on Windows OS in a consistent manner to Linux and macOS. Repository URL and tag are specified in a shared configuration file (SITK_CONFIG) which is used by both the configure and configure.win scripts. 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 59b2716

File tree

4 files changed

+124
-16
lines changed

4 files changed

+124
-16
lines changed

.circleci/config.yml

Lines changed: 27 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,17 @@ 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
5968
fi
6069
- run:
6170
name: System Dependencies
@@ -66,25 +75,29 @@ jobs:
6675
sudo rm -rf /var/lib/apt/lists/*
6776
elif [ "$RUNNER_OS" == "macos" ]; then
6877
brew install cmake
78+
elif [ "$RUNNER_OS" == "windows" ]; then
79+
choco install rtools -y
80+
RTOOLS_ROOT=$(ls -d /c/rtools* | head -n 1)
81+
echo "export PATH=\"$CMAKE_DIR:$RTOOLS_ROOT/x86_64-w64-mingw32.static.posix/bin:$RTOOLS_ROOT/usr/bin:\$PATH\"" >> $BASH_ENV
6982
fi
7083
- run:
7184
name: Configuration Information
7285
command: |
73-
mkdir -p ${R_LIBS}
74-
c++ --version
86+
echo $PATH
87+
echo "R_LIBS is: ${R_LIBS}"
88+
c++ --version || gcc --version || echo "no c++ compiler found"
7589
cmake --version || echo "cmake not found"
76-
which R
77-
R --version
90+
R --version || echo "R not found"
7891
- run:
7992
name: Install R packages
8093
command: |
81-
R -e "install.packages(c('remotes'), lib=c('${R_LIBS}'), repo='https://cloud.r-project.org/')"
94+
R -e "install.packages(c('remotes'), repo='https://cloud.r-project.org/')"
8295
- run:
8396
name: Build and test
8497
no_output_timeout: 30m
8598
command: |
8699
set -x
87-
R -e "remotes::install_git(c('.'), lib=c('${R_LIBS}'), configure.vars=c('MAKEJ=3'))"
100+
R -e "remotes::install_git(c('.'), configure.vars=c('MAKEJ=3'))"
88101
89102
workflows:
90103
r-build-test:
@@ -94,7 +107,7 @@ workflows:
94107
matrix:
95108
parameters:
96109
r-version: ['4.3.1', '4.4.1']
97-
os: ["macos-arm"]
110+
os: ["macos-arm", "windows"]
98111
filters:
99112
branches:
100113
only:

SITK_CONFIG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SimpleITK configuration shared between configure and configure.win
2+
export SimpleITKGit=https://github.com/SimpleITK/SimpleITK
3+
export SITKTAG=v2.5.3

configure

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#
77
# Requires git and cmake
88
#
9-
export SimpleITKGit=https://github.com/SimpleITK/SimpleITK
10-
export SITKTAG=v2.5.3
9+
10+
# Load shared configuration for all OS (SimpleITKrepository URL and tag)
11+
source "$(dirname "$0")/SITK_CONFIG"
1112

1213
export PKGBASED=$(pwd)
1314
echo ${PKGBASED}

configure.win

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

0 commit comments

Comments
 (0)