@@ -60,17 +60,18 @@ def write_output_file(outfile, module):
60
60
outfile .write (module [i ])
61
61
62
62
63
- def optimize_syscalls ( declares ):
63
+ def maybe_disable_filesystem ( imports ):
64
64
"""Disables filesystem if only a limited subset of syscalls is used.
65
65
66
66
Our syscalls are static, and so if we see a very limited set of them - in particular,
67
67
no open() syscall and just simple writing - then we don't need full filesystem support.
68
68
If FORCE_FILESYSTEM is set, we can't do this. We also don't do it if INCLUDE_FULL_LIBRARY, since
69
69
not including the filesystem would mean not including the full JS libraries, and the same for
70
- MAIN_MODULE since a side module might need the filesystem.
70
+ MAIN_MODULE=1 since a side module might need the filesystem.
71
71
"""
72
- relevant_settings = ['FORCE_FILESYSTEM' , 'INCLUDE_FULL_LIBRARY' , 'MAIN_MODULE' ]
73
- if any (settings [s ] for s in relevant_settings ):
72
+ if any (settings [s ] for s in ['FORCE_FILESYSTEM' , 'INCLUDE_FULL_LIBRARY' ]):
73
+ return
74
+ if settings .MAIN_MODULE == 1 :
74
75
return
75
76
76
77
if settings .FILESYSTEM == 0 :
@@ -79,7 +80,9 @@ def optimize_syscalls(declares):
79
80
else :
80
81
# TODO(sbc): Find a better way to identify wasi syscalls
81
82
syscall_prefixes = ('__syscall_' , 'fd_' )
82
- syscalls = {d for d in declares if d .startswith (syscall_prefixes ) or d in ['path_open' ]}
83
+ side_module_imports = [shared .demangle_c_symbol_name (s ) for s in settings .SIDE_MODULE_IMPORTS ]
84
+ all_imports = set (imports ).union (side_module_imports )
85
+ syscalls = {d for d in all_imports if d .startswith (syscall_prefixes ) or d in ['path_open' ]}
83
86
# check if the only filesystem syscalls are in: close, ioctl, llseek, write
84
87
# (without open, etc.. nothing substantial can be done, so we can disable
85
88
# extra filesystem support in that case)
@@ -116,7 +119,7 @@ def get_weak_imports(main_wasm):
116
119
117
120
118
121
def update_settings_glue (wasm_file , metadata ):
119
- optimize_syscalls (metadata .imports )
122
+ maybe_disable_filesystem (metadata .imports )
120
123
121
124
# Integrate info from backend
122
125
if settings .SIDE_MODULE :
0 commit comments