Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions site/source/docs/tools_reference/settings_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// - 2 and 3 are upstream ports build from the official SDL codebase.
// - 2 and 3 are upstream ports built from the official SDL codebase.

//
// Alternate syntax for using the port: --use-port=sdl2
// [compile+link]
var USE_SDL = 0;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 1 addition & 8 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this test removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the exact behavior that I'm removing. i.e. that ability to use SDL headers without -sUSE_SDL.

I'm fixing the TODO here really, and this test should really have been removed in #18443.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. now that I go back and read #18443 it seems like it was deliberately only targeting the unversioned includes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way, this lgtm. To use SDL, the flag should be needed, like all other ports.


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
Expand Down Expand Up @@ -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({
'': ([],),
Expand Down
15 changes: 8 additions & 7 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'''
Expand All @@ -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'''
Expand All @@ -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):
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion tools/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions tools/gen_struct_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tools/maint/gen_sig_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 2 additions & 0 deletions tools/ports/cocos2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def create(final):
'-DCP_USE_DOUBLES=0',
'-sUSE_ZLIB',
'-sUSE_LIBPNG',
'-sUSE_SDL',
]

for dirname in includes:
Expand All @@ -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):
Expand Down