Commit 0f883a24

0f883a24539aMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 4 files · ~4 modified

Description

feat: macOS support

Spinel previously assumed a glibc + GNU-ld + GCC toolchain. macOS lacks all three — the build broke on header inclusion, linker flags, and nested C functions emitted for procs/lambdas. This commit makes Spinel build and test on Apple platforms with the system clang, no Homebrew GCC required.

Changes:

  • lib/sp_runtime.h: behind APPLE guards, define _XOPEN_SOURCE + _DARWIN_C_SOURCE so ucontext.h exposes getcontext/makecontext, alias MAP_ANONYMOUS to MAP_ANON, skip the glibc-only <malloc.h> include and malloc_trim(0) call in sp_gc_collect.

  • Makefile, spinel: switch GC linker flag to -Wl,-dead_strip on Darwin (ld64 does not understand --gc-sections).

  • spinel_codegen.rb compile_proc_literal: hoist proc bodies to file scope (emitted via @lambda_funcs) instead of using a GCC nested function inside a statement expression. Apple clang rejects both of those GCC extensions. The current compile_proc_literal callers all produce non-capturing procs, so file-scope is sufficient.

The Linux toolchain path is untouched — every change is guarded by APPLE or uname -s = Darwin.

Inspired by ideas from PRs #3 and #6 (rewritten so we ship the codegen-side fix rather than steering users toward Homebrew GCC).

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
0f883a24539a
Parent
66e9388d2e97

MakefilemodifiedView file

@@ -13,7 +13,12 @@
1313 # Per-function sections allow the linker to strip unused bigint/regexp
1414 # functions from the final binary (supported since GCC 2.7 / binutils 2.17).
1515 SEC_FLAGS = -ffunction-sections -fdata-sections
16-GC_FLAGS = -Wl,--gc-sections
16+# Apple ld64 spells dead-code stripping --dead_strip; GNU ld uses --gc-sections.
17+ifeq ($(shell uname -s),Darwin)
18+ GC_FLAGS = -Wl,-dead_strip
19+else
20+ GC_FLAGS = -Wl,--gc-sections
21+endif
1722
1823 # Prism library: prefer vendor/prism (fetched via `make deps`), then
1924 # fall back to the Prism gem if one is installed. Override by setting