Skip to content
Draft
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
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Build and Test

on:
push:
branches: [ main ]
branches: [ master ]
pull_request:
branches: [ main ]
branches: [ master ]

jobs:
build:
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
shell_tests: "ON"

- name: rel-clang-macos
os: macos-11
os: macos-latest
compiler: clang
scanbuild: ""
cflags: "-O3 -Wall -Wextra -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wno-deprecated -Wwrite-strings"
Expand All @@ -86,7 +86,7 @@ jobs:
AGENT_BUILDDIRECTORY: ${{ github.workspace }}/NIFTIworkspace
BUILD_SOURCESDIRECTORY: ${{ github.workspace }}
SYSTEM_PULLREQUEST_SOURCEBRANCH: ${{ github.head_ref }}
BUILD_SOURCEBRANCHNAME: ${{ github.head_ref }}
BUILD_SOURCEBRANCHNAME: ${{ github.head_ref || github.ref_name }}
BUILD_BUILDID: ${{ github.run_id }}
SYSTEM_PULLREQUEST_PULLREQUESTNUMBER: ${{ github.event.pull_request.number }}
CTEST_SCRIPT_DIRECTORY: ${{ github.workspace }}/cmake
Expand Down Expand Up @@ -131,5 +131,5 @@ jobs:

- name: Run CTest
run: |
eval $SCANBUILD_EXE ctest -S ${CTEST_SCRIPT_DIRECTORY}/travis_dashboard.cmake -V -j 4
eval $SCANBUILD_EXE ctest -S ${CTEST_SCRIPT_DIRECTORY}/github_dashboard.cmake -V -j 4

131 changes: 106 additions & 25 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
# Per-PR build and test matrix.
#
# Axes and why each one is here:
#
# os / c_compiler GNU, Clang and AppleClang. macOS has no gcc entry
# because /usr/bin/gcc there is a clang shim that
# reports AppleClang, so a macos+gcc leg duplicates
# the macos+clang leg exactly.
# shared BUILD_SHARED_LIBS also gates TEST_INSTALL, so the
# ON legs are the only ones that run install_linking
# and therefore the only ones covering the install
# and export path.
# fslstyle -DFSLSTYLE is not additive. It rewrites behaviour
# in niftilib and nifti2 through global -DFSLSTYLE,
# -DPIGZ and -DREJECT_COMPLEX definitions, and one of
# them has an #else that changes the pixdim[0] value
# written to disk (nifti1_io.c). Both values are
# real configurations and neither subsumes the other.
# build_type Debug turns assert() from a no-op into an abort,
# and the library has live assert() sites. One
# static Debug leg carries this; Debug is not a
# second pass over the other axes.
#
# The optional libraries (cifti, fsliolib) are built everywhere rather
# than being an axis of their own; they are additive, so ON covers OFF.
# The minimal-configuration job below covers the other direction.

name: CMake on multiple platforms

on:
Expand All @@ -10,65 +35,73 @@ on:

jobs:
build:
name: ${{ matrix.os }} ${{ matrix.c_compiler }} ${{ matrix.build_type }} shared=${{ matrix.shared }} fslstyle=${{ matrix.fslstyle }}
runs-on: ${{ matrix.os }}

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false

# Set up a matrix to run the following 3 configurations:
# 1. <Windows, Release, latest MSVC compiler toolchain on the default runner image, default generator>
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
# 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator>
#
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
os: [ubuntu-latest, macos-latest]
build_type: [Release]
c_compiler: [gcc, clang]
build_type: [Release]
shared: ["OFF", "ON"]
fslstyle: ["OFF", "ON"]
include:
- os: macos-latest
c_compiler: clang
cpp_compiler: clang++
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: macos-latest
c_compiler: clang
cpp_compiler: clang++
# One Debug leg, static. Debug exists to make assert()
# live, not to re-cover the linkage or platform axes, so a
# single configuration carries it. FSLSTYLE is ON so the
# assert() sites behind those defines are reachable too.
- os: ubuntu-latest
c_compiler: cl
c_compiler: gcc
cpp_compiler: g++
build_type: Debug
shared: "OFF"
fslstyle: "ON"
exclude:
# /usr/bin/gcc on macOS is a clang shim; this leg would be an
# exact duplicate of the macos clang leg.
- os: macos-latest
c_compiler: gcc

steps:
- uses: actions/checkout@v4

- name: Install optional dependencies
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libexpat1-dev zlib1g-dev

- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
run: echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DBUILD_SHARED_LIBS=${{ matrix.shared }}
-DUSE_CIFTI_CODE=ON
-DUSE_FSL_CODE=ON
-DFSLSTYLE=${{ matrix.fslstyle }}
-S ${{ github.workspace }}

- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }}
run: ctest --build-config ${{ matrix.build_type }} --output-on-failure

minimal:
# The configuration a downstream project vendoring only the core
Expand Down Expand Up @@ -188,3 +221,51 @@ jobs:
-S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ github.workspace }}/build

