Mount the filesystem when running on node.js

Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
Username404 2022-12-04 13:50:12 +01:00
parent bf94b8c6eb
commit d1ebbda173
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
3 changed files with 21 additions and 1 deletions

View File

@ -78,7 +78,7 @@ if (${IS_GNU} OR ${IS_CLANG})
else() else()
set(IS_HOST_NOT_ANDROID 0) set(IS_HOST_NOT_ANDROID 0)
endif() endif()
set(CMAKE_EXE_LINKER_FLAGS "--closure 1 -sWASM=0 --memory-init-file 0 -sEXPORTED_FUNCTIONS=_main -sEXIT_RUNTIME=1 -sSINGLE_FILE=1 -sSAFE_HEAP=${IS_HOST_NOT_ANDROID} -sABORTING_MALLOC=0 -sJS_MATH=1 -sENVIRONMENT='web,webview,worker,node,shell' -sNODEJS_CATCH_EXIT=0 -sSTRICT=1 -sMINIMAL_RUNTIME=0 -sDISABLE_EXCEPTION_CATCHING=0 -sALLOW_MEMORY_GROWTH=1 -Wno-pthreads-mem-growth -sMEMORY_GROWTH_GEOMETRIC_STEP=0 -sDECLARE_ASM_MODULE_EXPORTS=0 ${CMAKE_EXE_LINKER_FLAGS}") set(CMAKE_EXE_LINKER_FLAGS "--closure 1 -lnodefs.js -sFORCE_FILESYSTEM=1 -sWASM=0 --memory-init-file 0 -sEXPORTED_FUNCTIONS=_main -sEXIT_RUNTIME=1 -sSINGLE_FILE=1 -sSAFE_HEAP=${IS_HOST_NOT_ANDROID} -sABORTING_MALLOC=0 -sJS_MATH=1 -sENVIRONMENT='web,webview,worker,node,shell' -sNODEJS_CATCH_EXIT=0 -sSTRICT=1 -sMINIMAL_RUNTIME=0 -sDISABLE_EXCEPTION_CATCHING=0 -sALLOW_MEMORY_GROWTH=1 -Wno-pthreads-mem-growth -sMEMORY_GROWTH_GEOMETRIC_STEP=0 -sDECLARE_ASM_MODULE_EXPORTS=0 ${CMAKE_EXE_LINKER_FLAGS}")
if (CMAKE_USE_PTHREADS_INIT) if (CMAKE_USE_PTHREADS_INIT)
set(CMAKE_CXX_FLAGS "-pthread ${CMAKE_CXX_FLAGS}") # Emscripten requires the -pthread flag set(CMAKE_CXX_FLAGS "-pthread ${CMAKE_CXX_FLAGS}") # Emscripten requires the -pthread flag
set(CMAKE_EXE_LINKER_FLAGS "--closure-args=\"--compilation_level SIMPLE\" -sPROXY_TO_PTHREAD=1 ${CMAKE_EXE_LINKER_FLAGS}") # See https://github.com/emscripten-core/emscripten/issues/16706 set(CMAKE_EXE_LINKER_FLAGS "--closure-args=\"--compilation_level SIMPLE\" -sPROXY_TO_PTHREAD=1 ${CMAKE_EXE_LINKER_FLAGS}") # See https://github.com/emscripten-core/emscripten/issues/16706

View File

@ -32,6 +32,9 @@
#include <optional> #include <optional>
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
#ifdef EMSCRIPTEN
#include <emscripten.h>
#endif
namespace Yerbacon { namespace Yerbacon {
consteval const char* getVersion() noexcept { return YBCON_VERSION; } consteval const char* getVersion() noexcept { return YBCON_VERSION; }

View File

@ -42,6 +42,23 @@ int main(int argc, char* argv[]) {
#ifdef _OPENMP #ifdef _OPENMP
if (not parallel) omp_set_num_threads(1); if (not parallel) omp_set_num_threads(1);
#endif #endif
#ifdef EMSCRIPTEN
const string directory (currentArgument.substr(0, currentArgument.find_last_of(filesystem::path::preferred_separator) + 1));
for (unsigned int i = 1; i < directory.size(); ++i) {
const string sub_directory = directory.substr(0, i);
if (directory[i] == '/' and not filesystem::is_directory(sub_directory)) {
MAIN_THREAD_EM_ASM({
if ((typeof process !== 'undefined') && (process.release.name === 'node')) {
const sub_directory = UTF8ToString($0);
if (!FS.isMountpoint(sub_directory)) {
FS.mkdir(sub_directory);
FS.mount(NODEFS, {root: sub_directory}, sub_directory);
};
}
}, sub_directory.c_str());
}
}
#endif
Units.insert_or_assign(currentArgument, async(not parallel ? launch::deferred : launch::async, [currentArgument, &text_provided, &target, &newLines]() { Units.insert_or_assign(currentArgument, async(not parallel ? launch::deferred : launch::async, [currentArgument, &text_provided, &target, &newLines]() {
unit_result resultingPair; unit_result resultingPair;
try { try {