Skip to content

Commit 48eec4c

Browse files
authored
Don't enable USE_GLFW by default (#19939)
This changes the default behaviour to match that of STRICT mode and MINIMAL_RUNTIME node. We made a similar change for USE_SDL back in #18443. As part of this change I also updated the code that maps `-l` flags to JS libraries. In some cases we also want these to set the corresponding `-sUSE_XXX` setting.
1 parent 1433a23 commit 48eec4c

File tree

6 files changed

+26
-11
lines changed

6 files changed

+26
-11
lines changed

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ See docs/process.md for more on how version tagging works.
3232
silent failures.
3333
- JS library decorators such as `__deps` and `__async` are now type checked so
3434
that errors are not silently ignored.
35+
- The `USE_GLFW` settings now defaults to 0 rather than 2. This matches other
36+
other settings such as `USE_SDL` that default to 0 these days and also matches
37+
the existing behaviour for `MINIMAL_RUNTIME` and `STRICT` mode.
38+
If you use GLFW you now need to explictly opt into it using `-sUSE_GLFW` or
39+
`-lglfw`. (#19939)
3540

3641
3.1.45 - 08/23/23
3742
-----------------

emcc.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
from tools import webassembly
5555
from tools import config
5656
from tools import cache
57-
from tools.settings import user_settings, settings, MEM_SIZE_SETTINGS, COMPILE_TIME_SETTINGS
57+
from tools.settings import default_setting, user_settings, settings, MEM_SIZE_SETTINGS, COMPILE_TIME_SETTINGS
5858
from tools.utils import read_file, write_file, read_binary, delete_file, removeprefix
5959

6060
logger = logging.getLogger('emcc')
@@ -410,11 +410,6 @@ def expand_byte_size_suffixes(value):
410410
return value
411411

412412

413-
def default_setting(name, new_default):
414-
if name not in user_settings:
415-
setattr(settings, name, new_default)
416-
417-
418413
def apply_user_settings():
419414
"""Take a map of users settings {NAME: VALUE} and apply them to the global
420415
settings object.
@@ -2028,15 +2023,13 @@ def phase_linker_setup(options, state, newargs):
20282023
default_setting('AUTO_JS_LIBRARIES', 0)
20292024
# When using MINIMAL_RUNTIME, symbols should only be exported if requested.
20302025
default_setting('EXPORT_KEEPALIVE', 0)
2031-
default_setting('USE_GLFW', 0)
20322026

20332027
if settings.STRICT_JS and (settings.MODULARIZE or settings.EXPORT_ES6):
20342028
exit_with_error("STRICT_JS doesn't work with MODULARIZE or EXPORT_ES6")
20352029

20362030
if settings.STRICT:
20372031
if not settings.MODULARIZE and not settings.EXPORT_ES6:
20382032
default_setting('STRICT_JS', 1)
2039-
default_setting('USE_GLFW', 0)
20402033
default_setting('AUTO_JS_LIBRARIES', 0)
20412034
default_setting('AUTO_NATIVE_LIBRARIES', 0)
20422035
default_setting('AUTO_ARCHIVE_INDEXES', 0)

src/settings.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,9 +1307,8 @@ var EMSCRIPTEN_TRACING = false;
13071307
// Specify the GLFW version that is being linked against. Only relevant, if you
13081308
// are linking against the GLFW library. Valid options are 2 for GLFW2 and 3
13091309
// for GLFW3.
1310-
// This defaults to 0 in either MINIMAL_RUNTIME or STRICT modes.
13111310
// [link]
1312-
var USE_GLFW = 2;
1311+
var USE_GLFW = 0;
13131312

13141313
// Whether to use compile code to WebAssembly. Set this to 0 to compile to JS
13151314
// instead of wasm.

test/test_browser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,11 @@ def test_sdl_fog_linear(self):
16201620

16211621
@requires_graphics_hardware
16221622
def test_glfw(self):
1623+
# Using only the `-l` flag
16231624
self.btest_exit('browser/test_glfw.c', args=['-sLEGACY_GL_EMULATION', '-lglfw', '-lGL'])
1625+
# Using only the `-s` flag
1626+
self.btest_exit('browser/test_glfw.c', args=['-sLEGACY_GL_EMULATION', '-sUSE_GLFW=2', '-lGL'])
1627+
# Using both `-s` and `-l` flags
16241628
self.btest_exit('browser/test_glfw.c', args=['-sLEGACY_GL_EMULATION', '-sUSE_GLFW=2', '-lglfw', '-lGL'])
16251629

16261630
def test_glfw_minimal(self):

tools/building.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from .shared import LLVM_DWARFDUMP, demangle_c_symbol_name
3333
from .shared import get_emscripten_temp_dir, exe_suffix, is_c_symbol
3434
from .utils import WINDOWS
35-
from .settings import settings
35+
from .settings import settings, default_setting
3636

3737
logger = logging.getLogger('building')
3838

@@ -1114,6 +1114,15 @@ def map_to_js_libs(library_name, emit_tsd):
11141114
'embind': 'libembind',
11151115
'GL': 'libGL',
11161116
}
1117+
settings_map = {
1118+
'glfw': {'USE_GLFW': 2},
1119+
'glfw3': {'USE_GLFW': 3},
1120+
'SDL': {'USE_SDL': 1},
1121+
}
1122+
1123+
if library_name in settings_map:
1124+
for key, value in settings_map[library_name].items():
1125+
default_setting(key, value)
11171126

11181127
if library_name in library_map:
11191128
libs = library_map[library_name]

tools/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@
9595
user_settings: Dict[str, str] = {}
9696

9797

98+
def default_setting(name, new_default):
99+
if name not in user_settings:
100+
setattr(settings, name, new_default)
101+
102+
98103
class SettingsManager:
99104
attrs: Dict[str, Any] = {}
100105
types: Dict[str, Any] = {}

0 commit comments

Comments
 (0)