windows:
# Twelve source files carry WIN32 or _MSC_VER guards and nothing has
# compiled them for as long as the workflows have existed, so a change
# that breaks the Windows path is invisible until a consumer reports
# it. zlib comes from vcpkg because the project requires it.
name: windows-latest msvc ${{ matrix.linkage }} (FSLSTYLE=${{ matrix.fslstyle }})
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
include:
- linkage: static
shared: "OFF"
fslstyle: "OFF"
triplet: x64-windows-static
- linkage: shared
shared: "ON"
fslstyle: "ON"
triplet: x64-windows
steps:
- uses: actions/checkout@v4
- name: Install zlib and expat
run: vcpkg install zlib:${{ matrix.triplet }} expat:${{ matrix.triplet }}
- name: Configure CMake
shell: pwsh
run: |
$toolchain = Join-Path $env:VCPKG_INSTALLATION_ROOT 'scripts/buildsystems/vcpkg.cmake'
Write-Host "vcpkg toolchain: $toolchain"
if (-not (Test-Path $toolchain)) { throw "toolchain file not found: $toolchain" }
cmake -B "${{ github.workspace }}/build" `
-DCMAKE_TOOLCHAIN_FILE="$toolchain" `
-DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }} `
-DBUILD_SHARED_LIBS=${{ matrix.shared }} `
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY="${{ github.workspace }}/build/bin" `

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Google Carbon] Two suggestions on the Windows CMake configuration:

  1. Instead of passing -DCMAKE_RUNTIME_OUTPUT_DIRECTORY only in CI YAML, set a WIN32 default in root CMakeLists.txt (before add_subdirectory, if not already defined by the caller) so local Windows BUILD_SHARED_LIBS=ON builds also place .dll and .exe artifacts together for ctest.
  2. Line 235 notes that twelve source files carry WIN32 or _MSC_VER guards, yet all #ifdef _MSC_VER (_popen/_pclose) blocks in nifti1_io.c & nifti2_io.c require -DFSLSTYLE=ON (PIGZ), and fsliolib's FSL_API DLL exports require -DUSE_FSL_CODE=ON. Please add -DUSE_FSL_CODE=ON (and -DFSLSTYLE=ON on at least one leg) so those Windows guards are actually compiled! (Enabling GitHub Actions binary caching for vcpkg install on line 254 will also save ~2–4 minutes per run.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Point 2 is in 06026f2: both legs now build fsliolib with -DUSE_FSL_CODE=ON, and the shared leg sets -DFSLSTYLE=ON; this is unverified until the workflow runs, since this PR's base is not master. Point 1 changes the default build layout for every Windows consumer of the root CMakeLists.txt, so I have left it for a maintainer decision rather than folding it in here.

-DNIFTI_BUILD_APPLICATIONS=ON `
-DUSE_NIFTI2_CODE=ON `
-DUSE_CIFTI_CODE=ON `
-DUSE_FSL_CODE=ON `
-DFSLSTYLE=${{ matrix.fslstyle }} `
-S "${{ github.workspace }}"
- name: Build
run: cmake --build ${{ github.workspace }}/build --config Release
- name: Test
working-directory: ${{ github.workspace }}/build
# A test that cannot find a DLL can raise a modal dialog and block the
# runner rather than exit, so every test carries a timeout.
run: ctest --build-config Release --output-on-failure --no-tests=error --timeout 120
66 changes: 46 additions & 20 deletions cifti/afni_xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,62 @@ typedef struct {
} afni_xml_control;


#ifndef CIF_API
Comment thread
hjmjohnson marked this conversation as resolved.
Resolved
#if defined(_WIN32) || defined(__CYGWIN__)
#if defined(CIFTI_BUILD_SHARED)
#ifdef __GNUC__
#define CIF_API __attribute__ ((dllexport))
#else
#define CIF_API __declspec( dllexport )
#endif
#elif defined(CIFTI_USE_SHARED)
#ifdef __GNUC__
#define CIF_API __attribute__ ((dllimport))
#else
#define CIF_API __declspec( dllimport )
#endif
#else
#define CIF_API
#endif
#elif (defined(__GNUC__) && __GNUC__ >= 4) || defined(__clang__)
#define CIF_API __attribute__ ((visibility ("default")))
#else
#define CIF_API
#endif
#endif

/* --------------------------- prototypes --------------------------------- */

/* main interface */
afni_xml_list axml_read_buf (const char * buf_in, int64_t bin_len);
afni_xml_list axml_read_file(const char * fname, int read_data);
CIF_API afni_xml_list axml_read_buf (const char * buf_in, int64_t bin_len);
CIF_API afni_xml_list axml_read_file(const char * fname, int read_data);

int axml_disp_xlist( const char *mesg, afni_xml_list * axlist, int verb);
int axml_disp_xml_t( const char *mesg, afni_xml_t * ax, int indent, int verb);
CIF_API int axml_disp_xlist( const char *mesg, afni_xml_list * axlist, int verb);
CIF_API int axml_disp_xml_t( const char *mesg, afni_xml_t * ax, int indent, int verb);


