Skip to content

Fix macOS paclet build; make multi-platform build automatic and host-aware#2

Open
sashakolpakov wants to merge 1 commit into
WolframInstitute:masterfrom
sashakolpakov:fix/macos-build-automatic-multiplatform
Open

Fix macOS paclet build; make multi-platform build automatic and host-aware#2
sashakolpakov wants to merge 1 commit into
WolframInstitute:masterfrom
sashakolpakov:fix/macos-build-automatic-multiplatform

Conversation

@sashakolpakov

Copy link
Copy Markdown

Fixes #1.

The bug

On macOS, linking libHypergraphRewriting.dylib failed with undefined WSTP
symbols (_WSNewPacket, _WSNextPacket, _WSPutFunction, _WSPutString).
The Darwin branch of the WSTP block in paclet_source/CMakeLists.txt set
HAVE_WSTP=1 and added the include dir but — unlike the Windows and Linux
branches — never linked the WSTP library. See #1 for the full analysis.

Changes

paclet_source/CMakeLists.txt

  • Darwin branch now links libWSTPi4.a (needs -framework Foundation, already
    present in the Darwin linker block). This is the actual fix for the linker error.
  • WSTP platform selection and PLATFORM_DIR now honour CMAKE_OSX_ARCHITECTURES,
    so a native -arch x86_64 build on Apple silicon links the x86_64 WSTP slice
    and is emitted into MacOSX-x86-64/.

cmake/FindMathematica.cmake

  • Add /Applications/Wolfram.app/Contents (Wolfram 14+ install name) and the
    ~/Applications variant to the macOS search paths — no more manual
    MATHEMATICA_HOME just to be found.

build_all_platforms.sh — rewritten around a declarative target schema

  • Every target declares its toolchain probe, auto-install command, and configure
    line. Missing-but-installable toolchains are installed automatically
    (--no-install to opt out).
  • Targets the host cannot build (e.g. Windows-ARM64, which needs the Windows SDK)
    are skipped with a reason, not fatal. The run only fails on a build that was
    actually attempted. Previously the Windows-ARM64 configure error aborted the
    whole script.
  • On a macOS host, both macOS slices build natively via Apple clang, and
    Linux/Windows targets build via the Homebrew cross-toolchains — OSXCross is no
    longer required for the native arches.
  • Assembles the .paclet archive at the end when all attempted builds succeed.

README.md — corrected build/cross-compilation docs (were Linux-only and
referenced clang-22); documented artifact locations and the host-aware skipping.

.gitignore — ignore the generated paclet_archive/.

Verification (macOS, Apple silicon, Wolfram 14)

./build_all_platforms.sh builds MacOSX-ARM64, MacOSX-x86-64, Linux-x86-64,
Linux-ARM64, Windows-x86-64
, skips Windows-ARM64 with a clear message, and
produces paclet_archive/WolframInstitute__HypergraphRewriteEngine-0.0.1.paclet.
nm -u on the macOS dylib shows no undefined WS* symbols. The x86_64 dylib
reports x86_64 via lipo -archs.

🤖 Generated with Claude Code

…aware

The macOS (Darwin) build of libHypergraphRewriting failed to link:

    Undefined symbols for architecture arm64:
      "_WSNewPacket", "_WSNextPacket", "_WSPutFunction", "_WSPutString"
      referenced from hypergraph_ffi.cpp.o

Root cause: in paclet_source/CMakeLists.txt the WSTP block has three
platform branches. Windows and Linux each link the WSTP library
(wstp64i4.lib / libWSTP64i4.so), but the Darwin branch only defined
HAVE_WSTP=1 and added the include dir -- it never linked libWSTPi4.a.
So hypergraph_ffi.cpp compiled with the WSTP code path enabled but the
symbols were never resolved.

Changes:

* paclet_source/CMakeLists.txt
  - Darwin branch now links libWSTPi4.a (it needs -framework Foundation,
    already added in the Darwin linker block).
  - WSTP platform selection and PLATFORM_DIR now honour
    CMAKE_OSX_ARCHITECTURES, so a native x86_64 build on Apple silicon
    links the x86_64 WSTP slice and lands in MacOSX-x86-64/.

* cmake/FindMathematica.cmake
  - Add /Applications/Wolfram.app/Contents (Wolfram 14+ install name) and
    its ~/Applications equivalent to the macOS search paths, so the kernel
    is found without setting MATHEMATICA_HOME.

* build_all_platforms.sh -- rewritten around a declarative target schema.
  - Each target declares its toolchain probe, auto-install command, and
    configure line. Missing-but-installable toolchains are installed
    automatically (--no-install to opt out).
  - Targets the host architecture cannot build (e.g. Windows-ARM64, which
    needs the Windows SDK) are SKIPPED with a reason instead of aborting
    the whole run. The run only fails on a build that was actually
    attempted. Previously the Windows-ARM64 configure error killed the
    entire script via `set -e` + `|| exit 1`.
  - macOS host now builds both macOS slices natively (Apple clang) and the
    Linux/Windows targets via the brew cross-toolchains -- no OSXCross
    required for the native arches.
  - Assembles the .paclet archive at the end when all attempted builds
    succeed.

* README.md -- corrected the build/cross-compilation docs (was Linux-only,
  referenced clang-22); documented where artifacts land (the
  paclet_archive/*.paclet) and the host-aware skipping behaviour.

* .gitignore -- ignore the generated paclet_archive/.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

macOS build fails: WSTP symbols undefined when linking libHypergraphRewriting.dylib

1 participant