Codebase list emscripten / 52724d2
emcc.py: consistent use of `user_settings` variable name. NFC (#16366) This map was being used in a few different places under different names. Also, remove duplicate definition of `default_setting`. Sam Clegg authored 2 years ago GitHub committed 2 years ago
1 changed file(s) with 47 addition(s) and 50 deletion(s). Raw diff Collapse all Expand all
339339 return value
340340
341341
342 def apply_settings(changes):
342 def default_setting(user_settings, name, new_default):
343 if name not in user_settings:
344 setattr(settings, name, new_default)
345
346
347 def apply_settings(user_settings):
343348 """Take a map of users settings {NAME: VALUE} and apply them to the global
344349 settings object.
345350 """
357362 value = str(1 - int(value))
358363 return key, value
359364
360 for key, value in changes.items():
365 for key, value in user_settings.items():
361366 key, value = standardize_setting_change(key, value)
362367
363368 if key in settings.internal_settings:
11211126
11221127 ## Process argument and setup the compiler
11231128 state = EmccState(args)
1124 options, newargs, settings_map = phase_parse_arguments(state)
1129 options, newargs, user_settings = phase_parse_arguments(state)
11251130
11261131 if 'EMMAKEN_NO_SDK' in os.environ:
11271132 exit_with_error('EMMAKEN_NO_SDK is no longer supported. The standard -nostdlib and -nostdinc flags should be used instead')
11371142 # settings until we reach the linking phase.
11381143 settings.limit_settings(COMPILE_TIME_SETTINGS)
11391144
1140 newargs, input_files = phase_setup(options, state, newargs, settings_map)
1145 newargs, input_files = phase_setup(options, state, newargs, user_settings)
11411146
11421147 if state.mode == Mode.POST_LINK_ONLY:
11431148 settings.limit_settings(None)
1144 target, wasm_target = phase_linker_setup(options, state, newargs, settings_map)
1149 target, wasm_target = phase_linker_setup(options, state, newargs, user_settings)
11451150 process_libraries(state, [])
11461151 if len(input_files) != 1:
11471152 exit_with_error('--post-link requires a single input file')
11661171 if options.output_file and options.output_file.startswith('-'):
11671172 exit_with_error(f'invalid output filename: `{options.output_file}`')
11681173
1169 target, wasm_target = phase_linker_setup(options, state, newargs, settings_map)
1174 target, wasm_target = phase_linker_setup(options, state, newargs, user_settings)
11701175
11711176 # Link object files using wasm-ld or llvm-link (for bitcode linking)
11721177 linker_arguments = phase_calculate_linker_inputs(options, state, linker_inputs)
12761281
12771282
12781283 @ToolchainProfiler.profile_block('setup')
1279 def phase_setup(options, state, newargs, settings_map):
1284 def phase_setup(options, state, newargs, user_settings):
12801285 """Second phase: configure and setup the compiler based on the specified settings and arguments.
12811286 """
12821287
12841289 diagnostics.warning('deprecated', 'RUNTIME_LINKED_LIBS is deprecated; you can simply list the libraries directly on the commandline now')
12851290 newargs += settings.RUNTIME_LINKED_LIBS
12861291
1287 def default_setting(name, new_default):
1288 if name not in settings_map:
1289 setattr(settings, name, new_default)
1290
12911292 if settings.STRICT:
1292 default_setting('DEFAULT_TO_CXX', 0)
1293 default_setting(user_settings, 'DEFAULT_TO_CXX', 0)
12931294
12941295 # Find input files
12951296
13971398 state.mode = Mode.COMPILE_ONLY
13981399
13991400 if state.mode in (Mode.COMPILE_ONLY, Mode.PREPROCESS_ONLY):
1400 for key in settings_map:
1401 for key in user_settings:
14011402 if key not in COMPILE_TIME_SETTINGS:
14021403 diagnostics.warning(
14031404 'unused-command-line-argument',
14331434 if settings.USE_PTHREADS and '-pthread' not in newargs:
14341435 newargs += ['-pthread']
14351436
1436 if 'DISABLE_EXCEPTION_CATCHING' in settings_map and 'EXCEPTION_CATCHING_ALLOWED' in settings_map:
1437 if 'DISABLE_EXCEPTION_CATCHING' in user_settings and 'EXCEPTION_CATCHING_ALLOWED' in user_settings:
14371438 # If we get here then the user specified both DISABLE_EXCEPTION_CATCHING and EXCEPTION_CATCHING_ALLOWED
14381439 # on the command line. This is no longer valid so report either an error or a warning (for
14391440 # backwards compat with the old `DISABLE_EXCEPTION_CATCHING=2`
1440 if settings_map['DISABLE_EXCEPTION_CATCHING'] in ('0', '2'):
1441 if user_settings['DISABLE_EXCEPTION_CATCHING'] in ('0', '2'):
14411442 diagnostics.warning('deprecated', 'DISABLE_EXCEPTION_CATCHING=X is no longer needed when specifying EXCEPTION_CATCHING_ALLOWED')
14421443 else:
14431444 exit_with_error('DISABLE_EXCEPTION_CATCHING and EXCEPTION_CATCHING_ALLOWED are mutually exclusive')
14591460 # Wasm SjLj cannot be used with Emscripten EH. We error out if
14601461 # DISABLE_EXCEPTION_THROWING=0 is explicitly requested by the user;
14611462 # otherwise we disable it here.
1462 default_setting('DISABLE_EXCEPTION_THROWING', 1)
1463 default_setting(user_settings, 'DISABLE_EXCEPTION_THROWING', 1)
14631464 if not settings.DISABLE_EXCEPTION_THROWING:
14641465 exit_with_error('SUPPORT_LONGJMP=wasm cannot be used with DISABLE_EXCEPTION_CATCHING=0')
14651466 # We error out for DISABLE_EXCEPTION_CATCHING=0, because it is 1 by default
14711472
14721473
14731474 @ToolchainProfiler.profile_block('linker_setup')
1474 def phase_linker_setup(options, state, newargs, settings_map):
1475 def phase_linker_setup(options, state, newargs, user_settings):
14751476 autoconf = os.environ.get('EMMAKEN_JUST_CONFIGURE') or 'conftest.c' in state.orig_args
14761477 if autoconf:
14771478 # configure tests want a more shell-like style, where we emit return codes on exit()
14851486 for f in ldflags:
14861487 add_link_flag(state, sys.maxsize, f)
14871488
1488 def default_setting(name, new_default):
1489 if name not in settings_map:
1490 setattr(settings, name, new_default)
1491
14921489 if settings.OPT_LEVEL >= 1:
1493 default_setting('ASSERTIONS', 0)
1490 default_setting(user_settings, 'ASSERTIONS', 0)
14941491
14951492 if options.emrun:
14961493 options.pre_js.append(utils.path_from_root('src/emrun_prejs.js'))
16261623 # reactor.
16271624 # 2. If the user doesn't export anything we default to exporting `_main` (unless `--no-entry`
16281625 # is specified (see above).
1629 if 'EXPORTED_FUNCTIONS' in settings_map:
1626 if 'EXPORTED_FUNCTIONS' in user_settings:
16301627 if '_main' not in settings.USER_EXPORTED_FUNCTIONS:
16311628 settings.EXPECT_MAIN = 0
16321629 else:
16381635 # See https://github.com/WebAssembly/WASI/blob/main/design/application-abi.md
16391636 # For a command we always want EXIT_RUNTIME=1
16401637 # For a reactor we always want EXIT_RUNTIME=0
1641 if 'EXIT_RUNTIME' in settings_map:
1638 if 'EXIT_RUNTIME' in user_settings:
16421639 exit_with_error('Explictly setting EXIT_RUNTIME not compatible with STANDALONE_WASM. EXIT_RUNTIME will always be True for programs (with a main function) and False for reactors (not main function).')
16431640 settings.EXIT_RUNTIME = settings.EXPECT_MAIN
16441641
16521649 # libraries because STACK_OVERFLOW_CHECK depends on emscripten_stack_get_end which is defined
16531650 # in libcompiler-rt.
16541651 if not settings.PURE_WASI and '-nostdlib' not in newargs and '-nodefaultlibs' not in newargs:
1655 default_setting('STACK_OVERFLOW_CHECK', max(settings.ASSERTIONS, settings.STACK_OVERFLOW_CHECK))
1652 default_setting(user_settings, 'STACK_OVERFLOW_CHECK', max(settings.ASSERTIONS, settings.STACK_OVERFLOW_CHECK))
16561653
16571654 if settings.LLD_REPORT_UNDEFINED or settings.STANDALONE_WASM:
16581655 # Reporting undefined symbols at wasm-ld time requires us to know if we have a `main` function
16621659
16631660 # For users that opt out of WARN_ON_UNDEFINED_SYMBOLS we assume they also
16641661 # want to opt out of ERROR_ON_UNDEFINED_SYMBOLS.
1665 if settings_map.get('WARN_ON_UNDEFINED_SYMBOLS') == '0':
1666 default_setting('ERROR_ON_UNDEFINED_SYMBOLS', 0)
1662 if user_settings.get('WARN_ON_UNDEFINED_SYMBOLS') == '0':
1663 default_setting(user_settings, 'ERROR_ON_UNDEFINED_SYMBOLS', 0)
16671664
16681665 # It is unlikely that developers targeting "native web" APIs with MINIMAL_RUNTIME need
16691666 # errno support by default.
16701667 if settings.MINIMAL_RUNTIME:
1671 default_setting('SUPPORT_ERRNO', 0)
1668 default_setting(user_settings, 'SUPPORT_ERRNO', 0)
16721669 # Require explicit -lfoo.js flags to link with JS libraries.
1673 default_setting('AUTO_JS_LIBRARIES', 0)
1670 default_setting(user_settings, 'AUTO_JS_LIBRARIES', 0)
16741671
16751672 if settings.STRICT:
1676 default_setting('STRICT_JS', 1)
1677 default_setting('AUTO_JS_LIBRARIES', 0)
1678 default_setting('AUTO_NATIVE_LIBRARIES', 0)
1679 default_setting('AUTO_ARCHIVE_INDEXES', 0)
1680 default_setting('IGNORE_MISSING_MAIN', 0)
1681 default_setting('ALLOW_UNIMPLEMENTED_SYSCALLS', 0)
1673 default_setting(user_settings, 'STRICT_JS', 1)
1674 default_setting(user_settings, 'AUTO_JS_LIBRARIES', 0)
1675 default_setting(user_settings, 'AUTO_NATIVE_LIBRARIES', 0)
1676 default_setting(user_settings, 'AUTO_ARCHIVE_INDEXES', 0)
1677 default_setting(user_settings, 'IGNORE_MISSING_MAIN', 0)
1678 default_setting(user_settings, 'ALLOW_UNIMPLEMENTED_SYSCALLS', 0)
16821679
16831680 if not settings.AUTO_JS_LIBRARIES:
1684 default_setting('USE_SDL', 0)
1681 default_setting(user_settings, 'USE_SDL', 0)
16851682
16861683 # Default to TEXTDECODER=2 (always use TextDecoder to decode UTF-8 strings)
16871684 # in -Oz builds, since custom decoder for UTF-8 takes up space.
16911688 # widely supported there.
16921689 if settings.SHRINK_LEVEL >= 2 and not settings.USE_PTHREADS and \
16931690 not settings.ENVIRONMENT_MAY_BE_SHELL:
1694 default_setting('TEXTDECODER', 2)
1691 default_setting(user_settings, 'TEXTDECODER', 2)
16951692
16961693 # If set to 1, we will run the autodebugger (the automatic debugging tool, see
16971694 # tools/autodebugger). Note that this will disable inclusion of libraries. This
17451742 # If we are including the entire JS library then we know for sure we will, by definition,
17461743 # require all the reverse dependencies.
17471744 if settings.INCLUDE_FULL_LIBRARY:
1748 default_setting('REVERSE_DEPS', 'all')
1745 default_setting(user_settings, 'REVERSE_DEPS', 'all')
17491746
17501747 if settings.MAIN_MODULE == 1 or settings.SIDE_MODULE == 1:
17511748 settings.LINKABLE = 1
19101907
19111908 # MIN_WEBGL_VERSION=2 implies MAX_WEBGL_VERSION=2
19121909 if settings.MIN_WEBGL_VERSION == 2:
1913 default_setting('MAX_WEBGL_VERSION', 2)
1910 default_setting(user_settings, 'MAX_WEBGL_VERSION', 2)
19141911
19151912 if settings.MIN_WEBGL_VERSION > settings.MAX_WEBGL_VERSION:
19161913 exit_with_error('MIN_WEBGL_VERSION must be smaller or equal to MAX_WEBGL_VERSION!')
19691966 if settings.RELOCATABLE and not settings.DYNAMIC_EXECUTION:
19701967 exit_with_error('cannot have both DYNAMIC_EXECUTION=0 and RELOCATABLE enabled at the same time, since RELOCATABLE needs to eval()')
19711968
1972 if settings.SIDE_MODULE and 'GLOBAL_BASE' in settings_map:
1969 if settings.SIDE_MODULE and 'GLOBAL_BASE' in user_settings:
19731970 exit_with_error('Cannot set GLOBAL_BASE when building SIDE_MODULE')
19741971
19751972 # When building a side module we currently have to assume that any undefined
19761973 # symbols that exist at link time will be satisfied by the main module or JS.
19771974 if settings.SIDE_MODULE:
1978 default_setting('ERROR_ON_UNDEFINED_SYMBOLS', 0)
1979 default_setting('WARN_ON_UNDEFINED_SYMBOLS', 0)
1975 default_setting(user_settings, 'ERROR_ON_UNDEFINED_SYMBOLS', 0)
1976 default_setting(user_settings, 'WARN_ON_UNDEFINED_SYMBOLS', 0)
19801977
19811978 if options.use_preload_plugins or len(options.preload_files) or len(options.embed_files):
19821979 if settings.NODERAWFS:
20282025 # the behavior of trying to grow and returning 0 from malloc on failure, like
20292026 # a standard system would. However, if the user sets the flag it
20302027 # overrides that.
2031 default_setting('ABORTING_MALLOC', 0)
2028 default_setting(user_settings, 'ABORTING_MALLOC', 0)
20322029
20332030 if settings.USE_PTHREADS:
20342031 if settings.USE_PTHREADS == 2:
21602157 if settings.MEMORY_GROWTH_LINEAR_STEP != -1:
21612158 check_memory_setting('MEMORY_GROWTH_LINEAR_STEP')
21622159
2163 if 'MAXIMUM_MEMORY' in settings_map and not settings.ALLOW_MEMORY_GROWTH:
2160 if 'MAXIMUM_MEMORY' in user_settings and not settings.ALLOW_MEMORY_GROWTH:
21642161 diagnostics.warning('unused-command-line-argument', 'MAXIMUM_MEMORY is only meaningful with ALLOW_MEMORY_GROWTH')
21652162
21662163 if settings.EXPORT_ES6 and not settings.MODULARIZE:
21672164 # EXPORT_ES6 requires output to be a module
2168 if 'MODULARIZE' in settings_map:
2165 if 'MODULARIZE' in user_settings:
21692166 exit_with_error('EXPORT_ES6 requires MODULARIZE to be set')
21702167 settings.MODULARIZE = 1
21712168
22532250 if options.use_closure_compiler == 2 and not settings.WASM2JS:
22542251 exit_with_error('closure compiler mode 2 assumes the code is asm.js, so not meaningful for wasm')
22552252
2256 if 'MEM_INIT_METHOD' in settings_map:
2253 if 'MEM_INIT_METHOD' in user_settings:
22572254 exit_with_error('MEM_INIT_METHOD is not supported in wasm. Memory will be embedded in the wasm binary if threads are not used, and included in a separate file if threads are used.')
22582255
22592256 if settings.WASM2JS:
23152312
23162313 if 'leak' in sanitize:
23172314 settings.USE_LSAN = 1
2318 default_setting('EXIT_RUNTIME', 1)
2315 default_setting(user_settings, 'EXIT_RUNTIME', 1)
23192316
23202317 if settings.RELOCATABLE:
23212318 exit_with_error('LSan does not support dynamic linking')
23222319
23232320 if 'address' in sanitize:
23242321 settings.USE_ASAN = 1
2325 default_setting('EXIT_RUNTIME', 1)
2322 default_setting(user_settings, 'EXIT_RUNTIME', 1)
23262323 if not settings.UBSAN_RUNTIME:
23272324 settings.UBSAN_RUNTIME = 2
23282325
23572354 if settings.ASAN_SHADOW_SIZE != -1:
23582355 diagnostics.warning('emcc', 'ASAN_SHADOW_SIZE is ignored and will be removed in a future release')
23592356
2360 if 'GLOBAL_BASE' in settings_map:
2357 if 'GLOBAL_BASE' in user_settings:
23612358 exit_with_error("ASan does not support custom GLOBAL_BASE")
23622359
23632360 # Increase the TOTAL_MEMORY and shift GLOBAL_BASE to account for
25032500 # Any "pointers" passed to JS will now be i64's, in both modes.
25042501 # Also turn off minifying, which clashes with instrumented functions in preamble.js
25052502 if settings.MEMORY64:
2506 if settings_map.get('WASM_BIGINT') == '0':
2503 if user_settings.get('WASM_BIGINT') == '0':
25072504 exit_with_error('MEMORY64 is not compatible with WASM_BIGINT=0')
25082505 settings.WASM_BIGINT = 1
25092506 settings.MINIFY_WASM_IMPORTS_AND_EXPORTS = 0