Skip to content

Commit

Permalink
Merge pull request emscripten-core#4665 from juj/emscripten_strict
Browse files Browse the repository at this point in the history
emscripten_strict
  • Loading branch information
juj authored Dec 19, 2016
2 parents 6665be6 + 9b727e8 commit 051ef31
Show file tree
Hide file tree
Showing 8 changed files with 378 additions and 195 deletions.
47 changes: 44 additions & 3 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,11 @@ def filter_emscripten_options(argv):
if compiler == shared.EMCC: compiler = [shared.PYTHON, shared.EMCC]
else: compiler = [compiler]
cmd = compiler + list(filter_emscripten_options(sys.argv[1:]))
if not use_js: cmd += shared.EMSDK_OPTS + ['-D__EMSCRIPTEN__', '-DEMSCRIPTEN']
if not use_js:
cmd += shared.EMSDK_OPTS + ['-D__EMSCRIPTEN__']
# The preprocessor define EMSCRIPTEN is deprecated. Don't pass it to code in strict mode. Code should use the define __EMSCRIPTEN__ instead.
if not shared.Settings.STRICT:
cmd += ['-DEMSCRIPTEN']
if use_js: cmd += ['-s', 'ERROR_ON_UNDEFINED_SYMBOLS=1'] # configure tests should fail when an undefined symbol exists

logging.debug('just configuring: ' + ' '.join(cmd))
Expand Down Expand Up @@ -934,6 +938,29 @@ def detect_fixed_language_mode(args):
if separate_asm:
shared.Settings.SEPARATE_ASM = os.path.basename(asm_target)

if 'EMCC_STRICT' in os.environ:
shared.Settings.STRICT = os.environ.get('EMCC_STRICT') != '0'

# Libraries are searched before settings_changes are applied, so apply the value for STRICT and ERROR_ON_MISSING_LIBRARIES from
# command line already now.

def get_last_setting_change(setting):
return ([None] + filter(lambda x: x.startswith(setting + '='), settings_changes))[-1]

strict_cmdline = get_last_setting_change('STRICT')
if strict_cmdline:
shared.Settings.STRICT = int(strict_cmdline[len('STRICT='):])

if shared.Settings.STRICT:
shared.Settings.ERROR_ON_UNDEFINED_SYMBOLS = 1
shared.Settings.ERROR_ON_MISSING_LIBRARIES = 1

error_on_missing_libraries_cmdline = get_last_setting_change('ERROR_ON_MISSING_LIBRARIES')
if error_on_missing_libraries_cmdline:
shared.Settings.ERROR_ON_MISSING_LIBRARIES = int(error_on_missing_libraries_cmdline[len('ERROR_ON_MISSING_LIBRARIES='):])

system_js_libraries = []

# Find library files
for i, lib in libs:
logging.debug('looking for library "%s"', lib)
Expand All @@ -950,8 +977,13 @@ def detect_fixed_language_mode(args):
break
if found: break
if found: break
if not found and lib not in ['GL', 'GLU', 'glut', 'm', 'c', 'SDL', 'stdc++', 'pthread']: # whitelist our default libraries
logging.warning('emcc: cannot find library "%s"', lib)
if not found:
system_js_libraries += shared.Building.path_to_system_js_libraries(lib)

# Certain linker flags imply some link libraries to be pulled in by default.
system_js_libraries += shared.Building.path_to_system_js_libraries_for_settings(settings_changes)

settings_changes.append('SYSTEM_JS_LIBRARIES="' + ','.join(system_js_libraries) + '"')

# If not compiling to JS, then we are compiling to an intermediate bitcode objects or library, so
# ignore dynamic linking, since multiple dynamic linkings can interfere with each other
Expand Down Expand Up @@ -1015,6 +1047,15 @@ def check(input_file):
if shared.get_llvm_target() == shared.WASM_TARGET:
shared.Settings.WASM_BACKEND = 1

if not shared.Settings.STRICT:
# The preprocessor define EMSCRIPTEN is deprecated. Don't pass it to code in strict mode. Code should use the define __EMSCRIPTEN__ instead.
shared.COMPILER_OPTS += ['-DEMSCRIPTEN']

# The system include path system/include/emscripten/ is deprecated, i.e. instead of #include <emscripten.h>, one should pass in #include <emscripten/emscripten.h>.
# This path is not available in Emscripten strict mode.
if shared.USE_EMSDK:
shared.C_INCLUDE_PATHS += [shared.path_from_root('system', 'include', 'emscripten')]

# Use settings

