Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.circleci/
^.*\.Rproj$
^\.Rproj\.user$
33 changes: 31 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ jobs:
fail-fast: false
matrix:
R: [ '4.3.1', '4.4.1' ]
os: [ 'macos-15-intel', 'ubuntu-latest' ]
os: [ 'macos-15-intel', 'ubuntu-latest', 'windows-latest']
exclude:
- R: '4.3.1'
os: 'windows-latest'
runs-on: ${{ matrix.os }}
name: ${{ matrix.R }} ${{ matrix.os }} build
env:
Expand All @@ -39,18 +42,44 @@ jobs:
sudo apt-get install -y libcurl4-openssl-dev libssh2-1-dev libharfbuzz-dev libfribidi-dev gh &&
sudo rm -rf /var/lib/apt/lists/*
- name: Configuration Information
if: runner.os == 'Linux' || runner.os == 'macOS'
run: |
mkdir ${R_LIBS}
c++ --version
cmake --version
which R
R --version
- name: Configuration Information (Windows)
if: startsWith(matrix.os, 'windows')
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path "$env:R_LIBS" | Out-Null
g++ --version
cmake --version
Get-Command R.exe
R.exe --version
- name: Install R packages
if: runner.os == 'Linux' || runner.os == 'macOS'
run: |
R -e "install.packages(c('remotes'), lib=c('${R_LIBS}'), repos='https://cloud.r-project.org/')"
- name: Install R packages (Windows)
if: startsWith(matrix.os, 'windows')
shell: pwsh
run: |
R -e "install.packages(c('remotes'), lib=c('${R_LIBS}'), repo='https://cloud.r-project.org/')"
Rscript -e "lib <- Sys.getenv('R_LIBS'); lib <- normalizePath(lib, winslash='/', mustWork=FALSE); dir.create(lib, recursive=TRUE, showWarnings=FALSE); install.packages('remotes', lib=lib, repos='https://cloud.r-project.org/')"
Rscript.exe -e "install.packages(c('remotes', 'desc'), repos='https://cloud.r-project.org/')"
Comment on lines +69 to +70
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Windows package-install step installs remotes twice and installs desc without targeting the same library path as $env:R_LIBS. This can lead to packages landing in a non-writable default library or not being visible via .libPaths() during the build. Install both remotes and desc once, explicitly into $env:R_LIBS (after normalizing/creating it).

Suggested change
Rscript -e "lib <- Sys.getenv('R_LIBS'); lib <- normalizePath(lib, winslash='/', mustWork=FALSE); dir.create(lib, recursive=TRUE, showWarnings=FALSE); install.packages('remotes', lib=lib, repos='https://cloud.r-project.org/')"
Rscript.exe -e "install.packages(c('remotes', 'desc'), repos='https://cloud.r-project.org/')"
Rscript.exe -e "lib <- Sys.getenv('R_LIBS'); lib <- normalizePath(lib, winslash='/', mustWork=FALSE); dir.create(lib, recursive=TRUE, showWarnings=FALSE); install.packages(c('remotes', 'desc'), lib=lib, repos='https://cloud.r-project.org/')"

Copilot uses AI. Check for mistakes.
- name: Build and test
if: runner.os == 'Linux' || runner.os == 'macOS'
run: |
set -x
R -e "remotes::install_git(c('.'), lib=c('${R_LIBS}'), configure.vars=c('"MAKEJ=2"'))"
env:
ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS: 2
- name: Build and test (Windows)
if: startsWith(matrix.os, 'windows')
shell: pwsh
env:
ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS: 2
run: |
$env:MAKEJ="3"
Rcmd.exe INSTALL --build .
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
*.Rproj
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ Use multicore compilation and build additional modules not included in the defau
remotes::install_github("SimpleITK/SimpleITKRInstaller", configure.vars=c("MAKEJ=6", "ADDITIONAL_SITK_MODULES=-DSimpleITK_USE_ELASTIX=ON\\ -DModule_ITKIODCMTK:BOOL=ON"))
```

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

Requires _cmake_ and _git_ in the path.

Tested on Linux and Mac.
On Windows requires [rtools](https://cran.r-project.org/bin/windows/Rtools/) installation and setting the `RTOOLS_HOME` environment variable. For example:
```R
Sys.setenv(RTOOLS_HOME = "C:/rtools45")
```

# How to Cite

Expand Down
3 changes: 3 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#
export SimpleITKGit=$(Rscript -e "d <- desc::desc(file='DESCRIPTION'); urls <- strsplit(d\$get_field('URL'), ',')[[1]]; cat(trimws(urls[1]))")
export SITKTAG=v$(Rscript -e "cat(desc::desc_get_field('Version', file='DESCRIPTION'))")
# TODO: parse SITKTAG from DESCRIPTION after new release
# export SITKTAG=v$(Rscript -e "cat(desc::desc_get_field('Version', file='DESCRIPTION'))")
export SITKTAG='1899b2'

export PKGBASED=$(pwd)
echo ${PKGBASED}
Expand Down
110 changes: 110 additions & 0 deletions configure.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env sh
set -e

# configure script that will fetch and build SimpleITK, then move the results
# to somewhere that R can install. It takes a long time and uses
# a substantial amount of disk space
#
# Requires rtools (https://cran.r-project.org/bin/windows/Rtools/)
#

# --- Settings ---
# Load shared configuration for all OS (SimpleITK repository URL and tag)
export SimpleITKGit=$(Rscript -e "d <- desc::desc(file='DESCRIPTION'); urls <- strsplit(d\$get_field('URL'), ',')[[1]]; cat(trimws(urls[1]))")
# TODO: parse SITKTAG from DESCRIPTION after new release
# export SITKTAG=v$(Rscript -e "cat(desc::desc_get_field('Version', file='DESCRIPTION'))")
export SITKTAG='1899b2'

PKGBASED=$(pwd)
echo "$PKGBASED"

# --- Check R_HOME and RTOOLS_HOME---
if [ -z "$R_HOME" ]; then
echo "Environment variable \"R_HOME\" is not set!" 1>&2
exit 1
fi

export RTOOLS_HOME="$(ls -d /c/rtools* | head -n 1)"
if [ -z "$RTOOLS_HOME" ]; then
echo "Environment variable \"RTOOLS_HOME\" is not set!" 1>&2
Comment on lines +27 to +29
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script overwrites RTOOLS_HOME by auto-detecting /c/rtools* but then errors with "RTOOLS_HOME is not set". This is contradictory to the README instructions and prevents users from pinning a specific Rtools install. Only auto-detect when RTOOLS_HOME is empty, and improve the error message to reflect what was checked.

Suggested change
export RTOOLS_HOME="$(ls -d /c/rtools* | head -n 1)"
if [ -z "$RTOOLS_HOME" ]; then
echo "Environment variable \"RTOOLS_HOME\" is not set!" 1>&2
if [ -z "$RTOOLS_HOME" ]; then
for rtools_dir in /c/rtools*; do
if [ -d "$rtools_dir" ]; then
export RTOOLS_HOME="$rtools_dir"
break
fi
done
fi
if [ -z "$RTOOLS_HOME" ]; then
echo "Environment variable \"RTOOLS_HOME\" is not set, and no Rtools installation was found under /c/rtools*." 1>&2

Copilot uses AI. Check for mistakes.
exit 1
fi

# Update PATH to include Rtools binaries
export PATH="${RTOOLS_HOME}/usr/bin:${RTOOLS_HOME}/x86_64-w64-mingw32.static.posix/bin:${PATH}"
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PATH entry ${RTOOLS_HOME}/x86_64-w64-mingw32.static.posix/bin does not match the Rtools 4.5 layout suggested in the README (e.g., C:/rtools45 uses ucrt64/bin). As written, this will fail to find the compiler on current Rtools installations. Update the PATH logic to handle the current Rtools directory structure (or detect the correct subdir).

Suggested change
export PATH="${RTOOLS_HOME}/usr/bin:${RTOOLS_HOME}/x86_64-w64-mingw32.static.posix/bin:${PATH}"
if [ -d "${RTOOLS_HOME}/ucrt64/bin" ]; then
RTOOLS_BIN="${RTOOLS_HOME}/ucrt64/bin"
elif [ -d "${RTOOLS_HOME}/x86_64-w64-mingw32.static.posix/bin" ]; then
RTOOLS_BIN="${RTOOLS_HOME}/x86_64-w64-mingw32.static.posix/bin"
elif [ -d "${RTOOLS_HOME}/mingw64/bin" ]; then
RTOOLS_BIN="${RTOOLS_HOME}/mingw64/bin"
else
echo "Could not find an Rtools compiler bin directory under ${RTOOLS_HOME}" 1>&2
exit 1
fi
export PATH="${RTOOLS_HOME}/usr/bin:${RTOOLS_BIN}:${PATH}"

Copilot uses AI. Check for mistakes.

# Use Rscript on Windows
RCALL="${R_HOME}/bin/Rscript.exe"
export RCALL

echo "R_LIBS is: ${R_LIBS}"
c++ --version || gcc --version || echo "no c++ compiler found"
cmake --version || echo "cmake not found"
make --version || echo "make not found"
$RCALL --version || echo "R not found"


# --- Build location: short path to avoid ITK limit ---
BUILDDIR="C:/bld"
echo "Using short build directory: $BUILDDIR"
mkdir -p "$BUILDDIR"

# Pull compiler flags from R (optional but kept for parity)
CC="$("${R_HOME}/bin/R.exe" CMD config CC)"
CXX="$("${R_HOME}/bin/R.exe" CMD config CXX)"
CFLAGS="$("${R_HOME}/bin/R.exe" CMD config CFLAGS)"
CXXFLAGS="$("${R_HOME}/bin/R.exe" CMD config CXX11FLAGS)"
CPPFLAGS="$("${R_HOME}/bin/R.exe" CMD config CPPFLAGS)"
export CC CXX CFLAGS CXXFLAGS CPPFLAGS

# Parallelism (default 1 if not provided)
: "${MAKEJ:=1}"
export MAKEJ

# --- Build in SITK directory ---
(
cd "$BUILDDIR"

if [ ! -d SimpleITK ]; then
git clone "$SimpleITKGit"
cd SimpleITK
git checkout "$SITKTAG"
else
cd SimpleITK
git fetch --tags
git checkout "$SITKTAG"
fi

SITK_SRC="$(pwd)"

mkdir -p ../Build
cd ../Build

echo "Path:"
echo $PWD

# Configure with Unix Makefiles (Rtools toolchain)
cmake -G "Unix Makefiles" \
-DWRAP_DEFAULT=OFF \
-DWRAP_R=ON \
-DSimpleITK_BUILD_DISTRIBUTE=ON \
-DBUILD_EXAMPLES=OFF \
-DBUILD_TESTING=OFF \
-DITK_SKIP_PATH_LENGTH_CHECK=ON \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DITK_USE_BUILD_DIR:BOOL=ON \
${ADDITIONAL_SITK_MODULES} \
"${BUILDDIR}/SimpleITK/SuperBuild/"

echo "Parallel build using -j${MAKEJ}"
echo $PWD
# Build the specific target with parallel jobs
cmake --build . --target SimpleITK-build -- -j"${MAKEJ}"

# Remove ITK-build to save space (if present)
[ -d ITK-build ] && rm -rf ITK-build

# Move wrapped R package into the package root
# TODO: sitkmove.R fails to move for Windows
cp -r SimpleITK-build/Wrapping/R/Packaging/SimpleITK/* "$PKGBASED/."
)
Loading