Skip to content

Commit 9a6c62e

Browse files
committed
Don't enable USE_GLFW by default
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 7b3d638 commit 9a6c62e

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ See docs/process.md for more on how version tagging works.
2424
- The `--minify=0` commnad line flag will now preserve comments as well as
2525
whitespace. This means the resulting output can then be run though closure
2626
compiler or some other tool that gives comments semantic meaning. (#20121)
27+
- The `USE_GLFW` settings now defaults to 0 rather than 2. This matches other
28+
other settings such as `USE_SDL` that default to 0 these days and also is
29+
inline the the behaviour under `MINIMAL_RUNTIME`. If you use glfw you now
30+
need to explictly opt into it using `-sUSE_GLFW`.
2731

2832
3.1.45 - 08/23/23
2933
-----------------

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')
@@ -409,11 +409,6 @@ def expand_byte_size_suffixes(value):
409409
return value
410410

411411

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

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

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

src/settings.js

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

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

test/test_browser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,7 @@ def test_sdl_fog_linear(self):
16211621
@requires_graphics_hardware
16221622
def test_glfw(self):
16231623
self.btest_exit('browser/test_glfw.c', args=['-sLEGACY_GL_EMULATION', '-lglfw', '-lGL'])
1624+
self.btest_exit('browser/test_glfw.c', args=['-sLEGACY_GL_EMULATION', '-sUSE_GLFW=2', '-lGL'])
16241625
self.btest_exit('browser/test_glfw.c', args=['-sLEGACY_GL_EMULATION', '-sUSE_GLFW=2', '-lglfw', '-lGL'])
16251626

16261627
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,12 +1114,21 @@ 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': 2},
1121+
}
11171122

11181123
if library_name in library_map:
11191124
libs = library_map[library_name]
11201125
logger.debug('Mapping library `%s` to JS libraries: %s' % (library_name, libs))
11211126
return (libs, native_library_map.get(library_name))
11221127

1128+
if library_name in settings_map:
1129+
for key, value in settings_map[library_name].items():
1130+
default_setting(key, value)
1131+
11231132
if library_name.endswith('.js') and os.path.isfile(path_from_root('src', f'library_{library_name}')):
11241133
return ([f'library_{library_name}'], None)
11251134

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)