diff --git a/ChangeLog.md b/ChangeLog.md index e7c9bf058dc18..f20760ba644e9 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -20,6 +20,10 @@ See docs/process.md for more on how version tagging works. 5.0.3 (in development) ---------------------- +- The `-sUSE_SDL` flag has been required to use SDL headers since #18443. + However, due to an oversight it was still possible to use `SDL/SDL.h` without + the explicit flag. This has now been fixed, which means some SDL users of SDL + may need to `-sUSE_SDL` when upgrading. (#26279) - When building with `-sWASM_WORKERS` emscripten will no longer include pthread API stub functions. These stub functions where never designed to work under Wasm Workers, so its safer to error at link time if pthread APIs are used diff --git a/site/source/docs/tools_reference/settings_reference.rst b/site/source/docs/tools_reference/settings_reference.rst index 61daa3a310311..5652d8ad7b6da 100644 --- a/site/source/docs/tools_reference/settings_reference.rst +++ b/site/source/docs/tools_reference/settings_reference.rst @@ -2140,11 +2140,12 @@ Default value: true USE_SDL ======= -Specify the SDL version that is being linked against. -1, the default, is 1.3, which is implemented in JS -2 is a port of the SDL C code on emscripten-ports -When AUTO_JS_LIBRARIES is set to 0 this defaults to 0 and SDL -is not linked in. +Specify the SDL version that is being linked against: + +- 0, the default, means no SDL headers or libraries will be used. +- 1 is a port of SDL 1.3, implemented in JS. +- 2 and 3 are upstream ports build from the official SDL codebase. + Alternate syntax for using the port: --use-port=sdl2 .. note:: Applicable during both linking and compilation diff --git a/src/settings.js b/src/settings.js index e72e545677a2c..3e500b5f19a10 100644 --- a/src/settings.js +++ b/src/settings.js @@ -1471,11 +1471,12 @@ var LEGALIZE_JS_FFI = true; // Ports -// Specify the SDL version that is being linked against. -// 1, the default, is 1.3, which is implemented in JS -// 2 is a port of the SDL C code on emscripten-ports -// When AUTO_JS_LIBRARIES is set to 0 this defaults to 0 and SDL -// is not linked in. +// Specify the SDL version that is being linked against: +// +// - 0, the default, means no SDL headers or libraries will be used. +// - 1 is a port of SDL 1.3, implemented in JS. +// - 2 and 3 are upstream ports build from the official SDL codebase. +// // Alternate syntax for using the port: --use-port=sdl2 // [compile+link] var USE_SDL = 0; diff --git a/system/include/fakesdl/SDL.h b/system/include/fakesdl/SDL/SDL.h similarity index 100% rename from system/include/fakesdl/SDL.h rename to system/include/fakesdl/SDL/SDL.h diff --git a/system/include/fakesdl/SDL_assert.h b/system/include/fakesdl/SDL/SDL_assert.h similarity index 100% rename from system/include/fakesdl/SDL_assert.h rename to system/include/fakesdl/SDL/SDL_assert.h diff --git a/system/include/fakesdl/SDL_atomic.h b/system/include/fakesdl/SDL/SDL_atomic.h similarity index 100% rename from system/include/fakesdl/SDL_atomic.h rename to system/include/fakesdl/SDL/SDL_atomic.h diff --git a/system/include/fakesdl/SDL_audio.h b/system/include/fakesdl/SDL/SDL_audio.h similarity index 100% rename from system/include/fakesdl/SDL_audio.h rename to system/include/fakesdl/SDL/SDL_audio.h diff --git a/system/include/fakesdl/SDL_blendmode.h b/system/include/fakesdl/SDL/SDL_blendmode.h similarity index 100% rename from system/include/fakesdl/SDL_blendmode.h rename to system/include/fakesdl/SDL/SDL_blendmode.h diff --git a/system/include/fakesdl/SDL_clipboard.h b/system/include/fakesdl/SDL/SDL_clipboard.h similarity index 100% rename from system/include/fakesdl/SDL_clipboard.h rename to system/include/fakesdl/SDL/SDL_clipboard.h diff --git a/system/include/fakesdl/SDL_compat.h b/system/include/fakesdl/SDL/SDL_compat.h similarity index 100% rename from system/include/fakesdl/SDL_compat.h rename to system/include/fakesdl/SDL/SDL_compat.h diff --git a/system/include/fakesdl/SDL_config.h b/system/include/fakesdl/SDL/SDL_config.h similarity index 100% rename from system/include/fakesdl/SDL_config.h rename to system/include/fakesdl/SDL/SDL_config.h diff --git a/system/include/fakesdl/SDL_copying.h b/system/include/fakesdl/SDL/SDL_copying.h similarity index 100% rename from system/include/fakesdl/SDL_copying.h rename to system/include/fakesdl/SDL/SDL_copying.h diff --git a/system/include/fakesdl/SDL_cpuinfo.h b/system/include/fakesdl/SDL/SDL_cpuinfo.h similarity index 100% rename from system/include/fakesdl/SDL_cpuinfo.h rename to system/include/fakesdl/SDL/SDL_cpuinfo.h diff --git a/system/include/fakesdl/SDL_endian.h b/system/include/fakesdl/SDL/SDL_endian.h similarity index 100% rename from system/include/fakesdl/SDL_endian.h rename to system/include/fakesdl/SDL/SDL_endian.h diff --git a/system/include/fakesdl/SDL_error.h b/system/include/fakesdl/SDL/SDL_error.h similarity index 100% rename from system/include/fakesdl/SDL_error.h rename to system/include/fakesdl/SDL/SDL_error.h diff --git a/system/include/fakesdl/SDL_events.h b/system/include/fakesdl/SDL/SDL_events.h similarity index 100% rename from system/include/fakesdl/SDL_events.h rename to system/include/fakesdl/SDL/SDL_events.h diff --git a/system/include/fakesdl/SDL_gesture.h b/system/include/fakesdl/SDL/SDL_gesture.h similarity index 100% rename from system/include/fakesdl/SDL_gesture.h rename to system/include/fakesdl/SDL/SDL_gesture.h diff --git a/system/include/fakesdl/SDL_gfxPrimitives.h b/system/include/fakesdl/SDL/SDL_gfxPrimitives.h similarity index 100% rename from system/include/fakesdl/SDL_gfxPrimitives.h rename to system/include/fakesdl/SDL/SDL_gfxPrimitives.h diff --git a/system/include/fakesdl/SDL_haptic.h b/system/include/fakesdl/SDL/SDL_haptic.h similarity index 100% rename from system/include/fakesdl/SDL_haptic.h rename to system/include/fakesdl/SDL/SDL_haptic.h diff --git a/system/include/fakesdl/SDL_hints.h b/system/include/fakesdl/SDL/SDL_hints.h similarity index 100% rename from system/include/fakesdl/SDL_hints.h rename to system/include/fakesdl/SDL/SDL_hints.h diff --git a/system/include/fakesdl/SDL_image.h b/system/include/fakesdl/SDL/SDL_image.h similarity index 100% rename from system/include/fakesdl/SDL_image.h rename to system/include/fakesdl/SDL/SDL_image.h diff --git a/system/include/fakesdl/SDL_input.h b/system/include/fakesdl/SDL/SDL_input.h similarity index 100% rename from system/include/fakesdl/SDL_input.h rename to system/include/fakesdl/SDL/SDL_input.h diff --git a/system/include/fakesdl/SDL_joystick.h b/system/include/fakesdl/SDL/SDL_joystick.h similarity index 100% rename from system/include/fakesdl/SDL_joystick.h rename to system/include/fakesdl/SDL/SDL_joystick.h diff --git a/system/include/fakesdl/SDL_keyboard.h b/system/include/fakesdl/SDL/SDL_keyboard.h similarity index 100% rename from system/include/fakesdl/SDL_keyboard.h rename to system/include/fakesdl/SDL/SDL_keyboard.h diff --git a/system/include/fakesdl/SDL_keycode.h b/system/include/fakesdl/SDL/SDL_keycode.h similarity index 100% rename from system/include/fakesdl/SDL_keycode.h rename to system/include/fakesdl/SDL/SDL_keycode.h diff --git a/system/include/fakesdl/SDL_loadso.h b/system/include/fakesdl/SDL/SDL_loadso.h similarity index 100% rename from system/include/fakesdl/SDL_loadso.h rename to system/include/fakesdl/SDL/SDL_loadso.h diff --git a/system/include/fakesdl/SDL_log.h b/system/include/fakesdl/SDL/SDL_log.h similarity index 100% rename from system/include/fakesdl/SDL_log.h rename to system/include/fakesdl/SDL/SDL_log.h diff --git a/system/include/fakesdl/SDL_main.h b/system/include/fakesdl/SDL/SDL_main.h similarity index 100% rename from system/include/fakesdl/SDL_main.h rename to system/include/fakesdl/SDL/SDL_main.h diff --git a/system/include/fakesdl/SDL_mixer.h b/system/include/fakesdl/SDL/SDL_mixer.h similarity index 100% rename from system/include/fakesdl/SDL_mixer.h rename to system/include/fakesdl/SDL/SDL_mixer.h diff --git a/system/include/fakesdl/SDL_mouse.h b/system/include/fakesdl/SDL/SDL_mouse.h similarity index 100% rename from system/include/fakesdl/SDL_mouse.h rename to system/include/fakesdl/SDL/SDL_mouse.h diff --git a/system/include/fakesdl/SDL_mutex.h b/system/include/fakesdl/SDL/SDL_mutex.h similarity index 100% rename from system/include/fakesdl/SDL_mutex.h rename to system/include/fakesdl/SDL/SDL_mutex.h diff --git a/system/include/fakesdl/SDL_name.h b/system/include/fakesdl/SDL/SDL_name.h similarity index 100% rename from system/include/fakesdl/SDL_name.h rename to system/include/fakesdl/SDL/SDL_name.h diff --git a/system/include/fakesdl/SDL_opengl.h b/system/include/fakesdl/SDL/SDL_opengl.h similarity index 100% rename from system/include/fakesdl/SDL_opengl.h rename to system/include/fakesdl/SDL/SDL_opengl.h diff --git a/system/include/fakesdl/SDL_opengles.h b/system/include/fakesdl/SDL/SDL_opengles.h similarity index 100% rename from system/include/fakesdl/SDL_opengles.h rename to system/include/fakesdl/SDL/SDL_opengles.h diff --git a/system/include/fakesdl/SDL_opengles2.h b/system/include/fakesdl/SDL/SDL_opengles2.h similarity index 100% rename from system/include/fakesdl/SDL_opengles2.h rename to system/include/fakesdl/SDL/SDL_opengles2.h diff --git a/system/include/fakesdl/SDL_pixels.h b/system/include/fakesdl/SDL/SDL_pixels.h similarity index 100% rename from system/include/fakesdl/SDL_pixels.h rename to system/include/fakesdl/SDL/SDL_pixels.h diff --git a/system/include/fakesdl/SDL_platform.h b/system/include/fakesdl/SDL/SDL_platform.h similarity index 100% rename from system/include/fakesdl/SDL_platform.h rename to system/include/fakesdl/SDL/SDL_platform.h diff --git a/system/include/fakesdl/SDL_power.h b/system/include/fakesdl/SDL/SDL_power.h similarity index 100% rename from system/include/fakesdl/SDL_power.h rename to system/include/fakesdl/SDL/SDL_power.h diff --git a/system/include/fakesdl/SDL_quit.h b/system/include/fakesdl/SDL/SDL_quit.h similarity index 100% rename from system/include/fakesdl/SDL_quit.h rename to system/include/fakesdl/SDL/SDL_quit.h diff --git a/system/include/fakesdl/SDL_rect.h b/system/include/fakesdl/SDL/SDL_rect.h similarity index 100% rename from system/include/fakesdl/SDL_rect.h rename to system/include/fakesdl/SDL/SDL_rect.h diff --git a/system/include/fakesdl/SDL_render.h b/system/include/fakesdl/SDL/SDL_render.h similarity index 100% rename from system/include/fakesdl/SDL_render.h rename to system/include/fakesdl/SDL/SDL_render.h diff --git a/system/include/fakesdl/SDL_revision.h b/system/include/fakesdl/SDL/SDL_revision.h similarity index 100% rename from system/include/fakesdl/SDL_revision.h rename to system/include/fakesdl/SDL/SDL_revision.h diff --git a/system/include/fakesdl/SDL_rotozoom.h b/system/include/fakesdl/SDL/SDL_rotozoom.h similarity index 100% rename from system/include/fakesdl/SDL_rotozoom.h rename to system/include/fakesdl/SDL/SDL_rotozoom.h diff --git a/system/include/fakesdl/SDL_rwops.h b/system/include/fakesdl/SDL/SDL_rwops.h similarity index 100% rename from system/include/fakesdl/SDL_rwops.h rename to system/include/fakesdl/SDL/SDL_rwops.h diff --git a/system/include/fakesdl/SDL_scancode.h b/system/include/fakesdl/SDL/SDL_scancode.h similarity index 100% rename from system/include/fakesdl/SDL_scancode.h rename to system/include/fakesdl/SDL/SDL_scancode.h diff --git a/system/include/fakesdl/SDL_shape.h b/system/include/fakesdl/SDL/SDL_shape.h similarity index 100% rename from system/include/fakesdl/SDL_shape.h rename to system/include/fakesdl/SDL/SDL_shape.h diff --git a/system/include/fakesdl/SDL_stdinc.h b/system/include/fakesdl/SDL/SDL_stdinc.h similarity index 100% rename from system/include/fakesdl/SDL_stdinc.h rename to system/include/fakesdl/SDL/SDL_stdinc.h diff --git a/system/include/fakesdl/SDL_surface.h b/system/include/fakesdl/SDL/SDL_surface.h similarity index 100% rename from system/include/fakesdl/SDL_surface.h rename to system/include/fakesdl/SDL/SDL_surface.h diff --git a/system/include/fakesdl/SDL_syswm.h b/system/include/fakesdl/SDL/SDL_syswm.h similarity index 100% rename from system/include/fakesdl/SDL_syswm.h rename to system/include/fakesdl/SDL/SDL_syswm.h diff --git a/system/include/fakesdl/SDL_thread.h b/system/include/fakesdl/SDL/SDL_thread.h similarity index 100% rename from system/include/fakesdl/SDL_thread.h rename to system/include/fakesdl/SDL/SDL_thread.h diff --git a/system/include/fakesdl/SDL_timer.h b/system/include/fakesdl/SDL/SDL_timer.h similarity index 100% rename from system/include/fakesdl/SDL_timer.h rename to system/include/fakesdl/SDL/SDL_timer.h diff --git a/system/include/fakesdl/SDL_touch.h b/system/include/fakesdl/SDL/SDL_touch.h similarity index 100% rename from system/include/fakesdl/SDL_touch.h rename to system/include/fakesdl/SDL/SDL_touch.h diff --git a/system/include/fakesdl/SDL_ttf.h b/system/include/fakesdl/SDL/SDL_ttf.h similarity index 100% rename from system/include/fakesdl/SDL_ttf.h rename to system/include/fakesdl/SDL/SDL_ttf.h diff --git a/system/include/fakesdl/SDL_types.h b/system/include/fakesdl/SDL/SDL_types.h similarity index 100% rename from system/include/fakesdl/SDL_types.h rename to system/include/fakesdl/SDL/SDL_types.h diff --git a/system/include/fakesdl/SDL_version.h b/system/include/fakesdl/SDL/SDL_version.h similarity index 100% rename from system/include/fakesdl/SDL_version.h rename to system/include/fakesdl/SDL/SDL_version.h diff --git a/system/include/fakesdl/SDL_video.h b/system/include/fakesdl/SDL/SDL_video.h similarity index 100% rename from system/include/fakesdl/SDL_video.h rename to system/include/fakesdl/SDL/SDL_video.h diff --git a/test/test_browser.py b/test/test_browser.py index c109b1a4e54d9..0ea074f704ea2 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -322,13 +322,6 @@ def reftest(self, filename, reference, reference_slack=0, *args, **kwargs): print(f'overwriting expected image: {reference}') self.run_process('pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB actual.png'.split() + [reference]) - def test_sdl1_in_emscripten_nonstrict_mode(self): - if 'EMCC_STRICT' in os.environ and int(os.environ['EMCC_STRICT']): - self.skipTest('This test requires being run in non-strict mode (EMCC_STRICT env. variable unset)') - # TODO: This test is verifying behavior that will be deprecated at some point in the future, remove this test once - # system JS libraries are no longer automatically linked to anymore. - self.reftest('hello_world_sdl.c', 'htmltest.png') - def test_sdl1(self): self.reftest('hello_world_sdl.c', 'htmltest.png', cflags=['-lSDL', '-lGL']) self.reftest('hello_world_sdl.c', 'htmltest.png', cflags=['-sUSE_SDL', '-lGL']) # is the default anyhow @@ -2218,7 +2211,7 @@ def test_perspective(self): @requires_graphics_hardware def test_glerror(self): - self.btest('gl_error.c', expected='1', cflags=['-sLEGACY_GL_EMULATION', '-lGL']) + self.btest('gl_error.c', expected='1', cflags=['-sLEGACY_GL_EMULATION', '-lGL', '-sUSE_SDL']) @parameterized({ '': ([],), diff --git a/test/test_other.py b/test/test_other.py index 6c8c5f3461754..4390029172a06 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -2542,7 +2542,7 @@ def test_sdl_endianness(self): return 0; } ''') - self.do_runf('main.c', '1234, 1234, 4321\n') + self.do_runf('main.c', '1234, 1234, 4321\n', cflags=['-sUSE_SDL']) def test_sdl_scan_code_from_key(self): create_file('main.c', r''' @@ -2554,7 +2554,7 @@ def test_sdl_scan_code_from_key(self): return 0; } ''') - self.do_runf('main.c', '204\n') + self.do_runf('main.c', '204\n', cflags=['-sUSE_SDL']) def test_sdl_get_key_name(self): create_file('main.c', r''' @@ -2576,7 +2576,7 @@ def test_sdl_get_key_name(self): 0 -> '0' 0 -> '9' F1 -> '' -''') +''', cflags=['-sUSE_SDL']) @requires_network def test_sdl2_mixer_wav(self): @@ -2902,16 +2902,16 @@ def test_undefined_data_symbols(self): def test_GetProcAddress_LEGACY_GL_EMULATION(self): # without legacy gl emulation, getting a proc from there should fail - self.do_other_test('test_GetProcAddress_LEGACY_GL_EMULATION.c', args=['0'], cflags=['-sLEGACY_GL_EMULATION=0', '-sGL_ENABLE_GET_PROC_ADDRESS']) + self.do_other_test('test_GetProcAddress_LEGACY_GL_EMULATION.c', args=['0'], cflags=['-sLEGACY_GL_EMULATION=0', '-sGL_ENABLE_GET_PROC_ADDRESS', '-sUSE_SDL']) # with it, it should work - self.do_other_test('test_GetProcAddress_LEGACY_GL_EMULATION.c', args=['1'], cflags=['-sLEGACY_GL_EMULATION', '-sGL_ENABLE_GET_PROC_ADDRESS']) + self.do_other_test('test_GetProcAddress_LEGACY_GL_EMULATION.c', args=['1'], cflags=['-sLEGACY_GL_EMULATION', '-sGL_ENABLE_GET_PROC_ADDRESS', '-sUSE_SDL']) # Verifies that is user is building without -sGL_ENABLE_GET_PROC_ADDRESS, then # at link time they should get a helpful error message guiding them to enable # the option. def test_get_proc_address_error_message(self): expected = 'error: linker: Undefined symbol: SDL_GL_GetProcAddress(). Please pass -sGL_ENABLE_GET_PROC_ADDRESS at link time to link in SDL_GL_GetProcAddress().' - self.assert_fail([EMCC, '-sGL_ENABLE_GET_PROC_ADDRESS=0', test_file('other/test_GetProcAddress_LEGACY_GL_EMULATION.c')], expected) + self.assert_fail([EMCC, '-sGL_ENABLE_GET_PROC_ADDRESS=0', '-sUSE_SDL', test_file('other/test_GetProcAddress_LEGACY_GL_EMULATION.c')], expected) @parameterized({ '': (False, False), @@ -8884,7 +8884,7 @@ def test_standalone_system_headers(self, prefix): if directory and directory != 'compat': header = f'{directory}/{header}' inc = f'#include <{header}>\n__attribute__((weak)) int foo;\n' - cflags = ['-Werror', '-Wall', '-pedantic', '-msimd128', '-msse4'] + cflags = ['-Werror', '-Wall', '-pedantic', '-msimd128', '-msse4', '-sUSE_SDL'] if header == 'immintrin.h': cflags.append('-mavx2') if cxx_only: @@ -9243,6 +9243,7 @@ def test_closure_type_annotations(self): self.build('hello_world.c', cflags=[ '--closure=1', '-sINCLUDE_FULL_LIBRARY', + '-sUSE_SDL', '-sFETCH', '-sFETCH_SUPPORT_INDEXEDDB', '-Werror=closure', diff --git a/tools/compile.py b/tools/compile.py index 81bedffa25ca7..6ad2be3919cc5 100644 --- a/tools/compile.py +++ b/tools/compile.py @@ -139,8 +139,9 @@ def array_contains_any_of(hay, needles): cflags += ['-D__ARM_NEON__=1'] if '-nostdinc' not in user_args: - if not settings.USE_SDL: + if not settings.USE_SDL and '-lSDL' not in user_args and '-lGLEW' not in user_args: cflags += ['-Xclang', '-iwithsysroot' + os.path.join('/include', 'fakesdl')] + cflags += ['-Xclang', '-iwithsysroot' + os.path.join('/include', 'fakesdl', 'SDL')] cflags += ['-Xclang', '-iwithsysroot' + os.path.join('/include', 'compat')] return cflags diff --git a/tools/gen_struct_info.py b/tools/gen_struct_info.py index dee74814d52d6..9cbdd83b125a6 100755 --- a/tools/gen_struct_info.py +++ b/tools/gen_struct_info.py @@ -215,6 +215,7 @@ def generate_cmd(js_file_path, src_file_path, cflags): '-sINCOMING_MODULE_JS_API=', '-sSTRICT', '-sSUPPORT_LONGJMP=0', + '-sUSE_SDL', '-sASSERTIONS=0'] # Default behavior for emcc is to warn for binaryen version check mismatches diff --git a/tools/maint/gen_sig_info.py b/tools/maint/gen_sig_info.py index 14ba9f076b5a8..268e5c3d7b926 100755 --- a/tools/maint/gen_sig_info.py +++ b/tools/maint/gen_sig_info.py @@ -338,6 +338,7 @@ def extract_sig_info(sig_info, extra_settings=None, extra_cflags=None, cxx=False obj_file = 'out.o' cmd = [compiler, c_file, '-c', '-pthread', '--tracing', + '-sUSE_SDL', '-Wno-deprecated-declarations', '-I' + utils.path_from_root('system/lib/libc'), '-I' + utils.path_from_root('system/lib/wasmfs'), diff --git a/tools/ports/cocos2d.py b/tools/ports/cocos2d.py index 475bc36336cb2..a03e4a21080e1 100644 --- a/tools/ports/cocos2d.py +++ b/tools/ports/cocos2d.py @@ -43,6 +43,7 @@ def create(final): '-DCP_USE_DOUBLES=0', '-sUSE_ZLIB', '-sUSE_LIBPNG', + '-sUSE_SDL', ] for dirname in includes: @@ -65,6 +66,7 @@ def clear(ports, settings, shared): def process_dependencies(settings): settings.USE_LIBPNG = 1 settings.USE_ZLIB = 1 + settings.USE_SDL = 1 def process_args(ports):