try:
Expand Down
18 changes: 17 additions & 1 deletion src/library_fs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
mergeInto(LibraryManager.library, {
$FS__deps: ['$ERRNO_CODES', '$ERRNO_MESSAGES', '__setErrNo', '$PATH', '$TTY', '$MEMFS', '$IDBFS', '$NODEFS', '$WORKERFS', 'stdin', 'stdout', 'stderr'],
$FS__deps: ['$ERRNO_CODES', '$ERRNO_MESSAGES', '__setErrNo', '$PATH', '$TTY', '$MEMFS',
#if __EMSCRIPTEN_HAS_idbfs_js__
'$IDBFS',
#endif
#if __EMSCRIPTEN_HAS_nodefs_js__
'$NODEFS',
#endif
#if __EMSCRIPTEN_HAS_workerfs_js__
'$WORKERFS',
#endif
'stdin', 'stdout', 'stderr'],
$FS__postset: 'FS.staticInit();' +
'__ATINIT__.unshift(function() { if (!Module["noFSInit"] && !FS.init.initialized) FS.init() });' +
'__ATMAIN__.push(function() { FS.ignorePermissions = false });' +
Expand Down Expand Up @@ -1382,9 +1392,15 @@ mergeInto(LibraryManager.library, {

FS.filesystems = {
'MEMFS': MEMFS,
#if __EMSCRIPTEN_HAS_idbfs_js__
'IDBFS': IDBFS,
#endif
#if __EMSCRIPTEN_HAS_nodefs_js__
'NODEFS': NODEFS,
#endif
#if __EMSCRIPTEN_HAS_workerfs_js__
'WORKERFS': WORKERFS,
#endif
};
},
init: function(input, output, error) {
Expand Down
70 changes: 48 additions & 22 deletions src/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,41 +96,67 @@ var LibraryManager = {
load: function() {
if (this.library) return;

// Core system libraries (always linked against)
var libraries = [
'library.js',
'library_browser.js',
'library_formatString.js',
'library_path.js',
'library_syscall.js'
'library_signals.js',
'library_syscall.js',
'library_html5.js'
];

if (!NO_FILESYSTEM) {
// Core filesystem libraries (always linked against, unless -s NO_FILESYSTEM=1 is specified)
libraries = libraries.concat([
'library_fs.js',
'library_idbfs.js',
'library_memfs.js',
'library_nodefs.js',
'library_sockfs.js',
'library_workerfs.js',
'library_tty.js',
'library_lz4.js',
]);

// Additional filesystem libraries (in strict mode, link to these explicitly via -lxxx.js)
if (!STRICT) {
libraries = libraries.concat([
'library_idbfs.js',
'library_nodefs.js',
'library_sockfs.js',
'library_workerfs.js',
'library_lz4.js',
]);
}
}

// Additional JS libraries (in strict mode, link to these explicitly via -lxxx.js)
if (!STRICT) {
libraries = libraries.concat([
'library_sdl.js',
'library_gl.js',
'library_glut.js',
'library_xlib.js',
'library_egl.js',
'library_openal.js',
'library_glfw.js',
'library_uuid.js',
'library_glew.js',
'library_idbstore.js',
'library_async.js',
'library_vr.js'
]);
}

// If there are any explicitly specified system JS libraries to link to, add those to link.
if (SYSTEM_JS_LIBRARIES) {
libraries = libraries.concat(SYSTEM_JS_LIBRARIES);
}

libraries = libraries.concat(additionalLibraries);

// For each JS library library_xxx.js, add a preprocessor token __EMSCRIPTEN_HAS_xxx_js__ so that code can conditionally dead code eliminate out
// if a particular feature is not being linked in.
for (var i = 0; i < libraries.length; ++i) {
global['__EMSCRIPTEN_HAS_' + libraries[i].replace('.', '_').replace('library_', '') + '__'] = 1
}
libraries = libraries.concat([
'library_sdl.js',
'library_gl.js',
'library_glut.js',
'library_xlib.js',
'library_egl.js',
'library_openal.js',
'library_glfw.js',
'library_uuid.js',
'library_glew.js',
'library_html5.js',
'library_signals.js',
'library_idbstore.js',
'library_async.js',
'library_vr.js'
]).concat(additionalLibraries);

if (BOOTSTRAPPING_STRUCT_INFO) libraries = ['library_bootstrap_structInfo.js', 'library_formatString.js'];
if (ONLY_MY_CODE) {
Expand Down
20 changes: 20 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,10 @@ var LINKABLE = 0; // If set to 1, this file can be linked with others, either as
// LINKABLE of 0 is very useful in that we can reduce the size of the
// generated code very significantly, by removing everything not actually used.

var STRICT = 0; // Emscripten 'strict' build mode: Drop supporting any deprecated build options.
// Set the environment variable EMCC_STRICT=1 or pass -s STRICT=1
// to test that a codebase builds nicely in forward compatible manner.

var WARN_ON_UNDEFINED_SYMBOLS = 1; // If set to 1, we will warn on any undefined symbols that
// are not resolved by the library_*.js files. Note that
// it is common in large projects to
Expand All @@ -501,6 +505,22 @@ var WARN_ON_UNDEFINED_SYMBOLS = 1; // If set to 1, we will warn on any undefined
var ERROR_ON_UNDEFINED_SYMBOLS = 0; // If set to 1, we will give a compile-time error on any
// undefined symbols (see WARN_ON_UNDEFINED_SYMBOLS).

// The default value for this is currently 0, but will be
// transitioned to 1 in the future. To keep relying on
// building with -s ERROR_ON_UNDEFINED_SYMBOLS=0 setting,
// prefer to set that option explicitly in your build system.

var ERROR_ON_MISSING_LIBRARIES = 0; // If set to 1, any -lfoo directives pointing to nonexisting
// library files will issue a linker error.

// The default value for this is currently 0, but will be
// transitioned to 1 in the future. To keep relying on
// building with -s ERROR_ON_MISSING_LIBRARIES=0 setting,
// prefer to set that option explicitly in your build system.

var SYSTEM_JS_LIBRARIES = []; // Specifies a list of Emscripten-provided JS libraries to link against.
// (internal, use -lfoo or -lfoo.js to link to Emscripten system JS libraries)

var SMALL_XHR_CHUNKS = 0; // Use small chunk size for binary synchronous XHR's in Web Workers.
// Used for testing.
// See test_chunked_synchronous_xhr in runner.py and library.js.
Expand Down
1 change: 1 addition & 0 deletions system/include/emscripten.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "emscripten/emscripten.h"
Loading

0 comments on commit 051ef31

Please sign in to comment.