@@ -12,7 +12,7 @@ TARGET_BASE := $(subst .js,,$(TARGET))
1212OS = Emscripten
1313OBJ :=
1414DEFINES := -DRARCH_INTERNAL -DHAVE_MAIN -DEMSCRIPTEN
15- DEFINES += -DHAVE_FILTERS_BUILTIN -DHAVE_ONLINE_UPDATER -DHAVE_UPDATE_ASSETS -DHAVE_UPDATE_CORE_INFO
15+ DEFINES += -DHAVE_FILTERS_BUILTIN -DHAVE_ONLINE_UPDATER -DHAVE_UPDATE_ASSETS -DHAVE_UPDATE_CORE_INFO -DHAVE_STB_VORBIS
1616
1717HAVE_STATESTREAM ?= 1
1818HAVE_PATCH = 1
@@ -26,7 +26,8 @@ HAVE_UPDATE_ASSETS = 1
2626HAVE_ONLINE_UPDATER = 1
2727HAVE_GLSL = 1
2828HAVE_SCREENSHOTS = 1
29- HAVE_REWIND = 1
29+ HAVE_REWIND ?= 1
30+ HAVE_RUNAHEAD ?= 1
3031HAVE_AUDIOMIXER = 1
3132HAVE_CC_RESAMPLER ?= 1
3233HAVE_EGL ?= 0
@@ -51,7 +52,7 @@ HAVE_CHEATS = 1
5152HAVE_IBXM = 1
5253HAVE_CORE_INFO_CACHE = 1
5354HAVE_7ZIP = 1
54- HAVE_BSV_MOVIE = 1
55+ HAVE_BSV_MOVIE ? = 1
5556HAVE_CHD ?= 0
5657HAVE_NETPLAYDISCOVERY ?= 0
5758
@@ -65,39 +66,55 @@ HAVE_AUDIOWORKLET ?= 0
6566# doesn't work on PROXY_TO_PTHREAD
6667HAVE_RWEBAUDIO ?= 1
6768
68- # requires ASYNC or PROXY_TO_PTHREAD
69+ # requires ASYNC or PROXY_TO_PTHREAD. Prefer another driver.
6970HAVE_AL ?= 0
7071
7172# whether the browser thread is allowed to block to wait for audio to play, not CPU usage-friendly!
7273# currently this variable is only used by rwebaudio and audioworklet; openal will never busywait.
7374ALLOW_AUDIO_BUSYWAIT ?= 0
7475
75- # minimal asyncify; better performance than full asyncify,
76- # but sleeping on the main thread is only possible in some places.
76+ # asyncify: enable fibers and sleeping on the browser thread,
77+ # this has a noticeable impact on compile time, output wasm size, and speed.
78+ # see https://emscripten.org/docs/porting/asyncify.html for more info
79+ ASYNC ?= 0
80+
81+ # minimal asyncify: better performance than full asyncify,
82+ # but sleeping on the browser thread is only possible in some places.
7783MIN_ASYNC ?= 0
7884
79- # runs RetroArch on a pthread instead of the browser thread; requires HAVE_THREADS
85+ # JSPI: experimental asyncify alternative, see https://webassembly.org/features/
86+ # currently (emscripten 4.0.15) this requires a patched emscripten toolchain.
87+ JSPI ?= 0
88+
89+ # runs RetroArch on a pthread instead of the browser thread; implies HAVE_THREADS
8090PROXY_TO_PTHREAD ?= 0
8191
8292# recommended FS when using HAVE_THREADS
8393HAVE_WASMFS ?= 0
8494
85- # enables OPFS (origin private file system) and FETCHFS, requires PROXY_TO_PTHREAD
95+ # enables OPFS (origin private file system) and FETCHFS, requires PROXY_TO_PTHREAD or JSPI
8696HAVE_EXTRA_WASMFS ?= 0
8797
98+ # use the closure compiler to further minify output JS
99+ CLOSURE_COMPILER ?= 0
100+
88101# enable javascript filesystem tracking, incompatible with HAVE_WASMFS
89102FS_DEBUG ?= 0
90103
91104# help diagnose GL problems (can cause issues in normal operation)
92105GL_DEBUG ?= 0
93106
94- # does nothing on its own, but automatically selected by some other options
95- WASM_WORKERS = 0
107+ # enable runtime assertions (always enabled in debug builds)
108+ # please use this when testing new emscripten-specific features!
109+ ASSERTIONS ?= 0
96110
97- HAVE_OPENGLES ?= 1
111+ # enable GLES 3.0 (WebGL 2).
112+ # if left disabled, GLES 2.0 (WebGL 1) will be used.
98113HAVE_OPENGLES3 ?= 0
99114
100- ASYNC ?= 0
115+ # does nothing on its own, but automatically selected by some other options
116+ WASM_WORKERS = 0
117+
101118LTO ?= 0
102119PTHREAD_POOL_SIZE ?= 4
103120
@@ -136,7 +153,10 @@ ifeq ($(HAVE_EXTRA_WASMFS), 1)
136153 DEFINES += -DHAVE_EXTRA_WASMFS
137154 override HAVE_WASMFS = 1
138155 ifeq ($(PROXY_TO_PTHREAD), 0)
139- $(error ERROR: HAVE_EXTRA_WASMFS requires PROXY_TO_PTHREAD)
156+ # note: currently HAVE_EXTRA_WASMFS+JSPI requires ASSERTIONS to be turned off
157+ ifeq ($(JSPI), 0)
158+ $(error ERROR: HAVE_EXTRA_WASMFS requires PROXY_TO_PTHREAD or JSPI)
159+ endif
140160 endif
141161endif
142162
@@ -154,6 +174,7 @@ ifeq ($(PROXY_TO_PTHREAD), 1)
154174 override STACK_SIZE = 4194304
155175else ifeq ($(HAVE_AL), 1)
156176 override ASYNC = 1
177+ override MIN_ASYNC = 0
157178endif
158179
159180ifeq ($(HAVE_SDL2), 1)
@@ -167,7 +188,7 @@ LDFLAGS := -L. --no-heap-copy -s STACK_SIZE=$(STACK_SIZE) -s INITIAL_MEMORY=$(IN
167188 -s MODULARIZE=1 -s EXPORT_ES6=1 -s EXPORT_NAME="libretro_$(subst -,_,$(LIBRETRO))" \
168189 -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0 \
169190 -s ENVIRONMENT=web,worker -s WASM_BIGINT=1 \
170- --extern-pre-js emscripten/pre .js \
191+ --extern-pre-js emscripten/extern_pre .js \
171192 --js-library emscripten/library_rwebcam.js \
172193 --js-library emscripten/library_platform_emscripten.js
173194
@@ -181,7 +202,6 @@ endif
181202
182203ifeq ($(GL_DEBUG), 1)
183204 LDFLAGS += -s GL_ASSERTIONS=1 -s GL_DEBUG=1
184- DEFINES += -DHAVE_GL_DEBUG_ES=1
185205endif
186206
187207ifeq ($(FS_DEBUG), 1)
@@ -211,6 +231,7 @@ ifeq ($(HAVE_AL), 1)
211231endif
212232
213233ifeq ($(PROXY_TO_PTHREAD), 1)
234+ else ifeq ($(JSPI), 1)
214235else ifeq ($(ASYNC), 1)
215236else
216237 DEFINES += -DEMSCRIPTEN_AUDIO_EXTERNAL_BLOCK
@@ -245,18 +266,26 @@ ifeq ($(WASM_WORKERS), 1)
245266 LDFLAGS += -s WASM_WORKERS=1
246267endif
247268
248- ifeq ($(ASYNC), 1)
249- DEFINES += -DEMSCRIPTEN_ASYNCIFY -DEMSCRIPTEN_FULL_ASYNCIFY
250- LDFLAGS += -s ASYNCIFY=1 -s ASYNCIFY_STACK_SIZE=8192
251- ifeq ($(DEBUG), 1)
252- #LDFLAGS += -s ASYNCIFY_DEBUG=1 # broken?
253- endif
269+ ifeq ($(JSPI), 1)
270+ CFLAGS += -fwasm-exceptions
271+ DEFINES += -DEMSCRIPTEN_ASYNCIFY -DEMSCRIPTEN_FULL_ASYNCIFY -DEMSCRIPTEN_JSPI
272+ LDFLAGS += -s JSPI=1 -fwasm-exceptions
254273else ifeq ($(MIN_ASYNC), 1)
255274 DEFINES += -DEMSCRIPTEN_ASYNCIFY -DEMSCRIPTEN_MIN_ASYNCIFY
256275 LDFLAGS += -s ASYNCIFY=1 -s ASYNCIFY_STACK_SIZE=8192 -s ASYNCIFY_IGNORE_INDIRECT=1 -s ASYNCIFY_ADD='$(ASYNCIFY_ADD)' -s ASYNCIFY_REMOVE='$(ASYNCIFY_REMOVE)'
257276 ifeq ($(DEBUG), 1)
258277 LDFLAGS += -s ASYNCIFY_ADVISE #-s ASYNCIFY_DEBUG=1
259278 endif
279+ else ifeq ($(ASYNC), 1)
280+ DEFINES += -DEMSCRIPTEN_ASYNCIFY -DEMSCRIPTEN_FULL_ASYNCIFY
281+ LDFLAGS += -s ASYNCIFY=1 -s ASYNCIFY_STACK_SIZE=8192
282+ ifeq ($(DEBUG), 1)
283+ #LDFLAGS += -s ASYNCIFY_DEBUG=1 # broken?
284+ endif
285+ endif
286+
287+ ifeq ($(CLOSURE_COMPILER), 1)
288+ LDFLAGS += --closure 1 --closure-args=--externs=emscripten/closure_externs.js --post-js emscripten/closure_post.js
260289endif
261290
262291include Makefile.common
@@ -281,9 +310,15 @@ ifneq ($(V), 1)
281310endif
282311
283312ifeq ($(DEBUG), 1)
284- LDFLAGS += -O0 -g -gsource-map -s SAFE_HEAP=2 -s STACK_OVERFLOW_CHECK=2 -s ASSERTIONS=1
313+ LDFLAGS += -O0 -g -gsource-map -s STACK_OVERFLOW_CHECK=2
285314 # -O0 in cflags gives "too many locals" errors
286315 CFLAGS += -O1 -g -gsource-map
316+ override ASSERTIONS = 1
317+ # "WASM_WORKERS is not currently compatible with `-fsanitize` tools"
318+ ifeq ($(WASM_WORKERS), 0)
319+ CFLAGS += -fsanitize=undefined
320+ LDFLAGS += -fsanitize=undefined
321+ endif
287322else
288323 LDFLAGS += -O3
289324 # WARNING: some optimizations can break some cores (ex: LTO breaks tyrquake)
@@ -293,6 +328,10 @@ else
293328 CFLAGS += -O3
294329endif
295330
331+ ifneq ($(ASSERTIONS), 0)
332+ LDFLAGS += -s ASSERTIONS=$(ASSERTIONS)
333+ endif
334+
296335CFLAGS += -Wall -I. -Ilibretro-common/include -Ideps/7zip -std=gnu99
297336
298337RARCH_OBJ := $(addprefix $(OBJDIR)/,$(OBJ))
0 commit comments