Skip to content

Mac: openzgy fails to compile (strerror_r signature + missing omp.h) #14044

@magnesj

Description

@magnesj

Problem

On macOS (Homebrew llvm@19, x86_64), the vendored ThirdParty/openzgy
library fails to compile with two errors:

  1. open-zgy/native/src/exception.cpp:60 — the #else branch assumes the
    glibc signature for strerror_r (returns char*), but Apple's libc
    returns int:
    char *e = strerror_r(system_errno, buf, sizeof(buf)-1);
             ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. open-zgy/native/src/impl/bulk.cpp:149#include <omp.h> fails
    because Homebrew llvm@19 doesn't ship libomp and
    ThirdParty/openzgy/CMakeLists.txt calls find_package(OpenMP) only as
    optional, so no include path is added. The same unconditional include
    appears in 5 more files (file_sd.cpp, mtguard.cpp, workorder.cpp,
    zgycopyc.cpp, wrappermodule.cpp).

The upstream open-zgy README documents Linux and Windows as the only
supported platforms.

Proposed fix

Adopt the brute-force patch maintained by the cssr-tools/homebrew-opm
tap, vendored as ThirdParty/openzgy/patches/macos-disable-openmp.patch
and applied automatically from ThirdParty/openzgy/CMakeLists.txt when
APPLE is true. The patch:

  • Replaces #include <omp.h> with three inline omp_get_*() stubs
    returning 1/0 in 6 files. Remaining #pragma omp directives become
    no-ops because clang is invoked without -fopenmp on macOS.
  • Rewrites the strerror_r fallback in exception.cpp to use a plain
    \"Unknown errno N\" string.
  • Comments out a BrickIterator bounds-check in edgebrick.h and the
    exception-capture blocks in MTGuard::fail() / WorkOrderTP::fail();
    these depend on OpenMP-driven parallel regions and are unreachable
    with threading disabled.

ThirdParty/openzgy/CMakeLists.txt is updated to:

  • Skip find_package(OpenMP) on APPLE.
  • Apply the patch idempotently via git apply with
    --reverse --check as the "already applied" probe; emit
    FATAL_ERROR with a pointer to the patch file when the source has
    drifted and the patch needs refreshing.

All edits are inside if(APPLE) guards — Linux and Windows configure
paths are byte-identical.

Trade-offs

  • OpenZGY operations on macOS run single-threaded (acceptable functional
    trade-off; performance regression on large ZGY ingest).
  • The disabled bounds-check and fail() blocks should be revisited if
    OpenMP is ever re-enabled on macOS.

Alternative considered

SoilRos/homebrew-OPM ships a minimal patch that only fixes the
preprocessor branch in exception.cpp and relies on Homebrew libomp
being wired into the CMake invocation. Rejected in favour of the
self-contained brute-force approach so the build works without
brew install libomp.

Sources

Verification

  • git apply --check succeeds against the current vendored open-zgy tree
    (commit ea9a1b7d8 Update to latest open-zgy).
  • After applying the patch, exception.cpp, bulk.cpp, mtguard.cpp
    and workorder.cpp compile cleanly with clang++ -std=c++20 -arch x86_64 from Homebrew llvm@19 — no strerror_r or omp.h errors.
  • if(APPLE) guards leave Linux/Windows configure paths unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions