@@ -1240,7 +1240,7 @@ def phase_linker_setup(options, state): # noqa: C901, PLR0912, PLR0915
12401240 state .append_link_flag ('--no-whole-archive' )
12411241 settings .FILESYSTEM = 1
12421242 settings .SYSCALLS_REQUIRE_FILESYSTEM = 0
1243- settings .JS_LIBRARIES .append (( 0 , 'library_wasmfs.js' ) )
1243+ settings .JS_LIBRARIES .append ('library_wasmfs.js' )
12441244 if settings .ASSERTIONS :
12451245 # used in assertion checks for unflushed content
12461246 settings .REQUIRED_EXPORTS += ['wasmfs_flush' ]
@@ -1362,14 +1362,14 @@ def phase_linker_setup(options, state): # noqa: C901, PLR0912, PLR0915
13621362
13631363 if settings .PTHREADS :
13641364 setup_pthreads ()
1365- settings .JS_LIBRARIES .append (( 0 , 'library_pthread.js' ) )
1365+ settings .JS_LIBRARIES .append ('library_pthread.js' )
13661366 if settings .PROXY_TO_PTHREAD :
13671367 settings .PTHREAD_POOL_SIZE_STRICT = 0
13681368 settings .DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$runtimeKeepalivePush' ]
13691369 else :
13701370 if settings .PROXY_TO_PTHREAD :
13711371 exit_with_error ('-sPROXY_TO_PTHREAD requires -pthread to work!' )
1372- settings .JS_LIBRARIES .append (( 0 , 'library_pthread_stub.js' ) )
1372+ settings .JS_LIBRARIES .append ('library_pthread_stub.js' )
13731373
13741374 if settings .MEMORY64 :
13751375 # Any "pointers" passed to JS will now be i64's, in both modes.
@@ -1383,7 +1383,7 @@ def phase_linker_setup(options, state): # noqa: C901, PLR0912, PLR0915
13831383 # set location of Wasm Worker bootstrap JS file
13841384 if settings .WASM_WORKERS == 1 :
13851385 settings .WASM_WORKER_FILE = unsuffixed (os .path .basename (target )) + '.ww.js'
1386- settings .JS_LIBRARIES .append (( 0 , 'library_wasm_worker.js' ) )
1386+ settings .JS_LIBRARIES .append ('library_wasm_worker.js' )
13871387
13881388 # Set min browser versions based on certain settings such as WASM_BIGINT,
13891389 # PTHREADS, AUDIO_WORKLET
@@ -1401,7 +1401,7 @@ def phase_linker_setup(options, state): # noqa: C901, PLR0912, PLR0915
14011401 if settings .AUDIO_WORKLET :
14021402 if settings .AUDIO_WORKLET == 1 :
14031403 settings .AUDIO_WORKLET_FILE = unsuffixed (os .path .basename (target )) + '.aw.js'
1404- settings .JS_LIBRARIES .append (( 0 , shared .path_from_root ('src' , 'library_webaudio.js' ) ))
1404+ settings .JS_LIBRARIES .append (shared .path_from_root ('src' , 'library_webaudio.js' ))
14051405 if not settings .MINIMAL_RUNTIME :
14061406 # If we are in the audio worklet environment, we can only access the Module object
14071407 # and not the global scope of the main JS script. Therefore we need to export
@@ -2807,12 +2807,15 @@ def map_to_js_libs(library_name):
28072807
28082808def process_libraries (state ):
28092809 new_flags = []
2810- libraries = []
28112810 suffixes = STATICLIB_ENDINGS + DYNAMICLIB_ENDINGS
28122811 system_libs_map = system_libs .Library .get_usable_variations ()
28132812
2814- # Find library files
2813+ # Process `-l` and `--js- library` flags
28152814 for i , flag in state .link_flags :
2815+ if flag .startswith ('--js-library=' ):
2816+ js_lib = os .path .abspath (flag .split ('=' , 1 )[1 ])
2817+ settings .JS_LIBRARIES .append (js_lib )
2818+ continue
28162819 if not flag .startswith ('-l' ):
28172820 new_flags .append ((i , flag ))
28182821 continue
@@ -2822,7 +2825,7 @@ def process_libraries(state):
28222825
28232826 js_libs = map_to_js_libs (lib )
28242827 if js_libs is not None :
2825- libraries += [( i , js_lib ) for js_lib in js_libs ]
2828+ settings . JS_LIBRARIES += js_libs
28262829
28272830 # We don't need to resolve system libraries to absolute paths here, we can just
28282831 # let wasm-ld handle that. However, we do want to map to the correct variant.
@@ -2848,12 +2851,6 @@ def process_libraries(state):
28482851
28492852 new_flags .append ((i , flag ))
28502853
2851- settings .JS_LIBRARIES += libraries
2852-
2853- # At this point processing JS_LIBRARIES is finished, no more items will be added to it.
2854- # Sort the input list from (order, lib_name) pairs to a flat array in the right order.
2855- settings .JS_LIBRARIES .sort (key = lambda lib : lib [0 ])
2856- settings .JS_LIBRARIES = [lib [1 ] for lib in settings .JS_LIBRARIES ]
28572854 state .link_flags = new_flags
28582855
28592856
0 commit comments