From 17cc3fe0b18e6389438b5fbfbaa8a2599e04ee52 Mon Sep 17 00:00:00 2001 From: Username404 Date: Mon, 21 Nov 2022 13:58:27 +0000 Subject: [PATCH 01/20] CMakeLists.txt: Use -Oz when it is supported on GNU or Clang compilers Signed-off-by: Username404 --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 39185e6..a6d1ff6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,10 @@ if (${IS_GNU} OR ${IS_CLANG}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstrict-enums -pipe -funwind-tables -fasynchronous-unwind-tables -frtti -fexceptions") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ffunction-sections -fdata-sections -fmerge-all-constants -ftree-vectorize -fno-math-errno") include(CheckCXXCompilerFlag) + check_cxx_compiler_flag("-Oz" Z_OPTIMIZATION_SUPPORTED) + if (Z_OPTIMIZATION_SUPPORTED) + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Oz") + endif() set(CF_PROTECTION "-fcf-protection") check_cxx_compiler_flag("${CF_PROTECTION}" CF_PROTECTION_SUPPORTED) if (CF_PROTECTION_SUPPORTED) From 845e9e3cb743fa2b58c3d3dcee04c26027935f2b Mon Sep 17 00:00:00 2001 From: Username404 Date: Fri, 25 Nov 2022 19:44:34 +0100 Subject: [PATCH 02/20] Revert "Jenkinsfile: Use glibc when compiling for riscv64 since the riscv64 cross-compiler doesn't seem to work" This reverts commit 6afec609 Signed-off-by: Username404 --- Jenkinsfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8066c55..c1e6b99 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,8 +7,7 @@ boolean use_yarn_or_npm() { return fileExists('/usr/bin/yarn') || fileExists('/u - Sidebar Link - Workspace Cleanup Required Compilers: - - G++ cross-compiler for riscv64 - - Musl cross-compiling toolchains (archives ending in "-cross" from https://musl.cc/#binaries) for x86_64, i686, armel, armhf and aarch64, unzipped into /usr/, along with soft links from /usr/bin/ to the binaries + - Musl cross-compiling toolchains (archives ending in "-cross" from https://musl.cc/#binaries) for x86_64, i686, armel, armhf, aarch64 and riscv64, unzipped into /usr/, along with soft links from /usr/bin/ to the binaries - Emscripten Clang (https://github.com/emscripten-core/emsdk) in /usr/share/ - MinGW32 G++/Clang (https://github.com/mstorsjo/llvm-mingw) for x86_64, i686, armhf and aarch64, (unzip the content of the folder in the tar.xz file) in /usr/, along with soft links from /usr/bin/ to the binaries Optional Tools: @@ -44,7 +43,7 @@ pipeline { 'armel-linux-musleabi (RPM=armv4l, DEB=armel)', 'armv7l-linux-musleabihf (RPM=armv7hl, DEB=armhf)', 'aarch64-linux-musl (RPM=aarch64, DEB=arm64)', - 'riscv64-linux-gnu (RPM=riscv64, DEB=riscv64)', + 'riscv64-linux-musl (RPM=riscv64, DEB=riscv64)', 'x86_64-w64-mingw32 (RPM=x86_64, DEB=amd64)', 'i686-w64-mingw32 (RPM=i386, DEB=i386)', 'armv7-w64-mingw32 (RPM=armv7hl, DEB=armhf)', From bf94b8c6eba998106698eb5825a5ad47d1f19317 Mon Sep 17 00:00:00 2001 From: Username404 Date: Sat, 26 Nov 2022 01:54:08 +0100 Subject: [PATCH 03/20] CMakeLists.txt: Add "-Wl,--gc-sections" to the linker flags for release builds Signed-off-by: Username404 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a6d1ff6..c78f2c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,7 +84,7 @@ if (${IS_GNU} OR ${IS_CLANG}) 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 endif() endif() - set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-s") + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-Wl,--gc-sections -s") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstrict-enums -pipe -funwind-tables -fasynchronous-unwind-tables -frtti -fexceptions") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ffunction-sections -fdata-sections -fmerge-all-constants -ftree-vectorize -fno-math-errno") include(CheckCXXCompilerFlag) From d1ebbda1732afb14df4c0e0827f29376b7863b32 Mon Sep 17 00:00:00 2001 From: Username404 Date: Sun, 4 Dec 2022 13:50:12 +0100 Subject: [PATCH 04/20] Mount the filesystem when running on node.js Signed-off-by: Username404 --- CMakeLists.txt | 2 +- src/headers/Yerbacon.hpp | 3 +++ src/main.cpp | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c78f2c5..b0c03f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/headers/Yerbacon.hpp b/src/headers/Yerbacon.hpp index 801deed..e24639a 100644 --- a/src/headers/Yerbacon.hpp +++ b/src/headers/Yerbacon.hpp @@ -32,6 +32,9 @@ #include #include #include +#ifdef EMSCRIPTEN +#include +#endif namespace Yerbacon { consteval const char* getVersion() noexcept { return YBCON_VERSION; } diff --git a/src/main.cpp b/src/main.cpp index b5993ee..56fdfa0 100644 --- a/src/main.cpp +++ b/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 { From 64ef5e60ff2c9838bc31761d875bb655f85c9b20 Mon Sep 17 00:00:00 2001 From: Username404 Date: Sun, 4 Dec 2022 22:24:37 +0100 Subject: [PATCH 05/20] main.cpp: Support Windows paths on node.js Signed-off-by: Username404 --- src/main.cpp | 54 ++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 56fdfa0..b5597c6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,41 +42,41 @@ int main(int argc, char* argv[]) { #ifdef _OPENMP if (not parallel) omp_set_num_threads(1); #endif + optional file_path = make_optional(); + if (not text_provided) { + file_path = filesystem::path(currentArgument); #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()); + if (currentArgument.size() >= 2 and currentArgument[1] == ':') { + auto path = string(currentArgument).erase(0, 2); + replace(path.begin(), path.end(), '\\', '/'); + file_path = path; + } + const string directory = filesystem::path(file_path.value()).remove_filename(); + for (unsigned int character = 1; character < directory.size(); ++character) { + const string sub_directory = directory.substr(0, character); + if ((directory[character] == '/') 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, file_path]() { unit_result resultingPair; try { resultingPair.first = Target::forName(target, newLines)->transpileWithTree( - parseString(text_provided ? currentArgument : getFileContent(currentArgument.data())) + parseString(text_provided ? currentArgument : getFileContent(file_path->string())) ); - if (not text_provided) outputFileContent(string(currentArgument.substr(0, currentArgument.size() - 6)) + '.' + target, resultingPair.first); + if (not text_provided) outputFileContent(filesystem::path(file_path.value()).replace_extension(target).string(), resultingPair.first); } catch (const Yerbacon::Exception& error) { - size_t lastSlash = 0; - const size_t position1 = currentArgument.find_last_of('/'); - if (cmp_not_equal(position1, string_view::npos)) lastSlash = position1; - if constexpr(filesystem::path::preferred_separator != '/') { - const size_t position2 = currentArgument.find_last_of(filesystem::path::preferred_separator); - if (cmp_not_equal(position2, string_view::npos)) { - lastSlash = max(lastSlash, position2); - } - } - resultingPair.first = currentArgument.substr(lastSlash + 1); + resultingPair.first = file_path.has_value() ? file_path->filename().string() : string(); resultingPair.second.emplace(error); } return resultingPair; From dc380c8dcb039d347d17fa412bfbf4b50ded74a7 Mon Sep 17 00:00:00 2001 From: Username404 Date: Mon, 5 Dec 2022 18:25:10 +0100 Subject: [PATCH 06/20] main.cpp: Catch exceptions when calling filesystem functions on node.js Signed-off-by: Username404 --- src/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b5597c6..8cc182b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -59,8 +59,10 @@ int main(int argc, char* argv[]) { 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); + try { + FS.mkdir(sub_directory); + FS.mount(NODEFS, {root: sub_directory}, sub_directory); + } catch (exception) {} }; } }, sub_directory.c_str()); From dedb12470e9af6da11837fd7cac3381fd4b66b43 Mon Sep 17 00:00:00 2001 From: Username404 Date: Mon, 19 Dec 2022 02:10:34 +0100 Subject: [PATCH 07/20] CMakeLists.txt: Disable EXIT_RUNTIME since it does not seem to work well on web browsers and is not really needed Signed-off-by: Username404 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b0c03f7..7d3198c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 -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}") + set(CMAKE_EXE_LINKER_FLAGS "--closure 1 -lnodefs.js -sFORCE_FILESYSTEM=1 -sWASM=0 --memory-init-file 0 -sEXPORTED_FUNCTIONS=_main -sEXIT_RUNTIME=0 -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 From 1aada9d23fd21ce04cc47606e193439890106780 Mon Sep 17 00:00:00 2001 From: Username404 Date: Sun, 8 Jan 2023 01:12:52 +0100 Subject: [PATCH 08/20] main.cpp: Force runtime exit when using node.js Signed-off-by: Username404 --- src/headers/Yerbacon.hpp | 9 ++++++++- src/main.cpp | 25 +++++++++++++------------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/headers/Yerbacon.hpp b/src/headers/Yerbacon.hpp index e24639a..fdec0b8 100644 --- a/src/headers/Yerbacon.hpp +++ b/src/headers/Yerbacon.hpp @@ -34,6 +34,13 @@ #include #ifdef EMSCRIPTEN #include +static bool is_node; +void exit(int status) { + if (is_node) emscripten_force_exit(status); else emscripten_exit_with_live_runtime(); + std::exit(status); +} +#else +using std::exit; #endif namespace Yerbacon { @@ -49,7 +56,7 @@ namespace Yerbacon { std::cout << current_string; }); std::cout << std::endl; - std::exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } inline void fail(const char* reason) { fail({reason}); } class Exception: public std::exception { diff --git a/src/main.cpp b/src/main.cpp index 8cc182b..11580e5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,6 +19,9 @@ int main(int argc, char* argv[]) { using unit_result = pair>; using unit = future; map Units; + #ifdef EMSCRIPTEN + is_node = MAIN_THREAD_EM_ASM_INT({ return ENVIRONMENT_IS_NODE; }); + #endif for (signed int i = 1; i < argc; ++i) { const string_view currentArgument (argv[i]); @@ -54,17 +57,15 @@ int main(int argc, char* argv[]) { const string directory = filesystem::path(file_path.value()).remove_filename(); for (unsigned int character = 1; character < directory.size(); ++character) { const string sub_directory = directory.substr(0, character); - if ((directory[character] == '/') and not filesystem::is_directory(sub_directory)) { + if (is_node and (directory[character] == '/') 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)) { - try { - FS.mkdir(sub_directory); - FS.mount(NODEFS, {root: sub_directory}, sub_directory); - } catch (exception) {} - }; - } + const sub_directory = UTF8ToString($0); + if (!FS.isMountpoint(sub_directory)) { + try { + FS.mkdir(sub_directory); + FS.mount(NODEFS, {root: sub_directory}, sub_directory); + } catch (exception) {} + }; }, sub_directory.c_str()); } } @@ -108,9 +109,9 @@ int main(int argc, char* argv[]) { } else { cout << "Compilation"; if (not text_provided) cout << " of " << result.first; cout << " has failed with the following error:" << endl; cerr << result.second.value().what() << '\n'; - return EXIT_FAILURE; + exit(EXIT_FAILURE); } } } else cout << (!text_provided ? "No valid file provided" : "No text was provided") << ".\n"; - return EXIT_SUCCESS; + exit(EXIT_SUCCESS); } \ No newline at end of file From e3ae8da7995a2d2c76552917fa5e43d0e6331687 Mon Sep 17 00:00:00 2001 From: Username404 Date: Thu, 19 Jan 2023 12:14:24 +0000 Subject: [PATCH 09/20] Yerbacon.hpp: Add a yerbacon_output variable to use in JavaScript Signed-off-by: Username404 --- CMakeLists.txt | 2 +- src/headers/Yerbacon.hpp | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d3198c..f84e274 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 -lnodefs.js -sFORCE_FILESYSTEM=1 -sWASM=0 --memory-init-file 0 -sEXPORTED_FUNCTIONS=_main -sEXIT_RUNTIME=0 -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 -lembind -sFORCE_FILESYSTEM=1 -sWASM=0 --memory-init-file 0 -sEXPORTED_FUNCTIONS=_main -sEXIT_RUNTIME=0 -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 diff --git a/src/headers/Yerbacon.hpp b/src/headers/Yerbacon.hpp index fdec0b8..f75638c 100644 --- a/src/headers/Yerbacon.hpp +++ b/src/headers/Yerbacon.hpp @@ -36,11 +36,30 @@ #include static bool is_node; void exit(int status) { + MAIN_THREAD_EM_ASM("yerbacon_output = Module.get_cout();"); if (is_node) emscripten_force_exit(status); else emscripten_exit_with_live_runtime(); std::exit(status); } +#include +static std::ostringstream string_cout; +using std::cout; +#define cout (is_node ? std::cout : string_cout) +#define cerr (is_node ? std::cerr : string_cout) +std::string get_cout() { + static size_t previous_cout_size = 0; + std::string output = string_cout.str(); + const size_t current_size = output.size(); + output = output.substr(previous_cout_size, current_size); + previous_cout_size = current_size; + return output; +} +#include +EMSCRIPTEN_BINDINGS() { + emscripten::function("get_cout", &get_cout); +} #else using std::exit; +using std::cout; #endif namespace Yerbacon { @@ -53,9 +72,9 @@ namespace Yerbacon { } static void fail(const std::initializer_list reason) { std::for_each(reason.begin(), reason.end(), [](const char* current_string){ - std::cout << current_string; + cout << current_string; }); - std::cout << std::endl; + cout << std::endl; exit(EXIT_FAILURE); } inline void fail(const char* reason) { fail({reason}); } From f2347725e10bdbda097bcdeb4c9b626d4c14a9f0 Mon Sep 17 00:00:00 2001 From: Username404 Date: Sun, 22 Jan 2023 01:30:38 +0100 Subject: [PATCH 10/20] Yerbacon.hpp: Remove a useless "using" statement Signed-off-by: Username404 --- src/headers/Yerbacon.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/headers/Yerbacon.hpp b/src/headers/Yerbacon.hpp index f75638c..f781405 100644 --- a/src/headers/Yerbacon.hpp +++ b/src/headers/Yerbacon.hpp @@ -42,7 +42,6 @@ void exit(int status) { } #include static std::ostringstream string_cout; -using std::cout; #define cout (is_node ? std::cout : string_cout) #define cerr (is_node ? std::cerr : string_cout) std::string get_cout() { From 375f10acb325f947d0887d84172eaba8e017deb4 Mon Sep 17 00:00:00 2001 From: Username404 Date: Sat, 11 Feb 2023 03:23:25 +0100 Subject: [PATCH 11/20] Re-enable EXIT_RUNTIME to replace emscripten_force_exit Signed-off-by: Username404 --- CMakeLists.txt | 2 +- src/headers/Yerbacon.hpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f84e274..4a5f343 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 -lnodefs.js -lembind -sFORCE_FILESYSTEM=1 -sWASM=0 --memory-init-file 0 -sEXPORTED_FUNCTIONS=_main -sEXIT_RUNTIME=0 -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 -lembind -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 diff --git a/src/headers/Yerbacon.hpp b/src/headers/Yerbacon.hpp index f781405..38139a2 100644 --- a/src/headers/Yerbacon.hpp +++ b/src/headers/Yerbacon.hpp @@ -35,11 +35,12 @@ #ifdef EMSCRIPTEN #include static bool is_node; -void exit(int status) { +void emscripten_exit(int status) { MAIN_THREAD_EM_ASM("yerbacon_output = Module.get_cout();"); - if (is_node) emscripten_force_exit(status); else emscripten_exit_with_live_runtime(); + if (not is_node) emscripten_exit_with_live_runtime(); std::exit(status); } +#define exit(status) emscripten_exit(status) #include static std::ostringstream string_cout; #define cout (is_node ? std::cout : string_cout) From b6a708dcc0a8bc2fd8f60023092609a489af092f Mon Sep 17 00:00:00 2001 From: Username404 Date: Sat, 1 Apr 2023 21:21:09 +0200 Subject: [PATCH 12/20] ReservedIdentifiers.hpp: Use std::any_of instead of std::find in the reserved function Signed-off-by: Username404 --- src/headers/parsing/ReservedIdentifiers.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/headers/parsing/ReservedIdentifiers.hpp b/src/headers/parsing/ReservedIdentifiers.hpp index 3bc29d1..fed4b5c 100644 --- a/src/headers/parsing/ReservedIdentifiers.hpp +++ b/src/headers/parsing/ReservedIdentifiers.hpp @@ -19,7 +19,9 @@ inline const char* ID(const ReservedIdentifier& identifier) { } bool reserved(const string_view words) { - return find(identifiers.cbegin(), identifiers.cend(), words) != identifiers.cend(); + return any_of(identifiers.cbegin(), identifiers.cend(), [&words](const auto& identifier) { + return words == identifier; + }); } #endif //YERBACON_RESERVEDIDENTIFIERS_HPP From 3ff5d67a72530609da754e8ae5186129483b8ccc Mon Sep 17 00:00:00 2001 From: Username404 Date: Sat, 8 Apr 2023 23:54:14 +0200 Subject: [PATCH 13/20] CMakeLists.txt: Add a predefined pool of 3 web workers for emscripten Signed-off-by: Username404 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a5f343..5774803 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,7 @@ if (${IS_GNU} OR ${IS_CLANG}) set(CMAKE_EXE_LINKER_FLAGS "--closure 1 -lnodefs.js -lembind -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 + set(CMAKE_EXE_LINKER_FLAGS "--closure-args=\"--compilation_level SIMPLE\" -sPROXY_TO_PTHREAD=1 -sPTHREAD_POOL_SIZE=3 ${CMAKE_EXE_LINKER_FLAGS}") # See https://github.com/emscripten-core/emscripten/issues/16706 endif() endif() set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-Wl,--gc-sections -s") From ad495c2e6e900810f5d2ce897d2a33cdd8da6822 Mon Sep 17 00:00:00 2001 From: Username404 Date: Sun, 9 Apr 2023 01:48:49 +0200 Subject: [PATCH 14/20] CMakeLists.txt: Set DECLARE_ASM_MODULE_EXPORTS to 1 and PROXY_TO_PTHREAD to 0 in order to fix the unlimited creation of workers Signed-off-by: Username404 --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5774803..4f8edb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,10 +78,10 @@ if (${IS_GNU} OR ${IS_CLANG}) else() set(IS_HOST_NOT_ANDROID 0) endif() - set(CMAKE_EXE_LINKER_FLAGS "--closure 1 -lnodefs.js -lembind -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}") + set(CMAKE_EXE_LINKER_FLAGS "--closure 1 -lnodefs.js -lembind -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=1 ${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 -sPTHREAD_POOL_SIZE=3 ${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=0 -sPTHREAD_POOL_SIZE=3 ${CMAKE_EXE_LINKER_FLAGS}") # See https://github.com/emscripten-core/emscripten/issues/16706 endif() endif() set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-Wl,--gc-sections -s") From e35e30df96aecc06a1b405ff7c7a5d27673263fb Mon Sep 17 00:00:00 2001 From: Username404 Date: Sun, 9 Apr 2023 12:13:32 +0200 Subject: [PATCH 15/20] CMakeLists.txt: Set STACK_SIZE to 8 megabytes on emscripten Signed-off-by: Username404 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f8edb1..5f75f5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 -lnodefs.js -lembind -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=1 ${CMAKE_EXE_LINKER_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "--closure 1 -lnodefs.js -lembind -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 -sSTACK_SIZE=8MB -sALLOW_MEMORY_GROWTH=1 -Wno-pthreads-mem-growth -sMEMORY_GROWTH_GEOMETRIC_STEP=0 -sDECLARE_ASM_MODULE_EXPORTS=1 ${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=0 -sPTHREAD_POOL_SIZE=3 ${CMAKE_EXE_LINKER_FLAGS}") # See https://github.com/emscripten-core/emscripten/issues/16706 From 17a34315e8fe66e1bbb642bbb62d22bad3c938c0 Mon Sep 17 00:00:00 2001 From: Username404 Date: Sun, 9 Apr 2023 23:18:05 +0200 Subject: [PATCH 16/20] CMakeLists.txt: Set DEMANGLE_SUPPORT to 1 on emscripten Signed-off-by: Username404 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f75f5d..0e150a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 -lnodefs.js -lembind -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 -sSTACK_SIZE=8MB -sALLOW_MEMORY_GROWTH=1 -Wno-pthreads-mem-growth -sMEMORY_GROWTH_GEOMETRIC_STEP=0 -sDECLARE_ASM_MODULE_EXPORTS=1 ${CMAKE_EXE_LINKER_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "--closure 1 -lnodefs.js -lembind -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 -sSTACK_SIZE=8MB -sALLOW_MEMORY_GROWTH=1 -Wno-pthreads-mem-growth -sMEMORY_GROWTH_GEOMETRIC_STEP=0 -sDECLARE_ASM_MODULE_EXPORTS=1 -sDEMANGLE_SUPPORT=1 ${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=0 -sPTHREAD_POOL_SIZE=3 ${CMAKE_EXE_LINKER_FLAGS}") # See https://github.com/emscripten-core/emscripten/issues/16706 From 8b86910998995af6be52c80e80eea1edfbe3a50d Mon Sep 17 00:00:00 2001 From: Username404 Date: Mon, 10 Apr 2023 00:09:26 +0200 Subject: [PATCH 17/20] CMakeLists.txt: Set MALLOC to 'emmalloc' on emscripten Signed-off-by: Username404 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e150a8..75d15d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 -lnodefs.js -lembind -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 -sSTACK_SIZE=8MB -sALLOW_MEMORY_GROWTH=1 -Wno-pthreads-mem-growth -sMEMORY_GROWTH_GEOMETRIC_STEP=0 -sDECLARE_ASM_MODULE_EXPORTS=1 -sDEMANGLE_SUPPORT=1 ${CMAKE_EXE_LINKER_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "--closure 1 -lnodefs.js -lembind -sFORCE_FILESYSTEM=1 -sWASM=0 --memory-init-file 0 -sEXPORTED_FUNCTIONS=_main -sEXIT_RUNTIME=1 -sSINGLE_FILE=1 -sSAFE_HEAP=${IS_HOST_NOT_ANDROID} -sMALLOC='emmalloc' -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 -sSTACK_SIZE=8MB -sALLOW_MEMORY_GROWTH=1 -Wno-pthreads-mem-growth -sMEMORY_GROWTH_GEOMETRIC_STEP=0 -sDECLARE_ASM_MODULE_EXPORTS=1 -sDEMANGLE_SUPPORT=1 ${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=0 -sPTHREAD_POOL_SIZE=3 ${CMAKE_EXE_LINKER_FLAGS}") # See https://github.com/emscripten-core/emscripten/issues/16706 From 9210b92a1fd998bbc388537165626f4704f5546a Mon Sep 17 00:00:00 2001 From: Username404 Date: Mon, 10 Apr 2023 00:22:07 +0200 Subject: [PATCH 18/20] CMakeLists.txt: Always use the SIMPLE compilation level with closure Signed-off-by: Username404 --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 75d15d3..5c44c97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,10 +78,10 @@ if (${IS_GNU} OR ${IS_CLANG}) else() set(IS_HOST_NOT_ANDROID 0) endif() - set(CMAKE_EXE_LINKER_FLAGS "--closure 1 -lnodefs.js -lembind -sFORCE_FILESYSTEM=1 -sWASM=0 --memory-init-file 0 -sEXPORTED_FUNCTIONS=_main -sEXIT_RUNTIME=1 -sSINGLE_FILE=1 -sSAFE_HEAP=${IS_HOST_NOT_ANDROID} -sMALLOC='emmalloc' -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 -sSTACK_SIZE=8MB -sALLOW_MEMORY_GROWTH=1 -Wno-pthreads-mem-growth -sMEMORY_GROWTH_GEOMETRIC_STEP=0 -sDECLARE_ASM_MODULE_EXPORTS=1 -sDEMANGLE_SUPPORT=1 ${CMAKE_EXE_LINKER_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "--closure 1 --closure-args=\"--compilation_level SIMPLE\" -lnodefs.js -lembind -sFORCE_FILESYSTEM=1 -sWASM=0 --memory-init-file 0 -sEXPORTED_FUNCTIONS=_main -sEXIT_RUNTIME=1 -sSINGLE_FILE=1 -sSAFE_HEAP=${IS_HOST_NOT_ANDROID} -sMALLOC='emmalloc' -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 -sSTACK_SIZE=8MB -sALLOW_MEMORY_GROWTH=1 -Wno-pthreads-mem-growth -sMEMORY_GROWTH_GEOMETRIC_STEP=0 -sDECLARE_ASM_MODULE_EXPORTS=1 -sDEMANGLE_SUPPORT=1 ${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=0 -sPTHREAD_POOL_SIZE=3 ${CMAKE_EXE_LINKER_FLAGS}") # See https://github.com/emscripten-core/emscripten/issues/16706 + set(CMAKE_EXE_LINKER_FLAGS "-sPROXY_TO_PTHREAD=0 -sPTHREAD_POOL_SIZE=3 ${CMAKE_EXE_LINKER_FLAGS}") # See https://github.com/emscripten-core/emscripten/issues/16706 endif() endif() set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-Wl,--gc-sections -s") From 7c179ea07213653dff22d2c98598067643f6e4c7 Mon Sep 17 00:00:00 2001 From: Username404 Date: Mon, 10 Apr 2023 00:55:53 +0200 Subject: [PATCH 19/20] CMakeLists.txt: Set DYNAMIC_EXECUTION to 0 on emscripten Signed-off-by: Username404 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c44c97..18c09b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 --closure-args=\"--compilation_level SIMPLE\" -lnodefs.js -lembind -sFORCE_FILESYSTEM=1 -sWASM=0 --memory-init-file 0 -sEXPORTED_FUNCTIONS=_main -sEXIT_RUNTIME=1 -sSINGLE_FILE=1 -sSAFE_HEAP=${IS_HOST_NOT_ANDROID} -sMALLOC='emmalloc' -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 -sSTACK_SIZE=8MB -sALLOW_MEMORY_GROWTH=1 -Wno-pthreads-mem-growth -sMEMORY_GROWTH_GEOMETRIC_STEP=0 -sDECLARE_ASM_MODULE_EXPORTS=1 -sDEMANGLE_SUPPORT=1 ${CMAKE_EXE_LINKER_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "--closure 1 --closure-args=\"--compilation_level SIMPLE\" -lnodefs.js -lembind -sDYNAMIC_EXECUTION=0 -sFORCE_FILESYSTEM=1 -sWASM=0 --memory-init-file 0 -sEXPORTED_FUNCTIONS=_main -sEXIT_RUNTIME=1 -sSINGLE_FILE=1 -sSAFE_HEAP=${IS_HOST_NOT_ANDROID} -sMALLOC='emmalloc' -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 -sSTACK_SIZE=8MB -sALLOW_MEMORY_GROWTH=1 -Wno-pthreads-mem-growth -sMEMORY_GROWTH_GEOMETRIC_STEP=0 -sDECLARE_ASM_MODULE_EXPORTS=1 -sDEMANGLE_SUPPORT=1 ${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 "-sPROXY_TO_PTHREAD=0 -sPTHREAD_POOL_SIZE=3 ${CMAKE_EXE_LINKER_FLAGS}") # See https://github.com/emscripten-core/emscripten/issues/16706 From 97f87e6822a15795f18dfd63b3fdc9d5c380bd08 Mon Sep 17 00:00:00 2001 From: Username404 Date: Mon, 10 Apr 2023 15:20:51 +0200 Subject: [PATCH 20/20] CMakeLists.txt: Always use the "-Oz" optimization flag on emscripten since it uses clang Signed-off-by: Username404 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 18c09b2..76530f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,7 +89,7 @@ if (${IS_GNU} OR ${IS_CLANG}) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ffunction-sections -fdata-sections -fmerge-all-constants -ftree-vectorize -fno-math-errno") include(CheckCXXCompilerFlag) check_cxx_compiler_flag("-Oz" Z_OPTIMIZATION_SUPPORTED) - if (Z_OPTIMIZATION_SUPPORTED) + if (Z_OPTIMIZATION_SUPPORTED OR EMSCRIPTEN) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Oz") endif() set(CF_PROTECTION "-fcf-protection")