Skip to content

Commit c5e53c4

Browse files
authored
WasmFS: Force-include FS only when FORCE_FILESYSTEM (#19511)
This just applies the principle consistently. The only issues in the test suite were 3 tests that did manual FS.* operations without setting FORCE_FILESYSTEM, so add that to them. As the test updates show this helps with code size (removing unused JS helps by itself, and also helps metadce remove wasm things that the JS was pointing to).
1 parent 1ddccf1 commit c5e53c4

17 files changed

+22
-46
lines changed

src/library_fs.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,3 @@ FS.staticInit();` +
18701870
#endif
18711871
},
18721872
});
1873-
1874-
if (FORCE_FILESYSTEM) {
1875-
DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push('$FS');
1876-
}

src/library_fs_shared.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,11 @@ mergeInto(LibraryManager.library, {
105105
if (canWrite) mode |= {{{ cDefs.S_IWUGO }}};
106106
return mode;
107107
},
108-
109108
});
109+
110+
// Normally only the FS things that the compiler sees are needed are included.
111+
// FORCE_FILESYSTEM makes us always include the FS object, which lets the user
112+
// call APIs on it from JS freely.
113+
if (FORCE_FILESYSTEM) {
114+
DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push('$FS');
115+
}

src/library_wasmfs.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,5 @@ FS.createPreloadedFile = FS_createPreloadedFile;
331331
},
332332
_wasmfs_copy_preloaded_file_data: function(index, buffer) {
333333
HEAPU8.set(wasmFSPreloadedFiles[index].fileData, buffer);
334-
}
334+
},
335335
});
336-
337-
DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push('$FS');
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
13082
1+
12960

test/other/metadce/test_metadce_files_wasmfs.exports

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,3 @@ q
22
r
33
s
44
t
5-
u
6-
v
7-
w
8-
x
9-
y

test/other/metadce/test_metadce_files_wasmfs.funcs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ $__pthread_mutex_lock
2929
$__stdio_close
3030
$__stdio_seek
3131
$__stdio_write
32-
$__syscall_newfstatat
3332
$__time
3433
$__unlockfile
3534
$__wasi_fd_close
3635
$__wasi_fd_write
3736
$__wasm_call_ctors
38-
$_wasmfs_read_file
3937
$close
4038
$decltype\28auto\29\20std::__2::__variant_detail::__visitation::__base::__dispatcher<1ul>::__dispatch\5babi:v160004\5d<std::__2::__variant_detail::__dtor<std::__2::__variant_detail::__traits<long\2c\20std::__2::shared_ptr<wasmfs::File>>\2c\20\28std::__2::__variant_detail::_Trait\291>::__destroy\5babi:v160004\5d\28\29::'lambda'\28auto&\29&&\2c\20std::__2::__variant_detail::__base<\28std::__2::__variant_detail::_Trait\291\2c\20long\2c\20std::__2::shared_ptr<wasmfs::File>>&>\28auto\2c\20std::__2::__variant_detail::__base<\28std::__2::__variant_detail::_Trait\291\2c\20long\2c\20std::__2::shared_ptr<wasmfs::File>>&\29
4139
$dlfree
@@ -51,9 +49,6 @@ $operator\20new\28unsigned\20long\29
5149
$pthread_mutex_init
5250
$readAtOffset\28OffsetHandling\2c\20unsigned\20int\2c\20__wasi_iovec_t\20const*\2c\20unsigned\20long\2c\20unsigned\20long*\2c\20unsigned\20long\20long\29
5351
$sbrk
54-
$stackAlloc
55-
$stackRestore
56-
$stackSave
5752
$std::__2::__shared_ptr_emplace<wasmfs::MemoryDataFile\2c\20std::__2::allocator<wasmfs::MemoryDataFile>>::~__shared_ptr_emplace\28\29
5853
$std::__2::__shared_ptr_emplace<wasmfs::MemoryDataFile\2c\20std::__2::allocator<wasmfs::MemoryDataFile>>::~__shared_ptr_emplace\28\29.1
5954
$std::__2::__shared_ptr_emplace<wasmfs::MemoryDirectory\2c\20std::__2::allocator<wasmfs::MemoryDirectory>>::__on_zero_shared\28\29
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7061
1+
6940
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
50559
1+
49396

test/other/metadce/test_metadce_hello_wasmfs.exports

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,3 @@ q
22
r
33
s
44
t
5-
u
6-
v
7-
w
8-
x
9-
y

test/other/metadce/test_metadce_hello_wasmfs.funcs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ $__pthread_mutex_lock
3131
$__stdio_close
3232
$__stdio_seek
3333
$__stdio_write
34-
$__syscall_newfstatat
3534
$__time
3635
$__towrite
3736
$__unlockfile
3837
$__wasi_fd_close
3938
$__wasi_fd_write
4039
$__wasm_call_ctors
41-
$_wasmfs_read_file
4240
$decltype\28auto\29\20std::__2::__variant_detail::__visitation::__base::__dispatcher<1ul>::__dispatch\5babi:v160004\5d<std::__2::__variant_detail::__dtor<std::__2::__variant_detail::__traits<long\2c\20std::__2::shared_ptr<wasmfs::File>>\2c\20\28std::__2::__variant_detail::_Trait\291>::__destroy\5babi:v160004\5d\28\29::'lambda'\28auto&\29&&\2c\20std::__2::__variant_detail::__base<\28std::__2::__variant_detail::_Trait\291\2c\20long\2c\20std::__2::shared_ptr<wasmfs::File>>&>\28auto\2c\20std::__2::__variant_detail::__base<\28std::__2::__variant_detail::_Trait\291\2c\20long\2c\20std::__2::shared_ptr<wasmfs::File>>&\29
4341
$dlfree
4442
$dlmalloc
@@ -51,9 +49,6 @@ $memmove
5149
$operator\20new\28unsigned\20long\29
5250
$pthread_mutex_init
5351
$sbrk
54-
$stackAlloc
55-
$stackRestore
56-
$stackSave
5752
$std::__2::__shared_ptr_emplace<wasmfs::MemoryDataFile\2c\20std::__2::allocator<wasmfs::MemoryDataFile>>::~__shared_ptr_emplace\28\29
5853
$std::__2::__shared_ptr_emplace<wasmfs::MemoryDataFile\2c\20std::__2::allocator<wasmfs::MemoryDataFile>>::~__shared_ptr_emplace\28\29.1
5954
$std::__2::__shared_ptr_emplace<wasmfs::MemoryDirectory\2c\20std::__2::allocator<wasmfs::MemoryDirectory>>::__on_zero_shared\28\29

0 commit comments

Comments
 (0)