The Host wrapper has one more rule. On Linux, a debug build compiles backtrace.c, which calls
_Unwind_Backtrace. gcc links its unwinder (libgcc) by itself, but zig cc does not, so a link
step needs zig's bundled -lunwind. macOS has the unwinder in libSystem and needs nothing. The
tool can run on wasm, so the wrapper decides at run time with uname -s. A compile step (-c)
does not link, so it gets no library.
The cc wrapper for MOON_CC: a /bin/sh script that runs zig cc.
A cross build needs two workarounds for upstream bugs in moon and in the MoonBit runtime:
- The runtime file env.c includes <stdlib.h> before it defines _CRT_RAND_S. On Windows
(mingw), rand_s is then not declared and the compile fails. A -D_CRT_RAND_S on the
command line defines it before the first include. The flag does no harm on other targets,
so every wrapper has it. Upstream: https://github.com/moonbitlang/moonbit-native-runtime/issues/2
- moon passes -DMOONBIT_USE_SIMDUTF and links the prebuilt objects moonbit_simdutf.o,
simdutf.o and libbacktrace.a. These objects are built for the machine that runs moon,
not for MOON_CC's target, so the link fails or the binary gets the wrong architecture.
A cross wrapper removes the flag and the three files. The Host wrapper removes nothing.
Upstream: https://github.com/moonbitlang/moon/issues/2320