Skip to content

Fix macOS build: qsort_r, OpenMP, linker flags#27

Merged
koldunovn merged 8 commits intomainfrom
fix/macos-build
Apr 8, 2026
Merged

Fix macOS build: qsort_r, OpenMP, linker flags#27
koldunovn merged 8 commits intomainfrom
fix/macos-build

Conversation

@koldunovn
Copy link
Copy Markdown
Collaborator

Summary

  • Fix qsort_r segfault on macOS — BSD and GNU have different argument order for the comparator and context pointer. Uses #ifdef __APPLE__ to select the correct calling convention
  • Auto-detect OpenMP support — skip -fopenmp when compiler doesn't support it (Apple Clang)
  • Fix --enable-new-dtags — was incorrectly added on Darwin (ifeqifneq), causing linker error
  • Add macOS (macos-latest) to CI workflow matrix with GRIB+Zarr build and tests
  • Add kdtree_qsort_r_large_tree regression test (10k scattered points, verifies sort correctness)

Test plan

  • All 13 default test suites pass on macOS
  • New kdtree_qsort_r_large_tree test passes (16/16 kdtree tests)
  • make WITH_GRIB=1 WITH_ZARR=1 builds cleanly on macOS
  • CI: Linux builds still pass (no regressions)
  • CI: macOS build passes

Three pre-existing bugs that prevented building on macOS:

1. qsort_r has different signatures on BSD (macOS) vs GNU (Linux).
   The comparator and context arguments were swapped, causing a
   segfault in KDTree construction. Use #ifdef __APPLE__ to select
   the correct calling convention.

2. Apple Clang doesn't support -fopenmp. Auto-detect compiler
   support and skip the flag when unavailable.

3. --enable-new-dtags is Linux-only but was being added on Darwin
   due to an inverted ifeq/ifneq condition.

Also adds a qsort_r regression test (10k points) and macOS to the
CI workflow matrix.
Homebrew installs X11 libraries (libxaw, libxt, libx11, etc.) into
per-package prefixes, so pkg-config can't find them without explicit
PKG_CONFIG_PATH. Add a setup step that discovers and exports the paths.

Also install additional X11 dependencies (libx11, libxmu, libxext,
xorgproto) needed for the build.
GITHUB_ENV with PKG_CONFIG_PATH wasn't being picked up by Make's
$(shell pkg-config ...) evaluation. Store the X11 paths in a custom
env var (X11_PKG_CONFIG_PATH) and export PKG_CONFIG_PATH explicitly
in the build and test steps.
Homebrew X11 packages spread headers across per-package prefixes,
making pkg-config discovery unreliable in Make's $(shell ...) context.
XQuartz installs everything to /opt/X11/ which the Makefile already
handles as a built-in fallback path.
XQuartz installs to /opt/X11 but the Makefile's wildcard detection
may not find it. Use the existing X11_PREFIX override to set the path
directly. Added debug ls to verify XQuartz headers are present.
The pattern rule $(OBJDIR)/interface/%.o was shadowed by the more
general $(OBJDIR)/%.o rule because Make's % matches 'interface/x_interface'
in both patterns. Merged into a single rule using $(findstring) to
select X11_FULL_CFLAGS for interface/ files and BASE_CFLAGS for others.

Also restructured X11 detection so X11_PREFIX takes priority over
pkg-config, preventing partial pkg-config results from masking the
explicit path override.
view.c references zarr/grib functions when those features are enabled.
The test Makefile now conditionally links file_zarr.c and file_grib.c
when WITH_ZARR=1 or WITH_GRIB=1 is set.
The test expected variable name "t@surface=0" but the scanner uses
just the shortName "t". Also fixed n_dims assertion: depth dimension
is always added for GRIB variables (even single-level), so n_dims=2
not 1.
@koldunovn koldunovn merged commit 33091d3 into main Apr 8, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant