From 98ab72c1193196fb7a9a94220e1ad2dd833e1045 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sun, 20 Jul 2025 10:18:44 +0000 Subject: [PATCH 1/2] [wasmfs] Expose wasmfs headers file for out-of-tree filesystems --- .../emscripten/wasmfs_internal}/backend.h | 3 ++- .../wasmfs => include/emscripten/wasmfs_internal}/file.h | 3 ++- .../emscripten/wasmfs_internal}/file_table.h | 3 ++- .../emscripten/wasmfs_internal}/support.h | 0 .../emscripten/wasmfs_internal}/wasmfs.h | 7 ++++--- system/lib/wasmfs/backends/fetch_backend.cpp | 6 +++--- system/lib/wasmfs/backends/fetch_backend.h | 2 +- system/lib/wasmfs/backends/ignore_case_backend.cpp | 6 +++--- system/lib/wasmfs/backends/js_file_backend.cpp | 4 ++-- system/lib/wasmfs/backends/js_file_backend.h | 2 +- system/lib/wasmfs/backends/memory_backend.cpp | 4 ++-- system/lib/wasmfs/backends/node_backend.cpp | 8 ++++---- system/lib/wasmfs/backends/opfs_backend.cpp | 8 ++++---- system/lib/wasmfs/backends/opfs_backend.h | 2 +- system/lib/wasmfs/emscripten.cpp | 6 +++--- system/lib/wasmfs/file.cpp | 4 ++-- system/lib/wasmfs/file_table.cpp | 2 +- system/lib/wasmfs/js_api.cpp | 4 ++-- system/lib/wasmfs/js_impl_backend.h | 6 +++--- system/lib/wasmfs/memory_backend.h | 4 ++-- system/lib/wasmfs/paths.cpp | 4 ++-- system/lib/wasmfs/paths.h | 2 +- system/lib/wasmfs/pipe_backend.h | 4 ++-- system/lib/wasmfs/proxied_async_js_impl_backend.h | 6 +++--- system/lib/wasmfs/special_files.h | 2 +- system/lib/wasmfs/support.cpp | 2 +- system/lib/wasmfs/syscalls.cpp | 8 ++++---- system/lib/wasmfs/virtual.h | 2 +- system/lib/wasmfs/wasmfs.cpp | 2 +- 29 files changed, 60 insertions(+), 56 deletions(-) rename system/{lib/wasmfs => include/emscripten/wasmfs_internal}/backend.h (88%) rename system/{lib/wasmfs => include/emscripten/wasmfs_internal}/file.h (99%) rename system/{lib/wasmfs => include/emscripten/wasmfs_internal}/file_table.h (97%) rename system/{lib/wasmfs => include/emscripten/wasmfs_internal}/support.h (100%) rename system/{lib/wasmfs => include/emscripten/wasmfs_internal}/wasmfs.h (87%) diff --git a/system/lib/wasmfs/backend.h b/system/include/emscripten/wasmfs_internal/backend.h similarity index 88% rename from system/lib/wasmfs/backend.h rename to system/include/emscripten/wasmfs_internal/backend.h index d8e584c01136a..4861968583849 100644 --- a/system/lib/wasmfs/backend.h +++ b/system/include/emscripten/wasmfs_internal/backend.h @@ -4,10 +4,11 @@ // found in the LICENSE file. // This file defines the modular backend abstract class. +// The declarations from this files should only be used by file system implementers #pragma once -#include "file.h" +#include namespace wasmfs { // A backend (or modular backend) provides a base to extend WasmFS with new diff --git a/system/lib/wasmfs/file.h b/system/include/emscripten/wasmfs_internal/file.h similarity index 99% rename from system/lib/wasmfs/file.h rename to system/include/emscripten/wasmfs_internal/file.h index 039d265c21899..160369e353639 100644 --- a/system/lib/wasmfs/file.h +++ b/system/include/emscripten/wasmfs_internal/file.h @@ -4,10 +4,11 @@ // found in the LICENSE file. // This file defines the file object. +// The declarations from this files should only be used by file system implementers #pragma once -#include "support.h" +#include #include #include #include diff --git a/system/lib/wasmfs/file_table.h b/system/include/emscripten/wasmfs_internal/file_table.h similarity index 97% rename from system/lib/wasmfs/file_table.h rename to system/include/emscripten/wasmfs_internal/file_table.h index e85d9b38e07f2..9a75f2b3f5e9d 100644 --- a/system/lib/wasmfs/file_table.h +++ b/system/include/emscripten/wasmfs_internal/file_table.h @@ -4,10 +4,11 @@ // found in the LICENSE file. // This file defines the open file table. +// The declarations from this files should only be used by file system implementers #pragma once -#include "file.h" +#include #include #include #include diff --git a/system/lib/wasmfs/support.h b/system/include/emscripten/wasmfs_internal/support.h similarity index 100% rename from system/lib/wasmfs/support.h rename to system/include/emscripten/wasmfs_internal/support.h diff --git a/system/lib/wasmfs/wasmfs.h b/system/include/emscripten/wasmfs_internal/wasmfs.h similarity index 87% rename from system/lib/wasmfs/wasmfs.h rename to system/include/emscripten/wasmfs_internal/wasmfs.h index 682d53064ee77..1d74bb97e0ad4 100644 --- a/system/lib/wasmfs/wasmfs.h +++ b/system/include/emscripten/wasmfs_internal/wasmfs.h @@ -4,12 +4,13 @@ // found in the LICENSE file. // This file defines the global state. +// The declarations from this files should only be used by file system implementers #pragma once -#include "backend.h" -#include "file.h" -#include "file_table.h" +#include +#include +#include #include #include #include diff --git a/system/lib/wasmfs/backends/fetch_backend.cpp b/system/lib/wasmfs/backends/fetch_backend.cpp index c4cad7f63efa5..c875d070d161a 100644 --- a/system/lib/wasmfs/backends/fetch_backend.cpp +++ b/system/lib/wasmfs/backends/fetch_backend.cpp @@ -5,10 +5,10 @@ // This file defines the fetch backend. -#include "fetch_backend.h" -#include "backend.h" +#include "fetch_backend.h" +#include #include "proxied_async_js_impl_backend.h" -#include "wasmfs.h" +#include namespace wasmfs { diff --git a/system/lib/wasmfs/backends/fetch_backend.h b/system/lib/wasmfs/backends/fetch_backend.h index a5d76859c1451..0a701e46cd49f 100644 --- a/system/lib/wasmfs/backends/fetch_backend.h +++ b/system/lib/wasmfs/backends/fetch_backend.h @@ -3,7 +3,7 @@ // University of Illinois/NCSA Open Source License. Both these licenses can be // found in the LICENSE file. -#include "wasmfs.h" +#include extern "C" { // See library_wasmfs_fetch.js diff --git a/system/lib/wasmfs/backends/ignore_case_backend.cpp b/system/lib/wasmfs/backends/ignore_case_backend.cpp index ba1f1f4e0b72a..8627d546421da 100644 --- a/system/lib/wasmfs/backends/ignore_case_backend.cpp +++ b/system/lib/wasmfs/backends/ignore_case_backend.cpp @@ -13,10 +13,10 @@ // See the comment in virtual.h for an explanation of why DataFiles and Symlinks // must have no-op wrappers. -#include "backend.h" -#include "file.h" +#include +#include #include "virtual.h" -#include "wasmfs.h" +#include namespace { diff --git a/system/lib/wasmfs/backends/js_file_backend.cpp b/system/lib/wasmfs/backends/js_file_backend.cpp index 6c3199a472262..58f8805125b75 100644 --- a/system/lib/wasmfs/backends/js_file_backend.cpp +++ b/system/lib/wasmfs/backends/js_file_backend.cpp @@ -6,9 +6,9 @@ // This file defines the JS file backend. #include "js_file_backend.h" -#include "backend.h" +#include #include "js_impl_backend.h" -#include "wasmfs.h" +#include namespace wasmfs { diff --git a/system/lib/wasmfs/backends/js_file_backend.h b/system/lib/wasmfs/backends/js_file_backend.h index d7d031cfe3d0c..60c24ac69c8f0 100644 --- a/system/lib/wasmfs/backends/js_file_backend.h +++ b/system/lib/wasmfs/backends/js_file_backend.h @@ -3,7 +3,7 @@ // University of Illinois/NCSA Open Source License. Both these licenses can be // found in the LICENSE file. -#include "wasmfs.h" +#include extern "C" { diff --git a/system/lib/wasmfs/backends/memory_backend.cpp b/system/lib/wasmfs/backends/memory_backend.cpp index 6752b3bbbb5bd..fe68e1da6fb17 100644 --- a/system/lib/wasmfs/backends/memory_backend.cpp +++ b/system/lib/wasmfs/backends/memory_backend.cpp @@ -6,8 +6,8 @@ // This file defines the memory file backend. #include "memory_backend.h" -#include "backend.h" -#include "wasmfs.h" +#include +#include namespace wasmfs { diff --git a/system/lib/wasmfs/backends/node_backend.cpp b/system/lib/wasmfs/backends/node_backend.cpp index a3a7ad19b32f3..176ac720db619 100644 --- a/system/lib/wasmfs/backends/node_backend.cpp +++ b/system/lib/wasmfs/backends/node_backend.cpp @@ -5,11 +5,11 @@ #include -#include "backend.h" -#include "file.h" +#include +#include #include "node_backend.h" -#include "support.h" -#include "wasmfs.h" +#include +#include namespace wasmfs { diff --git a/system/lib/wasmfs/backends/opfs_backend.cpp b/system/lib/wasmfs/backends/opfs_backend.cpp index 6a5be884cc38b..a9fc4cc36480a 100644 --- a/system/lib/wasmfs/backends/opfs_backend.cpp +++ b/system/lib/wasmfs/backends/opfs_backend.cpp @@ -6,12 +6,12 @@ #include #include -#include "backend.h" -#include "file.h" +#include +#include #include "opfs_backend.h" -#include "support.h" +#include #include "thread_utils.h" -#include "wasmfs.h" +#include using namespace wasmfs; diff --git a/system/lib/wasmfs/backends/opfs_backend.h b/system/lib/wasmfs/backends/opfs_backend.h index fc484bdd067b9..583b16279c2c7 100644 --- a/system/lib/wasmfs/backends/opfs_backend.h +++ b/system/lib/wasmfs/backends/opfs_backend.h @@ -2,7 +2,7 @@ #include -#include "backend.h" +#include using namespace wasmfs; diff --git a/system/lib/wasmfs/emscripten.cpp b/system/lib/wasmfs/emscripten.cpp index 81f4996a4445f..a8d1533c48a00 100644 --- a/system/lib/wasmfs/emscripten.cpp +++ b/system/lib/wasmfs/emscripten.cpp @@ -16,9 +16,9 @@ #include -#include "file.h" -#include "file_table.h" -#include "wasmfs.h" +#include +#include +#include namespace wasmfs { diff --git a/system/lib/wasmfs/file.cpp b/system/lib/wasmfs/file.cpp index c16af931c7228..72d361ed03af5 100644 --- a/system/lib/wasmfs/file.cpp +++ b/system/lib/wasmfs/file.cpp @@ -5,8 +5,8 @@ // This file defines the file object. -#include "file.h" -#include "wasmfs.h" +#include +#include #include "wasmfs_internal.h" #include diff --git a/system/lib/wasmfs/file_table.cpp b/system/lib/wasmfs/file_table.cpp index 13b8429f40386..5c108fa53e71b 100644 --- a/system/lib/wasmfs/file_table.cpp +++ b/system/lib/wasmfs/file_table.cpp @@ -5,7 +5,7 @@ // This file defines the open file table. -#include "file_table.h" +#include #include "special_files.h" namespace wasmfs { diff --git a/system/lib/wasmfs/js_api.cpp b/system/lib/wasmfs/js_api.cpp index dba5fdb6dd93d..6c130bcb3b5f7 100644 --- a/system/lib/wasmfs/js_api.cpp +++ b/system/lib/wasmfs/js_api.cpp @@ -8,8 +8,8 @@ #include #include -#include "backend.h" -#include "file.h" +#include +#include #include "paths.h" // Some APIs return data using a thread-local allocation that is never freed. diff --git a/system/lib/wasmfs/js_impl_backend.h b/system/lib/wasmfs/js_impl_backend.h index d79fc5abef7d5..5e81674b763dd 100644 --- a/system/lib/wasmfs/js_impl_backend.h +++ b/system/lib/wasmfs/js_impl_backend.h @@ -5,10 +5,10 @@ #pragma once -#include "backend.h" +#include #include "memory_backend.h" -#include "support.h" -#include "wasmfs.h" +#include +#include // // A JS Impl backend has files that are implemented by JS code. Each backend diff --git a/system/lib/wasmfs/memory_backend.h b/system/lib/wasmfs/memory_backend.h index 9da66e296d5a2..ee51cba37fc3b 100644 --- a/system/lib/wasmfs/memory_backend.h +++ b/system/lib/wasmfs/memory_backend.h @@ -8,8 +8,8 @@ #pragma once -#include "backend.h" -#include "file.h" +#include +#include #include namespace wasmfs { diff --git a/system/lib/wasmfs/paths.cpp b/system/lib/wasmfs/paths.cpp index 3d1fbf4c081e8..ebda98a721fd5 100644 --- a/system/lib/wasmfs/paths.cpp +++ b/system/lib/wasmfs/paths.cpp @@ -5,9 +5,9 @@ #include -#include "file.h" +#include #include "paths.h" -#include "wasmfs.h" +#include namespace wasmfs::path { diff --git a/system/lib/wasmfs/paths.h b/system/lib/wasmfs/paths.h index 353c55ae976b4..99abc989d8ad0 100644 --- a/system/lib/wasmfs/paths.h +++ b/system/lib/wasmfs/paths.h @@ -11,7 +11,7 @@ #include #include -#include "file.h" +#include namespace wasmfs::path { diff --git a/system/lib/wasmfs/pipe_backend.h b/system/lib/wasmfs/pipe_backend.h index 3336f28f9dd60..3b56d1bdda944 100644 --- a/system/lib/wasmfs/pipe_backend.h +++ b/system/lib/wasmfs/pipe_backend.h @@ -7,8 +7,8 @@ #include -#include "file.h" -#include "support.h" +#include +#include namespace wasmfs { diff --git a/system/lib/wasmfs/proxied_async_js_impl_backend.h b/system/lib/wasmfs/proxied_async_js_impl_backend.h index e91ec561ef5ff..1f0b97c1c6422 100644 --- a/system/lib/wasmfs/proxied_async_js_impl_backend.h +++ b/system/lib/wasmfs/proxied_async_js_impl_backend.h @@ -5,11 +5,11 @@ #pragma once -#include "backend.h" +#include #include "memory_backend.h" -#include "support.h" +#include #include "thread_utils.h" -#include "wasmfs.h" +#include // // Similar to JSImplBackend, but proxies to another thread where the JS can be diff --git a/system/lib/wasmfs/special_files.h b/system/lib/wasmfs/special_files.h index dcbe21ea55efb..600e7d26ab177 100644 --- a/system/lib/wasmfs/special_files.h +++ b/system/lib/wasmfs/special_files.h @@ -5,7 +5,7 @@ #pragma once -#include "file.h" +#include namespace wasmfs::SpecialFiles { diff --git a/system/lib/wasmfs/support.cpp b/system/lib/wasmfs/support.cpp index adf08aec37a47..ac5b292f4af9d 100644 --- a/system/lib/wasmfs/support.cpp +++ b/system/lib/wasmfs/support.cpp @@ -10,7 +10,7 @@ #include #endif -#include "support.h" +#include namespace wasmfs { diff --git a/system/lib/wasmfs/syscalls.cpp b/system/lib/wasmfs/syscalls.cpp index 64932128d19ad..0b3a2926012b2 100644 --- a/system/lib/wasmfs/syscalls.cpp +++ b/system/lib/wasmfs/syscalls.cpp @@ -26,13 +26,13 @@ #include #include -#include "backend.h" -#include "file.h" -#include "file_table.h" +#include +#include +#include #include "paths.h" #include "pipe_backend.h" #include "special_files.h" -#include "wasmfs.h" +#include // File permission macros for wasmfs. // Used to improve readability compared to those in stat.h diff --git a/system/lib/wasmfs/virtual.h b/system/lib/wasmfs/virtual.h index 238cd2dffc2ac..8da11649e9efc 100644 --- a/system/lib/wasmfs/virtual.h +++ b/system/lib/wasmfs/virtual.h @@ -15,7 +15,7 @@ #pragma once -#include "file.h" +#include namespace wasmfs { diff --git a/system/lib/wasmfs/wasmfs.cpp b/system/lib/wasmfs/wasmfs.cpp index d0b1ad19cea2b..b5b490e94578a 100644 --- a/system/lib/wasmfs/wasmfs.cpp +++ b/system/lib/wasmfs/wasmfs.cpp @@ -10,7 +10,7 @@ #include "memory_backend.h" #include "paths.h" #include "special_files.h" -#include "wasmfs.h" +#include #include "wasmfs_internal.h" namespace wasmfs { From 14bdb6732db2a1287433be9833e99864ec497704 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sat, 26 Jul 2025 08:40:08 +0000 Subject: [PATCH 2/2] Keep wasmfs headers near wasmfs source and use system header copy mechanism --- .../emscripten => lib/wasmfs}/wasmfs_internal/backend.h | 2 +- .../emscripten => lib/wasmfs}/wasmfs_internal/file.h | 2 +- .../emscripten => lib/wasmfs}/wasmfs_internal/file_table.h | 2 +- .../emscripten => lib/wasmfs}/wasmfs_internal/support.h | 0 .../emscripten => lib/wasmfs}/wasmfs_internal/wasmfs.h | 6 +++--- tools/system_libs.py | 1 + 6 files changed, 7 insertions(+), 6 deletions(-) rename system/{include/emscripten => lib/wasmfs}/wasmfs_internal/backend.h (95%) rename system/{include/emscripten => lib/wasmfs}/wasmfs_internal/file.h (99%) rename system/{include/emscripten => lib/wasmfs}/wasmfs_internal/file_table.h (99%) rename system/{include/emscripten => lib/wasmfs}/wasmfs_internal/support.h (100%) rename system/{include/emscripten => lib/wasmfs}/wasmfs_internal/wasmfs.h (92%) diff --git a/system/include/emscripten/wasmfs_internal/backend.h b/system/lib/wasmfs/wasmfs_internal/backend.h similarity index 95% rename from system/include/emscripten/wasmfs_internal/backend.h rename to system/lib/wasmfs/wasmfs_internal/backend.h index 4861968583849..fdd30402e34ae 100644 --- a/system/include/emscripten/wasmfs_internal/backend.h +++ b/system/lib/wasmfs/wasmfs_internal/backend.h @@ -8,7 +8,7 @@ #pragma once -#include +#include "file.h" namespace wasmfs { // A backend (or modular backend) provides a base to extend WasmFS with new diff --git a/system/include/emscripten/wasmfs_internal/file.h b/system/lib/wasmfs/wasmfs_internal/file.h similarity index 99% rename from system/include/emscripten/wasmfs_internal/file.h rename to system/lib/wasmfs/wasmfs_internal/file.h index 160369e353639..705730d9b30e1 100644 --- a/system/include/emscripten/wasmfs_internal/file.h +++ b/system/lib/wasmfs/wasmfs_internal/file.h @@ -8,7 +8,7 @@ #pragma once -#include +#include "support.h" #include #include #include diff --git a/system/include/emscripten/wasmfs_internal/file_table.h b/system/lib/wasmfs/wasmfs_internal/file_table.h similarity index 99% rename from system/include/emscripten/wasmfs_internal/file_table.h rename to system/lib/wasmfs/wasmfs_internal/file_table.h index 9a75f2b3f5e9d..cfd4f6c996b95 100644 --- a/system/include/emscripten/wasmfs_internal/file_table.h +++ b/system/lib/wasmfs/wasmfs_internal/file_table.h @@ -8,7 +8,7 @@ #pragma once -#include +#include "file.h" #include #include #include diff --git a/system/include/emscripten/wasmfs_internal/support.h b/system/lib/wasmfs/wasmfs_internal/support.h similarity index 100% rename from system/include/emscripten/wasmfs_internal/support.h rename to system/lib/wasmfs/wasmfs_internal/support.h diff --git a/system/include/emscripten/wasmfs_internal/wasmfs.h b/system/lib/wasmfs/wasmfs_internal/wasmfs.h similarity index 92% rename from system/include/emscripten/wasmfs_internal/wasmfs.h rename to system/lib/wasmfs/wasmfs_internal/wasmfs.h index 1d74bb97e0ad4..dc8480cd23835 100644 --- a/system/include/emscripten/wasmfs_internal/wasmfs.h +++ b/system/lib/wasmfs/wasmfs_internal/wasmfs.h @@ -8,9 +8,9 @@ #pragma once -#include -#include -#include +#include "backend.h" +#include "file.h" +#include "file_table.h" #include #include #include diff --git a/tools/system_libs.py b/tools/system_libs.py index 675f4dfead1e2..b417cf0a77162 100644 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -2499,6 +2499,7 @@ def safe_copytree(src, dst): def install_system_headers(stamp): install_dirs = { ('include',): '', + ('lib','wasmfs', 'wasmfs_internal'): 'emscripten/wasmfs_internal', ('lib', 'compiler-rt', 'include'): '', ('lib', 'libunwind', 'include'): '', # Copy the generic arch files first then