3232from .shared import LLVM_DWARFDUMP , demangle_c_symbol_name
3333from .shared import get_emscripten_temp_dir , exe_suffix , is_c_symbol
3434from .utils import WINDOWS
35- from .settings import settings , default_setting
35+ from .settings import settings
3636from .feature_matrix import UNSUPPORTED
3737
3838logger = logging .getLogger ('building' )
4646user_requested_exports : Set [str ] = set ()
4747
4848
49- # .. but for Popen, we cannot have doublequotes, so provide functionality to
50- # remove them when needed.
51- def remove_quotes (arg ):
52- if isinstance (arg , list ):
53- return [remove_quotes (a ) for a in arg ]
54-
55- if arg .startswith ('"' ) and arg .endswith ('"' ):
56- return arg [1 :- 1 ].replace ('\\ "' , '"' )
57- elif arg .startswith ("'" ) and arg .endswith ("'" ):
58- return arg [1 :- 1 ].replace ("\\ '" , "'" )
59- else :
60- return arg
61-
62-
6349def get_building_env ():
6450 cache .ensure ()
6551 env = os .environ .copy ()
@@ -1063,34 +1049,15 @@ def handle_final_wasm_symbols(wasm_file, symbols_file, debug_info):
10631049
10641050
10651051def is_ar (filename ):
1052+ """Return True if a the given filename is an ar archive, False otherwise.
1053+ """
10661054 try :
1067- if _is_ar_cache .get (filename ):
1068- return _is_ar_cache [filename ]
10691055 header = open (filename , 'rb' ).read (8 )
1070- sigcheck = header in (b'!<arch>\n ' , b'!<thin>\n ' )
1071- _is_ar_cache [filename ] = sigcheck
1072- return sigcheck
10731056 except Exception as e :
10741057 logger .debug ('is_ar failed to test whether file \' %s\' is a llvm archive file! Failed on exception: %s' % (filename , e ))
10751058 return False
10761059
1077-
1078- def is_bitcode (filename ):
1079- try :
1080- # look for magic signature
1081- b = open (filename , 'rb' ).read (4 )
1082- if b [:2 ] == b'BC' :
1083- return True
1084- # on macOS, there is a 20-byte prefix which starts with little endian
1085- # encoding of 0x0B17C0DE
1086- elif b == b'\xDE \xC0 \x17 \x0B ' :
1087- b = bytearray (open (filename , 'rb' ).read (22 ))
1088- return b [20 :] == b'BC'
1089- except IndexError :
1090- # not enough characters in the input
1091- # note that logging will be done on the caller function
1092- pass
1093- return False
1060+ return header in (b'!<arch>\n ' , b'!<thin>\n ' )
10941061
10951062
10961063def is_wasm (filename ):
@@ -1113,85 +1080,6 @@ def is_wasm_dylib(filename):
11131080 return False
11141081
11151082
1116- def map_to_js_libs (library_name ):
1117- """Given the name of a special Emscripten-implemented system library, returns an
1118- pair containing
1119- 1. Array of absolute paths to JS library files, inside emscripten/src/ that corresponds to the
1120- library name. `None` means there is no mapping and the library will be processed by the linker
1121- as a require for normal native library.
1122- 2. Optional name of a corresponding native library to link in.
1123- """
1124- # Some native libraries are implemented in Emscripten as system side JS libraries
1125- library_map = {
1126- 'embind' : ['embind/embind.js' , 'embind/emval.js' ],
1127- 'EGL' : ['library_egl.js' ],
1128- 'GL' : ['library_webgl.js' , 'library_html5_webgl.js' ],
1129- 'webgl.js' : ['library_webgl.js' , 'library_html5_webgl.js' ],
1130- 'GLESv2' : ['library_webgl.js' ],
1131- # N.b. there is no GLESv3 to link to (note [f] in https://www.khronos.org/registry/implementers_guide.html)
1132- 'GLEW' : ['library_glew.js' ],
1133- 'glfw' : ['library_glfw.js' ],
1134- 'glfw3' : ['library_glfw.js' ],
1135- 'GLU' : [],
1136- 'glut' : ['library_glut.js' ],
1137- 'openal' : ['library_openal.js' ],
1138- 'X11' : ['library_xlib.js' ],
1139- 'SDL' : ['library_sdl.js' ],
1140- 'uuid' : ['library_uuid.js' ],
1141- 'fetch' : ['library_fetch.js' ],
1142- 'websocket' : ['library_websocket.js' ],
1143- # These 4 libraries are separate under glibc but are all rolled into
1144- # libc with musl. For compatibility with glibc we just ignore them
1145- # completely.
1146- 'dl' : [],
1147- 'm' : [],
1148- 'rt' : [],
1149- 'pthread' : [],
1150- # This is the name of GNU's C++ standard library. We ignore it here
1151- # for compatibility with GNU toolchains.
1152- 'stdc++' : [],
1153- }
1154- settings_map = {
1155- 'glfw' : {'USE_GLFW' : 2 },
1156- 'glfw3' : {'USE_GLFW' : 3 },
1157- 'SDL' : {'USE_SDL' : 1 },
1158- }
1159-
1160- if library_name in settings_map :
1161- for key , value in settings_map [library_name ].items ():
1162- default_setting (key , value )
1163-
1164- if library_name in library_map :
1165- libs = library_map [library_name ]
1166- logger .debug ('Mapping library `%s` to JS libraries: %s' % (library_name , libs ))
1167- return libs
1168-
1169- if library_name .endswith ('.js' ) and os .path .isfile (path_from_root ('src' , f'library_{ library_name } ' )):
1170- return [f'library_{ library_name } ' ]
1171-
1172- return None
1173-
1174-
1175- # Map a linker flag to a settings. This lets a user write -lSDL2 and it will
1176- # have the same effect as -sUSE_SDL=2.
1177- def map_and_apply_to_settings (library_name ):
1178- # most libraries just work, because the -l name matches the name of the
1179- # library we build. however, if a library has variations, which cause us to
1180- # build multiple versions with multiple names, then we need this mechanism.
1181- library_map = {
1182- # SDL2_mixer's built library name contains the specific codecs built in.
1183- 'SDL2_mixer' : [('USE_SDL_MIXER' , 2 )],
1184- }
1185-
1186- if library_name in library_map :
1187- for key , value in library_map [library_name ]:
1188- logger .debug ('Mapping library `%s` to settings changes: %s = %s' % (library_name , key , value ))
1189- setattr (settings , key , value )
1190- return True
1191-
1192- return False
1193-
1194-
11951083def emit_wasm_source_map (wasm_file , map_file , final_wasm ):
11961084 # source file paths must be relative to the location of the map (which is
11971085 # emitted alongside the wasm)
0 commit comments