Skip to content

Commit b71f229

Browse files
committed
Finalize EMCC_STRICT mode for linking to libraries. Improve browser suite to pass in EMCC_STRICT mode.
1 parent 87d0bd0 commit b71f229

File tree

5 files changed

+208
-170
lines changed

5 files changed

+208
-170
lines changed

emcc.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,12 +955,18 @@ def detect_fixed_language_mode(args):
955955
'm': '',
956956
'openal': 'library_openal.js',
957957
'pthread': '',
958+
'X11': 'library_xlib.js',
958959
'SDL': 'library_sdl.js',
959-
'stdc++': ''
960+
'stdc++': '',
961+
'uuid': 'library_uuid.js'
960962
}
961963
if lib in js_system_libraries:
962964
if len(js_system_libraries[lib]) > 0:
963965
system_js_libraries += [js_system_libraries[lib]]
966+
967+
# TODO: This is unintentional due to historical reasons. Improve EGL to use HTML5 API to avoid depending on GLUT.
968+
if lib == 'EGL': system_js_libraries += ['library_glut.js']
969+
964970
elif lib.endswith('.js') and os.path.isfile(shared.path_from_root('src', 'library_' + lib)):
965971
system_js_libraries += ['library_' + lib]
966972
else:
@@ -972,6 +978,12 @@ def detect_fixed_language_mode(args):
972978
else:
973979
logging.warning('emcc: cannot find library "%s"', lib)
974980

981+
# Certain linker flags imply some link libraries to be pulled in by default.
982+
if 'EMTERPRETIFY_ASYNC=1' in settings_changes: system_js_libraries += ['library_async.js']
983+
if 'ASYNCIFY=1' in settings_changes: system_js_libraries += ['library_async.js']
984+
if 'LZ4=1' in settings_changes: system_js_libraries += ['library_lz4.js']
985+
if 'USE_SDL=1' in settings_changes: system_js_libraries += ['library_sdl.js']
986+
if 'USE_SDL=2' in settings_changes: system_js_libraries += ['library_egl.js', 'library_glut.js', 'library_gl.js']
975987
settings_changes.append('SYSTEM_JS_LIBRARIES="' + ','.join(system_js_libraries) + '"')
976988

977989
# If not compiling to JS, then we are compiling to an intermediate bitcode objects or library, so

src/library_fs.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
mergeInto(LibraryManager.library, {
2-
$FS__deps: ['$ERRNO_CODES', '$ERRNO_MESSAGES', '__setErrNo', '$PATH', '$TTY', '$MEMFS', '$IDBFS', '$NODEFS', '$WORKERFS', 'stdin', 'stdout', 'stderr'],
2+
$FS__deps: ['$ERRNO_CODES', '$ERRNO_MESSAGES', '__setErrNo', '$PATH', '$TTY', '$MEMFS',
3+
#if __EMSCRIPTEN_HAS_idbfs_js__
4+
'$IDBFS',
5+
#endif
6+
#if __EMSCRIPTEN_HAS_nodefs_js__
7+
'$NODEFS',
8+
#endif
9+
#if __EMSCRIPTEN_HAS_workerfs_js__
10+
'$WORKERFS',
11+
#endif
12+
'stdin', 'stdout', 'stderr'],
313
$FS__postset: 'FS.staticInit();' +
414
'__ATINIT__.unshift(function() { if (!Module["noFSInit"] && !FS.init.initialized) FS.init() });' +
515
'__ATMAIN__.push(function() { FS.ignorePermissions = false });' +
@@ -1379,9 +1389,15 @@ mergeInto(LibraryManager.library, {
13791389

13801390
FS.filesystems = {
13811391
'MEMFS': MEMFS,
1392+
#if __EMSCRIPTEN_HAS_idbfs_js__
13821393
'IDBFS': IDBFS,
1394+
#endif
1395+
#if __EMSCRIPTEN_HAS_nodefs_js__
13831396
'NODEFS': NODEFS,
1397+
#endif
1398+
#if __EMSCRIPTEN_HAS_workerfs_js__
13841399
'WORKERFS': WORKERFS,
1400+
#endif
13851401
};
13861402
},
13871403
init: function(input, output, error) {

src/modules.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ var LibraryManager = {
102102
'library_browser.js',
103103
'library_formatString.js',
104104
'library_path.js',
105+
'library_signals.js',
105106
'library_syscall.js',
106107
'library_html5.js'
107108
];
@@ -138,7 +139,6 @@ var LibraryManager = {
138139
'library_glfw.js',
139140
'library_uuid.js',
140141
'library_glew.js',
141-
'library_signals.js',
142142
'library_idbstore.js',
143143
'library_async.js',
144144
'library_vr.js'
@@ -148,6 +148,11 @@ var LibraryManager = {
148148
// If there are any explicitly specified system JS libraries to link to, add those to link.
149149
if (SYSTEM_JS_LIBRARIES) {
150150
SYSTEM_JS_LIBRARIES = SYSTEM_JS_LIBRARIES.split(',');
151+
// For each system JS library library_xxx.js, add a preprocessor token __EMSCRIPTEN_HAS_xxx_js__ so that code can conditionally dead code eliminate out
152+
// if a particular feature is not being linked in.
153+
for (var i = 0; i < SYSTEM_JS_LIBRARIES.length; ++i) {
154+
global['__EMSCRIPTEN_HAS_' + SYSTEM_JS_LIBRARIES[i].replace('.', '_').replace('library_', '') + '__'] = 1
155+
}
151156
libraries = libraries.concat(SYSTEM_JS_LIBRARIES);
152157
}
153158

0 commit comments

Comments
 (0)