Commit f252c586

f252c5868029Merged

Yasuhiro Matsumoto <[email protected]> · 7 months ago · 2 files · ~2 modified

Description

feat: build on Windows (MinGW) without ucontext.h / sys/mman.h

Guard POSIX-only headers and replace POSIX runtime primitives with Win32 equivalents so the runtime header compiles and links with MinGW gcc:

  • Fiber runtime: Windows branch uses Win32 Fiber API (CreateFiber / SwitchToFiber / ConvertThreadToFiber / DeleteFiber) in place of ucontext_t + makecontext/swapcontext/setcontext.
  • Lambda arena (sp_lam_alloc): Windows branch uses VirtualAlloc with MEM_RESERVE|MEM_COMMIT; arena sized at 256MB on Windows (16GB on POSIX).
  • malloc_trim(0) is glibc-only; wrapped in !_WIN32.
  • Ship a 64MB stack reserve (-Wl,--stack,67108864) via LDFLAGS on Windows builds to fit the bootstrap compiler's deep AST recursion (MinGW's default 1MB stack overflows otherwise).

Details

Commit
f252c5868029
Parent
e3b80de37fca

MakefilemodifiedView file

@@ -20,6 +20,12 @@
2020 GC_FLAGS = -Wl,--gc-sections
2121 endif
2222
23+# Windows (MinGW) default stack is 1MB — far too small for the deeply
24+# recursive bootstrap compile (~75k frames of AST traversal). Reserve 64MB.
25+ifeq ($(OS),Windows_NT)
26+ LDFLAGS += -Wl,--stack,67108864
27+endif
28+
2329 # Prism library: prefer vendor/prism (fetched via `make deps`), then
2430 # fall back to the Prism gem if one is installed. Override by setting
2531 # PRISM_DIR=/path/to/prism on the command line.
@@ -116,10 +122,10 @@
116122 ./spinel_parse spinel_codegen.rb build/codegen.ast
117123 @echo "=== Bootstrap Step 2: gen1 (CRuby) ==="
118124 ruby spinel_codegen.rb build/codegen.ast build/gen1.c
119- $(CC) $(CFLAGS) -Ilib build/gen1.c -lm -o build/bin1
125+ $(CC) $(CFLAGS) -Ilib build/gen1.c $(LDFLAGS) -lm -o build/bin1
120126 @echo "=== Bootstrap Step 3: gen2 (bin1) ==="
121127 ./build/bin1 build/codegen.ast build/gen2.c
122- $(CC) $(CFLAGS) -Ilib build/gen2.c -lm -o build/bin2
128+ $(CC) $(CFLAGS) -Ilib build/gen2.c $(LDFLAGS) -lm -o build/bin2
123129 @echo "=== Bootstrap Step 4: gen3 (bin2) - verify ==="
124130 ./build/bin2 build/codegen.ast build/gen3.c
125131 @diff build/gen2.c build/gen3.c > /dev/null && echo "gen2.c == gen3.c (bootstrap OK)" || (echo "BOOTSTRAP FAILED: gen2.c != gen3.c" && exit 1)
@@ -134,7 +140,7 @@
134140 bn=$$(basename "$$f" .rb); \
135141 ./spinel_parse "$$f" /tmp/_sp_t.ast 2>/dev/null && \
136142 ./spinel_codegen /tmp/_sp_t.ast /tmp/_sp_t.c 2>/dev/null && \
137- $(CC) $(CFLAGS) -Werror $(SEC_FLAGS) -Ilib /tmp/_sp_t.c $(SP_RT_LIB) -lm $(GC_FLAGS) -o /tmp/_sp_t_bin 2>/dev/null; \
143+ $(CC) $(CFLAGS) -Werror $(SEC_FLAGS) -Ilib /tmp/_sp_t.c $(SP_RT_LIB) $(LDFLAGS) -lm $(GC_FLAGS) -o /tmp/_sp_t_bin 2>/dev/null; \
138144 if [ $$? -eq 0 ]; then \
139145 expected=$$(timeout 10 ruby "$$f" 2>/dev/null); \
140146 actual=$$(timeout 10 /tmp/_sp_t_bin 2>/dev/null); \
@@ -157,7 +163,7 @@
157163 bn=$$(basename "$$f" .rb); \
158164 timeout 10 ./spinel_parse "$$f" /tmp/_sp_b.ast 2>/dev/null && \
159165 timeout 10 ./spinel_codegen /tmp/_sp_b.ast /tmp/_sp_b.c 2>/dev/null && \
160- $(CC) $(CFLAGS) -Werror $(SEC_FLAGS) -Ilib /tmp/_sp_b.c $(SP_RT_LIB) -lm $(GC_FLAGS) -o /tmp/_sp_b_bin 2>/dev/null; \
166+ $(CC) $(CFLAGS) -Werror $(SEC_FLAGS) -Ilib /tmp/_sp_b.c $(SP_RT_LIB) $(LDFLAGS) -lm $(GC_FLAGS) -o /tmp/_sp_b_bin 2>/dev/null; \
161167 if [ $$? -eq 0 ]; then \
162168 expected=$$(timeout 60 ruby "$$f" 2>/dev/null); \
163169 ruby_rc=$$?; \