From 7be0ee0135fa61d4ed74da33362791c97c0dd5a1 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 28 Oct 2020 12:46:01 -0700 Subject: [PATCH 1/6] auto [ci skip] --- emcc.py | 2 ++ tools/building.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/emcc.py b/emcc.py index f88063c1c74e2..416465f74fe9c 100755 --- a/emcc.py +++ b/emcc.py @@ -3150,6 +3150,8 @@ def process_libraries(libs, lib_dirs, temp_files): if jslibs is not None: libraries += [(i, jslib) for jslib in jslibs] consumed.append(i) + elif building.map_and_apply_to_settings(lib): + consumed.append(i) shared.Settings.SYSTEM_JS_LIBRARIES += libraries diff --git a/tools/building.py b/tools/building.py index 885bb7852d687..a22b576d16c63 100644 --- a/tools/building.py +++ b/tools/building.py @@ -1467,6 +1467,23 @@ def map_to_js_libs(library_name): return None +# map a linker flag to a Settings option, and apply it. this lets a user write +# -lSDL2 and it will have the same effect as -s USE_SDL=2. +def map_and_apply_to_settings(library_name): + library_map = { + 'SDL2': [('USE_SDL', 2)], + 'SDL2_mixer': [('USE_SDL', 2), ('USE_SDL_MIXER', 2)], + } + + if library_name in library_map: + for key, value in library_map[library_name]: + logger.debug('Mapping library `%s` to settings changes: %s = %s' % (library_name, key, value)) + shared.Settings.__setattr__(key, value) + return True + + return False + + def emit_wasm_source_map(wasm_file, map_file): # source file paths must be relative to the location of the map (which is # emitted alongside the wasm) From 5d35370e0f99d489ced5b06b3ca6640619c122dc Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 28 Oct 2020 16:25:09 -0700 Subject: [PATCH 2/6] fixes #12589 --- tools/building.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/building.py b/tools/building.py index a22b576d16c63..fffab34692436 100644 --- a/tools/building.py +++ b/tools/building.py @@ -1470,9 +1470,12 @@ def map_to_js_libs(library_name): # map a linker flag to a Settings option, and apply it. this lets a user write # -lSDL2 and it will have the same effect as -s USE_SDL=2. def map_and_apply_to_settings(library_name): + # most libraries just work, because the -l name matches the name of the + # library we build. however, if a library has variations, which cause us to + # build multiple versions with multiple names, then we need this mechanism. library_map = { - 'SDL2': [('USE_SDL', 2)], - 'SDL2_mixer': [('USE_SDL', 2), ('USE_SDL_MIXER', 2)], + # SDL2_mixer's built library name contains the specific codecs built in. + 'SDL2_mixer': [('USE_SDL_MIXER', 2)], } if library_name in library_map: From e703cbc2b5b38d7504c3291c335c87eeed121042 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 28 Oct 2020 16:32:02 -0700 Subject: [PATCH 3/6] test --- tests/sdl2_mixer_wav.c | 7 +++++++ tests/test_browser.py | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/sdl2_mixer_wav.c b/tests/sdl2_mixer_wav.c index 400f058384dcc..aed62b069ddd9 100644 --- a/tests/sdl2_mixer_wav.c +++ b/tests/sdl2_mixer_wav.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -21,6 +22,12 @@ void sound_loop_then_quit() { } int main(int argc, char* argv[]){ + SDL_version version; + SDL_GetVersion(&version); + printf("Linked against SDL %d.%d.%d.\n", + version.major, version.minor, version.patch); + assert(version.major == 2); + if (SDL_Init(SDL_INIT_AUDIO) < 0) return -1; int const frequency = EM_ASM_INT_V({ diff --git a/tests/test_browser.py b/tests/test_browser.py index 71d3f7ce17f51..10b72b9994017 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -3192,10 +3192,14 @@ def test_sdl2_misc(self): self.compile_btest(['test.o', '-s', 'USE_SDL=2', '-o', 'test.html']) self.run_browser('test.html', '...', '/report_result?1') + @parameterized({ + 'dash_s': (['-s', 'USE_SDL=2', '-s', 'USE_SDL_MIXER=2'],), + 'dash_l': (['-lSDL2', '-lSDL2_mixer'],), + }) @requires_sound_hardware - def test_sdl2_mixer_wav(self): + def test_sdl2_mixer_wav(self, flags): shutil.copyfile(path_from_root('tests', 'sounds', 'the_entertainer.wav'), 'sound.wav') - self.btest('sdl2_mixer_wav.c', expected='1', args=['--preload-file', 'sound.wav', '-s', 'USE_SDL=2', '-s', 'USE_SDL_MIXER=2', '-s', 'INITIAL_MEMORY=33554432']) + self.btest('sdl2_mixer_wav.c', expected='1', args=['--preload-file', 'sound.wav', '-s', 'INITIAL_MEMORY=33554432'] + flags) @parameterized({ 'wav': ([], '0', 'the_entertainer.wav'), From bc5773a502a82ef1a277d66c204d51a06e655c96 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 28 Oct 2020 16:35:34 -0700 Subject: [PATCH 4/6] test --- tests/sdl2_mixer_wav.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/tests/sdl2_mixer_wav.c b/tests/sdl2_mixer_wav.c index aed62b069ddd9..7e192957197ab 100644 --- a/tests/sdl2_mixer_wav.c +++ b/tests/sdl2_mixer_wav.c @@ -28,8 +28,12 @@ int main(int argc, char* argv[]){ version.major, version.minor, version.patch); assert(version.major == 2); - if (SDL_Init(SDL_INIT_AUDIO) < 0) - return -1; + if (SDL_Init(SDL_INIT_AUDIO) < 0) { + puts("Failed to init audio"); +#ifdef REPORT_RESULT + REPORT_RESULT(100); +#endif + } int const frequency = EM_ASM_INT_V({ var context; try { @@ -39,13 +43,25 @@ int main(int argc, char* argv[]){ } return context.sampleRate; }); - if(Mix_OpenAudio(frequency, MIX_DEFAULT_FORMAT, 2, 1024) == -1) - return -1; + if(Mix_OpenAudio(frequency, MIX_DEFAULT_FORMAT, 2, 1024) == -1) { + puts("Failed to open audio"); +#ifdef REPORT_RESULT + REPORT_RESULT(101); +#endif + } wave = Mix_LoadWAV(WAV_PATH); - if (wave == NULL) - return -1; - if (Mix_PlayChannel(-1, wave, 0) == -1) - return -1; + if (wave == NULL) { + puts("Failed to load audio"); +#ifdef REPORT_RESULT + REPORT_RESULT(102); +#endif + } + if (Mix_PlayChannel(-1, wave, 0) == -1) { + puts("Failed to play audio"); +#ifdef REPORT_RESULT + REPORT_RESULT(103); +#endif + } printf("Starting sound play loop\n"); emscripten_set_main_loop(sound_loop_then_quit, 0, 1); return 0; From 5cf6de232e3b94fd0eb12d33481676005162713d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 28 Oct 2020 16:38:36 -0700 Subject: [PATCH 5/6] changelog --- ChangeLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index fe16e915f870e..a88f2773ebdf0 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -23,6 +23,9 @@ Current Trunk - dlopen, in conformace with the spec, now checks that one of either RTDL_LAZY or RTDL_NOW flags ar set. Previously, it was possible set nether of these without generating an error. +- Allow `-lSDL2_mixer` to just work. (Others like `-lSDL2` always worked, but + for `SDL2_mixer` things were broken because we build multiple variations of + that library.) That link flag is now the same as `-s USE_SDL2_MIXER=2`. 2.0.8: 10/24/2020 ----------------- From 46a5dbde41c8a5d22073ec1ebf36f79f6d4589a0 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 29 Oct 2020 15:27:07 -0700 Subject: [PATCH 6/6] use setattr --- tools/building.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/building.py b/tools/building.py index 16a8eb94cb686..86b7e8b94a366 100644 --- a/tools/building.py +++ b/tools/building.py @@ -1479,7 +1479,7 @@ def map_and_apply_to_settings(library_name): if library_name in library_map: for key, value in library_map[library_name]: logger.debug('Mapping library `%s` to settings changes: %s = %s' % (library_name, key, value)) - shared.Settings.__setattr__(key, value) + setattr(shared.Settings, key, value) return True return False