Mount the filesystem when running on node.js
Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
parent
bf94b8c6eb
commit
d1ebbda173
|
@ -78,7 +78,7 @@ if (${IS_GNU} OR ${IS_CLANG})
|
|||
else()
|
||||
set(IS_HOST_NOT_ANDROID 0)
|
||||
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)
|
||||
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
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
#include <optional>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
namespace Yerbacon {
|
||||
consteval const char* getVersion() noexcept { return YBCON_VERSION; }
|
||||
|
|
17
src/main.cpp
17
src/main.cpp
|
@ -42,6 +42,23 @@ int main(int argc, char* argv[]) {
|
|||
#ifdef _OPENMP
|
||||
if (not parallel) omp_set_num_threads(1);
|
||||
#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]() {
|
||||
unit_result resultingPair;
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue