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
# Per-function sections allow the linker to strip unused bigint/regexp# functions from the final binary (supported since GCC 2.7 / binutils 2.17).SEC_FLAGS = -ffunction-sections -fdata-sectionsGC_FLAGS = -Wl,--gc-sections# Apple ld64 spells dead-code stripping --dead_strip; GNU ld uses --gc-sections.ifeq ($(shell uname -s),Darwin) GC_FLAGS = -Wl,-dead_stripelse GC_FLAGS = -Wl,--gc-sectionsendif# Prism library: prefer vendor/prism (fetched via `make deps`), then# fall back to the Prism gem if one is installed. Override by settinglib/sp_runtime.hmodifiedView file
Loading diff…
spinelmodifiedView file
Loading diff…
spinel_codegen.rbmodifiedView file
Loading diff…