@@ -26,16 +26,15 @@ BOOST_CANDIDATES = $(foreach d,$(shell brew --prefix boost 2>/dev/null) \
2626 /opt/homebrew/opt/boost /usr/local/opt/boost /usr/local /usr,$(d ) /include)
2727BOOST_INCLUDE ?= $(firstword $(foreach d,$(BOOST_CANDIDATES ) ,$(if $(wildcard $(d ) /boost/version.hpp) ,$(d ) ) ) /usr/include)
2828
29- ALLTARGETS =cc65 6809tools yasm verilator zmac xasm smlrc nesasm merlin32 c2t makewav fastbasic dasm Silice wiz cc2600 cc7800 nesfab
30- # TODO: add sdcc when wasmtime upgraded and more browsers have exception support
29+ ALLTARGETS =cc65 6809tools yasm verilator zmac xasm smlrc nesasm merlin32 c2t makewav fastbasic dasm Silice wiz cc2600 cc7800 nesfab sdcc
3130
3231.PHONY : clean clobber prepare $(ALLTARGETS ) test test.acme test.dasm test.yasm \
3332 test.vasm test.zmac test.naken_asm test.c2t test.makewav test.merlin32 \
3433 test.smlrc test.cc2600 test.cc7800 test.nesfab test.cc65 test.nesasm test.sdcc test.xasm
3534
3635test : test.acme test.dasm test.yasm test.vasm test.zmac test.naken_asm \
3736 test.c2t test.makewav test.merlin32 test.smlrc \
38- test.cc2600 test.cc7800 test.nesfab test.cc65 test.nesasm test.xasm # test.sdcc
37+ test.cc2600 test.cc7800 test.nesfab test.cc65 test.nesasm test.xasm test.sdcc
3938 @echo ' All tests passed.'
4039
4140all : $(ALLTARGETS )
@@ -202,19 +201,24 @@ SDCC_WASI_CONFIG = --host=wasm32-wasi --build=$$(./config.guess) \
202201 --disable-device-lib --disable-packihx --disable-sdcpp \
203202 --disable-sdbinutils --without-ccache ac_cv_header_zlib_h=yes
204203
205- # C++ code throws (wasm EH), sdas uses setjmp (wasm sjlj). The EH feature
206- # flag goes in CPPFLAGS too, since dependency generation runs cpp alone and
207- # setjmp.h #errors without it. sdas Makefiles hardcode LIBS, so the extra
208- # libraries go in LDFLAGS.
209- SDCC_WASI_EH = -mexception-handling -mllvm -wasm-use-legacy-eh=false
204+ # sdas uses setjmp (wasm sjlj). The EH feature flag goes in CPPFLAGS too,
205+ # since dependency generation runs cpp alone and setjmp.h #errors without it.
206+ # sdas Makefiles hardcode LIBS, so the extra libraries go in LDFLAGS.
207+ # sdcc's C++ (Boost.Graph register allocator) never catches anything, so it is
208+ # built with -fno-exceptions and linked against wasi-sdk's non-EH libc++
209+ # (lib/wasm32-wasip1/noeh). That keeps sdcc.wasm free of exnref instructions,
210+ # which Node < 25 only accepts behind --experimental-wasm-exnref.
211+ # BOOST_NO_EXCEPTIONS needs boost::throw_exception defined: sdcc-noexc.a provides it.
212+ SDCC_WASI_EH = -mexception-handling -mllvm -wasm-use-legacy-eh=true
213+ SDCC_NOEXC_LIB = $(BUILDDIR ) /sdcc-noexc.a
210214SDCC_WASI_ENV = \
211215 CC="$(WASI_CC ) $(WASI_CFLAGS ) " CXX="$(WASI_CC ) ++ $(WASI_CFLAGS ) " \
212216 AR=$(WASI_SDK ) /bin/llvm-ar RANLIB=$(WASI_SDK ) /bin/llvm-ranlib \
213217 STRIP=$(WASI_STRIP ) \
214218 CPPFLAGS="-mexception-handling -D_GNU_SOURCE -D_WASI_EMULATED_GETPID -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_PROCESS_CLOCKS -idirafter $(BOOST_INCLUDE ) " \
215219 CFLAGS="-O2 -mllvm -wasm-enable-sjlj $(SDCC_WASI_EH ) " \
216- CXXFLAGS="-O2 -fwasm -exceptions $( SDCC_WASI_EH ) " \
217- LDFLAGS="-fwasm-exceptions -Wl,-z,stack-size=8388608 -lsetjmp -lunwind -lwasi-emulated-getpid -lwasi-emulated-signal -lwasi-emulated-process-clocks"
220+ CXXFLAGS="-O2 -fno -exceptions -DBOOST_NO_EXCEPTIONS " \
221+ LDFLAGS="$( SDCC_NOEXC_LIB ) -Wl,-z,stack-size=8388608 -lsetjmp -lwasi-emulated-getpid -lwasi-emulated-signal -lwasi-emulated-process-clocks"
218222
219223# sdld picks its target from argv[0] (sdldz80, sdldgb, sdld6808 for 6502),
220224# so it ships under each name.
@@ -242,7 +246,12 @@ sdcc.native: copy.sdcc
242246 cp -rp $(BUILDDIR ) /sdcc/device/lib/build/* $(BUILDDIR ) /sdcc/fsroot/share/sdcc/lib/
243247 touch $@
244248
245- sdcc.wasi : copy.sdcc patches/sdcc-wasi.patch $(MAKEFILE_LIST )
249+ $(SDCC_NOEXC_LIB ) : patches/sdcc-noexc.cc prepare
250+ @mkdir -p $(BUILDDIR )
251+ $(WASI_CC ) ++ $(WASI_CFLAGS ) -O2 -fno-exceptions -DBOOST_NO_EXCEPTIONS -idirafter $(BOOST_INCLUDE ) -c $< -o $(BUILDDIR ) /sdcc-noexc.o
252+ rm -f $@ && $(WASI_SDK ) /bin/llvm-ar rc $@ $(BUILDDIR ) /sdcc-noexc.o
253+
254+ sdcc.wasi : copy.sdcc patches/sdcc-wasi.patch $(SDCC_NOEXC_LIB ) $(MAKEFILE_LIST )
246255 rm -rf $(BUILDDIR ) /sdcc-wasi && mkdir -p $(BUILDDIR ) /sdcc-wasi
247256 git -C sdcc archive HEAD | tar x -C $(BUILDDIR ) /sdcc-wasi
248257 cd $(BUILDDIR ) /sdcc-wasi && patch -p1 < $(CURDIR ) /patches/sdcc-wasi.patch
0 commit comments