From e8246f42b2a6e0a023492a5ad7a6b16f5a445b38 Mon Sep 17 00:00:00 2001 From: lizzie Date: Tue, 9 Jun 2026 04:03:20 +0000 Subject: [PATCH] proper jthread support --- .patch/openssl-cmake/0005-wasm-support.patch | 39 ++++++-------------- CMakeLists.txt | 8 ++++ src/common/fs/path_util.cpp | 5 +++ src/yuzu_cmd/CMakeLists.txt | 5 ++- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/.patch/openssl-cmake/0005-wasm-support.patch b/.patch/openssl-cmake/0005-wasm-support.patch index 8492e3f616..35746a3f4b 100644 --- a/.patch/openssl-cmake/0005-wasm-support.patch +++ b/.patch/openssl-cmake/0005-wasm-support.patch @@ -1,33 +1,18 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 1ca57e1..d38c0c6 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -113,9 +113,10 @@ elseif(MINGW) - find_program(MAKE mingw32-make REQUIRED) - set(OPENSSL_BUILD_TOOL ${MAKE}) - else() -- find_program(MAKE make REQUIRED) -+ find_program(MAKE gmake REQUIRED) - set(OPENSSL_BUILD_TOOL ${MAKE}) - endif() -+set(OPENSSL_BUILD_TOOL gmake) - - # Modify configure/build options - if(OPENSSL_TEST AND NOT CMAKE_CROSSCOMPILING) -@@ -140,7 +141,7 @@ if(NUMBER_OF_THREADS GREATER 1) - list(APPEND OPENSSL_CONFIGURE_OPTIONS /FS) - list(APPEND OPENSSL_BUILD_OPTIONS /J ${NUMBER_OF_THREADS}) - else() -- list(APPEND OPENSSL_BUILD_OPTIONS -j ${NUMBER_OF_THREADS}) -+# list(APPEND OPENSSL_BUILD_OPTIONS -j ${NUMBER_OF_THREADS}) - endif() - endif() - diff --git a/cmake/ConfigureOpenSSL.cmake b/cmake/ConfigureOpenSSL.cmake -index 3012e05..9862aa0 100644 +index 3012e05..eda6cfb 100644 --- a/cmake/ConfigureOpenSSL.cmake +++ b/cmake/ConfigureOpenSSL.cmake -@@ -134,10 +134,24 @@ function(configure_openssl) +@@ -108,7 +108,8 @@ function(configure_openssl) + ) + + if(NOT "${CONFIGURE_OPTIONS_OLD}" STREQUAL "") +- if(CONFIGURE_OPTIONS STREQUAL CONFIGURE_OPTIONS_OLD) ++ # TODO(lizzie): Emscripten has issues with rebuilding due to the wrapper it uses ++ if(CMAKE_SYSTEM_NAME MATCHES "Emscripten" OR CONFIGURE_OPTIONS STREQUAL CONFIGURE_OPTIONS_OLD) + message(STATUS "Found previous configure results. Don't perform configuration") + return() + endif() +@@ -134,10 +135,24 @@ function(configure_openssl) set(VERBOSE_OPTION OUTPUT_QUIET) endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index f69c4a1ac2..946cd4f58c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -381,6 +381,14 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) # Prefer the -pthread flag on Linux. set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) +# It is absolutely promordial to enable on Emscripten +# Not only this allows to use std::thread and std::jthread without exceptions +# but it also fixes several issues related to MT operations. +# ...and CMake doesn't include it by default even when we specify +# that we prefer the pthread flag; why is that? I don't know. +if (PLATFORM_EMSCRIPTEN) + add_compile_options($<$:-pthread>) +endif() find_package(RenderDoc MODULE) diff --git a/src/common/fs/path_util.cpp b/src/common/fs/path_util.cpp index 3844cca06b..e5eb970717 100644 --- a/src/common/fs/path_util.cpp +++ b/src/common/fs/path_util.cpp @@ -136,6 +136,11 @@ public: eden_path = GetDataDirectory("XDG_DATA_HOME") / EDEN_DIR; eden_path_cache = GetDataDirectory("XDG_CACHE_HOME") / EDEN_DIR; eden_path_config = GetDataDirectory("XDG_CONFIG_HOME") / EDEN_DIR; +#if defined(__EMSCRIPTEN__) || defined(__wasi__) || defined(__managarm__) + // folders MAY not exist in this distrobution/OS + CreateParentDir(GetDataDirectory("XDG_CONFIG_HOME")); + CreateParentDir(GetDataDirectory("XDG_CACHE_HOME")); +#endif } else { eden_path_cache = eden_path / CACHE_DIR; eden_path_config = eden_path / CONFIG_DIR; diff --git a/src/yuzu_cmd/CMakeLists.txt b/src/yuzu_cmd/CMakeLists.txt index 4b097418bb..13b00bdebc 100644 --- a/src/yuzu_cmd/CMakeLists.txt +++ b/src/yuzu_cmd/CMakeLists.txt @@ -77,5 +77,8 @@ if (NOT MSVC) endif() if (PLATFORM_EMSCRIPTEN) - set_target_properties(yuzu-cmd PROPERTIES LINK_FLAGS_RELEASE "--global-base=16777216") + target_link_options(yuzu-cmd PRIVATE + -sGLOBAL_BASE=16777216 + -sPTHREAD_POOL_SIZE_STRICT=0 + -sPTHREAD_POOL_SIZE=navigator.hardwareConcurrency) endif()