/* create/free */
afni_xml_t * new_afni_xml (const char * name);
int axml_add_attrs (afni_xml_t * ax, const char ** attr);
int axml_free_xml_t(afni_xml_t * ax);
int axml_free_xlist(afni_xml_list * axlist);
CIF_API afni_xml_t * new_afni_xml (const char * name);
CIF_API int axml_add_attrs (afni_xml_t * ax, const char ** attr);
CIF_API int axml_free_xml_t(afni_xml_t * ax);
CIF_API int axml_free_xlist(afni_xml_list * axlist);

char * axml_attr_value(afni_xml_t * ax, const char * name);
int axml_recur(int(*func)(FILE*,afni_xml_t*,int), afni_xml_t * ax);
CIF_API char * axml_attr_value(afni_xml_t * ax, const char * name);
CIF_API int axml_recur(int(*func)(FILE*,afni_xml_t*,int), afni_xml_t * ax);
CIF_API afni_xml_t * axml_recur_find_xml(int (*func)(afni_xml_t *, int), afni_xml_t * ax,
int depth, int max_depth);


/* control API */
int axml_set_verb ( int val );
int axml_get_verb ( void );
int axml_set_dstore ( int val );
int axml_get_dstore ( void );
int axml_set_indent ( int val );
int axml_get_indent ( void );
int axml_set_buf_size ( int val );
int axml_get_buf_size ( void );
int axml_set_wstream ( FILE *fp );
FILE * axml_get_wstream ( void );
CIF_API int axml_set_verb ( int val );
CIF_API int axml_get_verb ( void );
CIF_API int axml_set_dstore ( int val );
CIF_API int axml_get_dstore ( void );
CIF_API int axml_set_indent ( int val );
CIF_API int axml_get_indent ( void );
CIF_API int axml_set_buf_size ( int val );
CIF_API int axml_get_buf_size ( void );
CIF_API int axml_set_wstream ( FILE *fp );
CIF_API FILE * axml_get_wstream ( void );

#endif /* AFNI_XML_H */
23 changes: 0 additions & 23 deletions cifti/afni_xml_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,6 @@
- convert as in SUMA_Create_Fake_CIFTI()
* ----------------------------------------------------------------------*/

#ifndef CIF_API
#if defined(_WIN32) || defined(__CYGWIN__)
#if defined(CIFTI_BUILD_SHARED)
#ifdef __GNUC__
#define CIF_API __attribute__ ((dllexport))
#else
#define CIF_API __declspec( dllexport )
#endif
#elif defined(CIFTI_USE_SHARED)
#ifdef __GNUC__
#define CIF_API __attribute__ ((dllimport))
#else
#define CIF_API __declspec( dllimport )
#endif
#else
#define CIF_API
#endif
#elif (defined(__GNUC__) && __GNUC__ >= 4) || defined(__clang__)
#define CIF_API __attribute__ ((visibility ("default")))
#else
#define CIF_API
#endif
#endif

/* --------------------------- structures --------------------------------- */

Expand Down
60 changes: 60 additions & 0 deletions cmake/collect_exported_symbols.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh
# Collect the dynamic symbols exported by the built shared libraries.
#
# collect_exported_symbols.sh <build-dir> <output-file>
#
# The output is sorted "<library> <symbol>" lines, so a diff against the
# committed baseline names both the library and the symbol that moved.
#
# The library name is reported with any version suffix stripped, so a
# SOVERSION bump does not rewrite every line of the baseline:
# libniftiio.so.3.0.0 is reported as libniftiio.so.
#
# Regenerate the baseline after an intended ABI change:
# cmake -B build -DBUILD_SHARED_LIBS=ON -DUSE_CIFTI_CODE=ON -DUSE_FSL_CODE=ON
# cmake --build build
# sh cmake/collect_exported_symbols.sh build cmake/exported_symbols_linux.txt

set -eu

if [ $# -ne 2 ]; then
echo "usage: $0 <build-dir> <output-file>" >&2
exit 2
fi

build_dir=$1
output=$2

if [ ! -d "$build_dir" ]; then
echo "$0: no such build directory: $build_dir" >&2
exit 1
fi

# Match versioned sonames too (libfoo.so.3.0.0), and resolve symlinks so
# libfoo.so -> libfoo.so.3.0.0 is not counted twice.
libs=$(find "$build_dir" -name 'lib*.so*' -exec readlink -f {} \; \
| LC_ALL=C sort -u)

if [ -z "$libs" ]; then
echo "$0: no shared libraries under $build_dir;" \
"configure with -DBUILD_SHARED_LIBS=ON" >&2
exit 1
fi

: > "$output.tmp"

for lib in $libs; do
# libniftiio.so.3.0.0 -> libniftiio.so
name=$(basename "$lib" | sed -E 's/\.so(\.[0-9]+)*$/.so/')
# -D dynamic symbols, --defined-only drops imports; field 3 is the name.
nm -D --defined-only "$lib" \
| awk 'NF >= 3 { print $3 }' \
| grep -v '^$' \
| sed "s|^|$name |" >> "$output.tmp"
done

LC_ALL=C sort -u "$output.tmp" > "$output"
rm -f "$output.tmp"

echo "$0: wrote $(wc -l < "$output") symbols from" \
"$(awk '{print $1}' "$output" | LC_ALL=C sort -u | wc -l) libraries to $output"
Loading