From caf0c82a9909e1a0e46386361f04d6467d20c11c Mon Sep 17 00:00:00 2001 From: lizzie Date: Wed, 20 May 2026 19:29:21 +0000 Subject: [PATCH 01/25] Use managarm special fastmem fallback --- src/common/host_memory.cpp | 17 +++++++++++++++-- src/common/host_memory.h | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index fa30b2c047..9935dc7490 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp @@ -695,10 +695,21 @@ HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_) backing_base = fallback_buffer->data(); virtual_base = nullptr; #else + bool has_memfd = true; // all platforms support it +#ifdef _WIN32 + // EXCEPT WINDOWS who may not (Windows 8.1, 7, Vista, etc) + DynamicLibrary kernelbase_dll("KernelBase"); + has_memfd = kernelbase_dll.IsOpen(); + if (has_memfd) { + PFN_CreateFileMapping2 p{}; + GetFuncAddress(kernelbase_dll, "CreateFileMapping2", p); + has_memfd = p != nullptr; + } +#endif // Try to allocate a fastmem arena. // The implementation will fail with std::bad_alloc on errors. impl = std::make_unique(AlignUp(backing_size, PageAlignment), AlignUp(virtual_size, PageAlignment) + HugePageSize); - if (impl->Init()) { + if (has_memfd && impl->Init()) { backing_base = impl->backing_base; virtual_base = impl->virtual_base; if (virtual_base) { @@ -708,10 +719,12 @@ HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_) } } else { impl.reset(); - LOG_WARNING(HW_Memory, "Platform can support fastmem, but can't create it"); + LOG_WARNING(HW_Memory, "Platform doesn't support fastmem"); +#ifdef _WIN32 fallback_buffer.emplace(backing_size); backing_base = fallback_buffer->data(); virtual_base = nullptr; +#endif } #endif } diff --git a/src/common/host_memory.h b/src/common/host_memory.h index 24f4670732..e003429baf 100644 --- a/src/common/host_memory.h +++ b/src/common/host_memory.h @@ -86,7 +86,9 @@ private: u8* virtual_base{}; size_t virtual_base_offset{}; // Windows requires it for kernels whom lack proper support for some functions! +#if defined(__OPENORBIS__) || defined(__managarm__) || defined(_WIN32) || defined(__EMSCRIPTEN__) std::optional> fallback_buffer; +#endif }; } // namespace Common From fbb05fc5d5beb0363ca6ec0833e3448467860185 Mon Sep 17 00:00:00 2001 From: lizzie Date: Fri, 22 May 2026 23:02:39 +0000 Subject: [PATCH 02/25] ok fixup but better with bool returns --- src/common/host_memory.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 9935dc7490..818981c95a 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp @@ -724,7 +724,6 @@ HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_) fallback_buffer.emplace(backing_size); backing_base = fallback_buffer->data(); virtual_base = nullptr; -#endif } #endif } From 9e651d9460038cdf62dc77018cd6a4cbe338fa79 Mon Sep 17 00:00:00 2001 From: lizzie Date: Mon, 8 Jun 2026 23:30:08 +0000 Subject: [PATCH 03/25] initial wasm support --- .ci/wasm/build.sh | 75 ++++++++++++ .patch/openssl-cmake/0005-wasm-support.patch | 55 +++++++++ .patch/openssl/0002-wasm-support.patch | 108 ++++++++++++++++++ CMakeLists.txt | 17 ++- cpmfile.json | 3 +- .../cmake-modules/DetectArchitecture.cmake | 14 ++- externals/cmake-modules/DetectPlatform.cmake | 3 + externals/ffmpeg/CMakeLists.txt | 75 +++++++++--- externals/tz/tz/tz.cpp | 2 + src/CMakeLists.txt | 7 +- src/common/CMakeLists.txt | 6 +- src/common/fiber.cpp | 97 ++++++++++++++-- src/common/fiber.h | 3 +- src/core/CMakeLists.txt | 17 ++- src/core/arm/dynarmic/arm_dynarmic.h | 6 +- src/core/debugger/debugger.cpp | 27 ++++- src/core/hle/kernel/k_process.cpp | 13 ++- .../abstracted_pad/abstract_mcu_handler.h | 5 +- src/hid_core/resources/shared_memory_holder.h | 10 +- src/input_common/CMakeLists.txt | 10 +- src/input_common/main.cpp | 22 +++- src/shader_recompiler/CMakeLists.txt | 3 +- src/shader_recompiler/environment.h | 2 +- .../translate/impl/texture_fetch_swizzled.cpp | 11 +- .../translate/impl/texture_load_swizzled.cpp | 11 +- 25 files changed, 522 insertions(+), 80 deletions(-) create mode 100644 .ci/wasm/build.sh create mode 100644 .patch/openssl-cmake/0005-wasm-support.patch create mode 100644 .patch/openssl/0002-wasm-support.patch diff --git a/.ci/wasm/build.sh b/.ci/wasm/build.sh new file mode 100644 index 0000000000..bdaab223e0 --- /dev/null +++ b/.ci/wasm/build.sh @@ -0,0 +1,75 @@ +#!/bin/sh -ex + +# SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +# SPDX-License-Identifier: GPL-3.0-or-later + +NUM_JOBS=$(nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 2) + +: "${CCACHE:=false}" +RETURN=0 + +usage() { + cat <&2 + RETURN=1 usage +} + +type() { + [ -z "$1" ] && die "You must specify a valid type." + TYPE="$1" +} + +outdir() { + [ -z "$1" ] && die "You must specify a valid output directory." + OUTDIR="$1" +} + +while true; do + case "$1" in + -r|--release) DEVEL=false ;; + -b|--build-type) type "$2"; shift ;; + -o|--outdir) outdir "$2"; shift ;; + -h|--help) usage ;; + *) break ;; + esac + shift +done + +: "${TYPE:=Release}" +: "${DEVEL:=true}" +: "${OUTDIR:=build}" + +emcmake cmake -B "$OUTDIR" -G "Unix Makefiles" \ + -DCMAKE_BUILD_TYPE=${TYPE} \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DENABLE_OPENGL=OFF \ + -DENABLE_LTO=OFF \ + -DENABLE_QT=OFF \ + -DENABLE_UNITY_BUILD=OFF \ + -DENABLE_QT_TRANSLATION=OFF \ + -DENABLE_CUBEB=OFF \ + -DENABLE_LIBUSB=OFF \ + -DENABLE_UPDATE_CHECKER=OFF \ + -DENABLE_WEB_SERVICE=OFF \ + -DUSE_DISCORD_PRESENCE=OFF \ + -DUSE_FASTER_LINKER=ON \ + -DYUZU_USE_BUNDLED_OPENSSL=OFF \ + -DYUZU_USE_EXTERNAL_FFMPEG=ON \ + -Dzstd_FORCE_BUNDLED=ON \ + -DOpenSSL_FORCE_BUNDLED=ON +cmake --build "$OUTDIR" -- -j$NUM_JOBS diff --git a/.patch/openssl-cmake/0005-wasm-support.patch b/.patch/openssl-cmake/0005-wasm-support.patch new file mode 100644 index 0000000000..8492e3f616 --- /dev/null +++ b/.patch/openssl-cmake/0005-wasm-support.patch @@ -0,0 +1,55 @@ +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 +--- a/cmake/ConfigureOpenSSL.cmake ++++ b/cmake/ConfigureOpenSSL.cmake +@@ -134,10 +134,24 @@ function(configure_openssl) + set(VERBOSE_OPTION OUTPUT_QUIET) + endif() + ++ if (CMAKE_SYSTEM_NAME MATCHES "Emscripten") ++ set(EMSCRIPTEN_CMAKE_WRAPPER "emcmake") ++ find_program(EMCC emcc REQUIRED) ++ set(EMSCRIPTEN_LINKER ${EMCC}) ++ list(APPEND CONFIGURE_COMMAND wasm64) ++ else() ++ set(EMSCRIPTEN_CMAKE_WRAPPER "") ++ set(EMSCRIPTEN_LINKER ${CMAKE_LINKER}) ++ endif () ++ + execute_process( +- COMMAND ${CMAKE_COMMAND} -E env ++ COMMAND ${EMSCRIPTEN_CMAKE_WRAPPER} ${CMAKE_COMMAND} -E env + "CFLAGS=${CMAKE_C_FLAGS}" + "CXXFLAGS=${CMAKE_CXX_FLAGS}" ++ "LDFLAGS=${CMAKE_CXX_LINKER_FLAGS}" ++ "CC=${CMAKE_C_COMPILER}" ++ "CXX=${CMAKE_CXX_COMPILER}" ++ "LD=${EMSCRIPTEN_LINKER}" + ${CONFIGURE_COMMAND} + WORKING_DIRECTORY ${CONFIGURE_BUILD_DIR} + ${VERBOSE_OPTION} diff --git a/.patch/openssl/0002-wasm-support.patch b/.patch/openssl/0002-wasm-support.patch new file mode 100644 index 0000000000..ddf2498c08 --- /dev/null +++ b/.patch/openssl/0002-wasm-support.patch @@ -0,0 +1,108 @@ +diff --git a/Configurations/10-main.conf b/Configurations/10-main.conf +index e62721e..6fcea0d 100644 +--- a/Configurations/10-main.conf ++++ b/Configurations/10-main.conf +@@ -1970,6 +1970,26 @@ my %targets = ( + multilib => "64", + }, + ++ "wasm32" => { ++ inherit_from => [ "BASE_unix" ], ++ CC => "emcc", ++ CXX => "emc++", ++ cflags => add("--target=wasm32-unknown-emscripten"), ++ cxxflags => add("--target=wasm32-unknown-emscripten"), ++ lib_cppflags => add("-DL_ENDIAN"), ++ bn_ops => "THIRTY_TWO_BIT", ++ }, ++ "wasm64" => { ++ inherit_from => [ "BASE_unix" ], ++ CC => "emcc", ++ CXX => "emc++", ++ cflags => add("--target=wasm64-unknown-emscripten"), ++ cxxflags => add("--target=wasm64-unknown-emscripten"), ++ lib_cppflags => add("-DL_ENDIAN"), ++ bn_ops => "SIXTY_FOUR_BIT_LONG", ++ }, ++ ++ + #### uClinux + "uClinux-dist" => { + inherit_from => [ "BASE_unix" ], +diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c +index d9e8f02..0bd63b0 100644 +--- a/crypto/rand/rand_lib.c ++++ b/crypto/rand/rand_lib.c +@@ -379,17 +379,25 @@ void RAND_add(const void *buf, int num, double randomness) + #if !defined(OPENSSL_NO_DEPRECATED_1_1_0) + int RAND_pseudo_bytes(unsigned char *buf, int num) + { ++#ifdef __EMSCRIPTEN__ ++ arc4random_buf(buf, num); ++ return 1; ++#else + const RAND_METHOD *meth = RAND_get_rand_method(); + + if (meth != NULL && meth->pseudorand != NULL) + return meth->pseudorand(buf, num); + ERR_raise(ERR_LIB_RAND, RAND_R_FUNC_NOT_IMPLEMENTED); + return -1; ++#endif + } + #endif + + int RAND_status(void) + { ++#ifdef __EMSCRIPTEN__ ++ return 1; ++#else + EVP_RAND_CTX *rand; + #ifndef OPENSSL_NO_DEPRECATED_3_0 + const RAND_METHOD *meth = RAND_get_rand_method(); +@@ -401,6 +409,7 @@ int RAND_status(void) + if ((rand = RAND_get0_primary(NULL)) == NULL) + return 0; + return EVP_RAND_get_state(rand) == EVP_RAND_STATE_READY; ++#endif + } + #else /* !FIPS_MODULE */ + +@@ -420,6 +429,10 @@ const RAND_METHOD *RAND_get_rand_method(void) + int RAND_priv_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, size_t num, + unsigned int strength) + { ++#ifdef __EMSCRIPTEN__ ++ arc4random_buf(buf, num); ++ return 1; ++#else + RAND_GLOBAL *dgbl; + EVP_RAND_CTX *rand; + #if !defined(OPENSSL_NO_DEPRECATED_3_0) && !defined(FIPS_MODULE) +@@ -451,6 +464,7 @@ int RAND_priv_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, size_t num, + return EVP_RAND_generate(rand, buf, num, strength, 0, NULL, 0); + + return 0; ++#endif + } + + int RAND_priv_bytes(unsigned char *buf, int num) +diff --git a/ssl/ssl_cert.c b/ssl/ssl_cert.c +index 3d21801..e026f8f 100644 +--- a/ssl/ssl_cert.c ++++ b/ssl/ssl_cert.c +@@ -941,6 +941,7 @@ done: + return ret; + } + ++#ifndef OPENSSL_NO_POSIX_IO + int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, + const char *dir) + { +@@ -1016,6 +1017,7 @@ err: + + return ret; + } ++#endif + + static int add_uris_recursive(STACK_OF(X509_NAME) *stack, + const char *uri, int depth) diff --git a/CMakeLists.txt b/CMakeLists.txt index 477e7c636d..57b6098e0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -405,7 +405,12 @@ set(BUILD_TESTING OFF) set(ENABLE_TESTING OFF) # boost -set(BOOST_INCLUDE_LIBRARIES algorithm icl pool container heap asio headers process filesystem crc variant) +if (PLATFORM_EMSCRIPTEN) + set(BOOST_INCLUDE_LIBRARIES algorithm icl pool container heap headers filesystem crc variant) + set(BOOST_CONTAINER_HEADER_ONLY ON) +else() + set(BOOST_INCLUDE_LIBRARIES algorithm icl pool container heap asio headers process filesystem crc variant) +endif() AddJsonPackage(boost) @@ -426,10 +431,12 @@ if (Boost_ADDED) target_compile_options(boost_heap INTERFACE $<$:-Wno-shadow>) target_compile_options(boost_icl INTERFACE $<$:-Wno-shadow>) - target_compile_options(boost_asio INTERFACE - $<$:-Wno-conversion> - $<$:-Wno-implicit-fallthrough> - ) + # May not exist (i.e emscripten) + if (TARGET boost_asio) + target_compile_options(boost_asio INTERFACE + $<$:-Wno-conversion> + $<$:-Wno-implicit-fallthrough>) + endif() endif() endif() diff --git a/cpmfile.json b/cpmfile.json index c0d879f838..149d73d465 100644 --- a/cpmfile.json +++ b/cpmfile.json @@ -219,7 +219,8 @@ "0001-cpmutil-compat.patch", "0002-use-ccache.patch", "0003-use-cmake-compiler-flags.patch", - "0004-use-shell-wrapper.patch" + "0004-use-shell-wrapper.patch", + "0005-wasm-support.patch" ], "repo": "jimmy-park/openssl-cmake", "version": "3.6.2" diff --git a/externals/cmake-modules/DetectArchitecture.cmake b/externals/cmake-modules/DetectArchitecture.cmake index 105963c8c2..083a255a27 100644 --- a/externals/cmake-modules/DetectArchitecture.cmake +++ b/externals/cmake-modules/DetectArchitecture.cmake @@ -94,6 +94,10 @@ function(detect_architecture_symbols) endfunction() # arches here are put in a sane default order of importance +# EXCEPT FOR WASM, which must be probed for FIRST, because some genius +# decided to also allow the host architecture to be defined when building +# for the emscripten target, absolutely lovely detail. +# # notably, amd64, arm64, and riscv (in order) are BY FAR the most common # mips is pretty popular in embedded # ppc64 is pretty popular in supercomputing @@ -101,6 +105,11 @@ endfunction() # ia64 exists # the rest exist, but are probably less popular than ia64 +detect_architecture_symbols( + ARCH wasm + SYMBOLS + "__EMSCRIPTEN__") + detect_architecture_symbols( ARCH arm64 SYMBOLS @@ -203,11 +212,6 @@ detect_architecture_symbols( "__loongarch__" "__loongarch64") -detect_architecture_symbols( - ARCH wasm - SYMBOLS - "__EMSCRIPTEN__") - # "generic" target # If you have reached this point, you're on some as-of-yet unsupported architecture. # See the docs up above for known unsupported architectures diff --git a/externals/cmake-modules/DetectPlatform.cmake b/externals/cmake-modules/DetectPlatform.cmake index 0f7cdfcf46..10b4378850 100644 --- a/externals/cmake-modules/DetectPlatform.cmake +++ b/externals/cmake-modules/DetectPlatform.cmake @@ -20,6 +20,9 @@ elseif (${CMAKE_SYSTEM_NAME} STREQUAL "managarm") set(MANAGARM ON) elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Haiku") set(HAIKUOS ON) +elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten") + set(EMSCRIPTEN ON) + message(WARNING "${CMAKE_LIBRARY_ARCHITECTURE} support is highly experimental!!!") endif() # BSD diff --git a/externals/ffmpeg/CMakeLists.txt b/externals/ffmpeg/CMakeLists.txt index f1bf099c10..82fd08d7b0 100644 --- a/externals/ffmpeg/CMakeLists.txt +++ b/externals/ffmpeg/CMakeLists.txt @@ -35,26 +35,39 @@ if (NOT YUZU_USE_BUNDLED_FFMPEG) elseif (NOT (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES CMAKE_SYSTEM_PROCESSOR AND CMAKE_HOST_SYSTEM_NAME MATCHES CMAKE_SYSTEM_NAME)) string(TOLOWER "${CMAKE_SYSTEM_NAME}" FFmpeg_SYSTEM_NAME) - if (FFmpeg_SYSTEM_NAME STREQUAL "openorbis" OR FFmpeg_SYSTEM_NAME STREQUAL "managarm") + # All of these platforms are supported by ffmpeg as native build OSes + # anything else (like Redox or Managarm or PS4) is NOT natively supported + # hence, assume the "unix like" is just "none" for the sake of OUR sanity. + # If YOUR OS/platform has actual native support: + # 1. fucking congrats + # 2. feel free to add it on the condition below + if (NOT (PLATFORM_NETBSD OR PLATFORM_SUN OR PLATFORM_FREEBSD + OR PLATFORM_OPENBSD OR PLATFORM_DRAGONFLYBSD OR PLATFORM_HAIKU + OR PLATFORM_LINUX OR PLATFORM_MSYS OR WIN32 OR ANDROID OR APPLE)) set(FFmpeg_SYSTEM_NAME "none") endif() # TODO: Can we really do better? Auto-detection? Something clever? list(APPEND FFmpeg_CROSS_COMPILE_FLAGS --enable-cross-compile --arch="${CMAKE_SYSTEM_PROCESSOR}" - --target-os="${FFmpeg_SYSTEM_NAME}" - --sysroot="${CMAKE_SYSROOT}" - ) + --target-os="${FFmpeg_SYSTEM_NAME}") + if (PLATFORM_EMSCRIPTEN) + # funniest trolling from emscripten, such a classic! + # maybe I should PR so they use CMAKE_SYSROOT... y'know? + list(APPEND FFmpeg_CROSS_COMPILE_FLAGS --sysroot="${EMSCRIPTEN_SYSROOT}") + else() + list(APPEND FFmpeg_CROSS_COMPILE_FLAGS --sysroot="${CMAKE_SYSROOT}") + endif() if (DEFINED FFmpeg_CROSS_PREFIX) list(APPEND FFmpeg_CROSS_COMPILE_FLAGS --cross-prefix="${FFmpeg_CROSS_PREFIX}") else() - message(WARNING "Please set FFmpeg_CROSS_PREFIX to your cross toolchain prefix, for example: \${CMAKE_STAGING_PREFIX}/bin/${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_SYSTEM_NAME}-") + message(WARNING "Please set FFmpeg_CROSS_PREFIX to your cross toolchain prefix, for example: ${CMAKE_STAGING_PREFIX}/bin/${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_SYSTEM_NAME}") endif() set(FFmpeg_IS_CROSS_COMPILING TRUE) endif() endif() -if (OPENORBIS OR MANAGARM) +if (OPENORBIS OR MANAGARM OR EMSCRIPTEN) # Doesn't support VA-API, don't go thru the embarrassment of trying to enable it list(APPEND FFmpeg_HWACCEL_FLAGS --disable-vaapi) elseif (ANDROID) @@ -162,8 +175,7 @@ if (OPENORBIS) -lSceUserService -lSceSysmodule -lSceNet - -lSceLibcInternal - ) + -lSceLibcInternal) list(APPEND FFmpeg_CROSS_COMPILE_FLAGS --disable-pthreads --extra-cflags=${CMAKE_SYSROOT}/usr/include @@ -174,8 +186,18 @@ elseif (MANAGARM) # Required for proper stuff list(APPEND FFmpeg_CROSS_COMPILE_FLAGS --disable-pthreads - --extra-libs="${FFmpeg_CROSS_COMPILE_LIBS}" - ) + --extra-libs="${FFmpeg_CROSS_COMPILE_LIBS}") +endif() + +# Usually used by Emscripten +if (DEFINED CMAKE_AR) + list(APPEND FFmpeg_CROSS_COMPILE_FLAGS --ar=${CMAKE_AR}) +endif() +if (DEFINED CMAKE_NM) + list(APPEND FFmpeg_CROSS_COMPILE_FLAGS --nm=${CMAKE_NM}) +endif() +if (DEFINED CMAKE_RANLIB) + list(APPEND FFmpeg_CROSS_COMPILE_FLAGS --ranlib=${CMAKE_RANLIB}) endif() if (YUZU_USE_BUNDLED_FFMPEG) @@ -205,6 +227,7 @@ else() # Build FFmpeg from externals message(STATUS "Using FFmpeg from externals") + set(FFmpeg_LD ${CMAKE_LINKER}) if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64|amd64)") # FFmpeg has source that requires one of nasm or yasm to assemble it. # REQUIRED throws an error if not found here during configuration rather than during compilation. @@ -213,6 +236,12 @@ else() message(FATAL_ERROR "One of either `nasm` or `yasm` not found but is required.") endif() endif() + if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + # TODO: this is 100% redundant but we need it because CMAKE_LINKER can resolve to ld.lld + # which is NOT compatible + find_program(EMCC NAMES emcc REQUIRED) + set(FFmpeg_LD ${EMCC}) + endif() find_program(AUTOCONF autoconf) if ("${AUTOCONF}" STREQUAL "AUTOCONF-NOTFOUND") @@ -246,7 +275,13 @@ else() CACHE PATH "Paths to FFmpeg libraries" FORCE) endforeach() - find_program(BASH_PROGRAM bash REQUIRED) + # Some SDKs (especially wasm) require us, actually, WANT us to use their "emconfigure" + # otherwise they will cry a billion tears + if (PLATFORM_EMSCRIPTEN) + find_program(FFmpeg_CONFIGURE_WRAPPER emconfigure REQUIRED) + else() + find_program(FFmpeg_CONFIGURE_WRAPPER bash REQUIRED) + endif() # `configure` parameters builds only exactly what yuzu needs from FFmpeg # `--disable-vdpau` is needed to avoid linking issues @@ -256,7 +291,7 @@ else() OUTPUT ${FFmpeg_MAKEFILE} COMMAND - ${BASH_PROGRAM} ${FFmpeg_PREFIX}/configure + ${FFmpeg_CONFIGURE_WRAPPER} ${FFmpeg_PREFIX}/configure --disable-avdevice --disable-avformat --disable-doc @@ -265,6 +300,10 @@ else() --disable-ffprobe --disable-network --disable-swresample + --disable-autodetect + --disable-runtime-cpudetect + --disable-debug + --disable-programs --enable-decoder=h264 --enable-decoder=vp8 --enable-decoder=vp9 @@ -272,7 +311,7 @@ else() --enable-pic --cc=${FFmpeg_CC} --cxx=${FFmpeg_CXX} - --ld=${CMAKE_LINKER} + --ld=${FFmpeg_LD} --extra-cflags=${CMAKE_C_FLAGS} --extra-cxxflags=${CMAKE_CXX_FLAGS} --extra-ldflags=${CMAKE_C_LINK_FLAGS} @@ -288,11 +327,7 @@ else() # Workaround for Ubuntu 18.04's older version of make not being able to call make as a child # with context of the jobserver. Also helps ninja users. - execute_process( - COMMAND - nproc - OUTPUT_VARIABLE - SYSTEM_THREADS) + cmake_host_system_information(RESULT SYSTEM_THREADS QUERY NUMBER_OF_LOGICAL_CORES) set(FFmpeg_BUILD_LIBRARIES ${FFmpeg_LIBRARIES}) @@ -300,6 +335,8 @@ else() if (LINUX OR ANDROID OR APPLE OR WIN32 OR FREEBSD) set(FFmpeg_MAKE_ARGS -j${SYSTEM_THREADS}) else() + # No GNU make implies that this system may be highly non-GNU + find_program(MAKE make required) set(FFmpeg_MAKE_ARGS "") endif() @@ -307,7 +344,7 @@ else() OUTPUT ${FFmpeg_BUILD_LIBRARIES} COMMAND - gmake ${FFmpeg_MAKE_ARGS} + ${MAKE} ${FFmpeg_MAKE_ARGS} WORKING_DIRECTORY ${FFmpeg_BUILD_DIR} ) diff --git a/externals/tz/tz/tz.cpp b/externals/tz/tz/tz.cpp index 3269d9cc1e..e0b19d8fd5 100644 --- a/externals/tz/tz/tz.cpp +++ b/externals/tz/tz/tz.cpp @@ -14,7 +14,9 @@ namespace Tz { namespace { +#ifndef EINVAL #define EINVAL 22 +#endif static Rule gmtmem{}; static Rule* const gmtptr = &gmtmem; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a2abc7d1b3..c0b14e21a7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -177,7 +177,6 @@ else() $<$:-Wno-invalid-offsetof> $<$:-Wno-unused-parameter> $<$:-Wno-missing-field-initializers>) - if (CXX_CLANG OR CXX_ICC OR CXX_APPLE) # Clang, AppleClang, or Intel C++ if (NOT MSVC) add_compile_options( @@ -191,7 +190,11 @@ else() $<$:-Wno-nullability-completeness>) endif() - if (ARCHITECTURE_x86_64) + if (ARCHITECTURE_wasm) + # we are evil but fmt is even more evil + add_compile_options( + $<$:-Wno-shorten-64-to-32>) + elseif (ARCHITECTURE_x86_64) add_compile_options($<$:-mcx16>) if (LINUX OR FREEBSD) add_compile_options($<$:-mtls-dialect=gnu2>) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index d90190e6a0..961977ff83 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -236,7 +236,11 @@ else() target_link_libraries(common PUBLIC Boost::headers) endif() target_link_libraries(common PRIVATE OpenSSL::SSL) -target_link_libraries(common PUBLIC Boost::filesystem Boost::context httplib::httplib nlohmann_json::nlohmann_json) +target_link_libraries(common PUBLIC Boost::filesystem httplib::httplib nlohmann_json::nlohmann_json) +if (NOT PLATFORM_EMSCRIPTEN) + # Emscripten is: "bring your own implementation", boost doesn't add upstream support sadly + target_link_libraries(common PRIVATE Boost::context) +endif() if (lz4_ADDED) target_include_directories(common PRIVATE ${lz4_SOURCE_DIR}/lib) diff --git a/src/common/fiber.cpp b/src/common/fiber.cpp index 69eca732eb..a2912aa524 100644 --- a/src/common/fiber.cpp +++ b/src/common/fiber.cpp @@ -11,7 +11,12 @@ #include "common/fiber.h" #include "common/virtual_buffer.h" +#ifdef __EMSCRIPTEN__ +#include +#include +#else #include +#endif namespace Common { @@ -22,36 +27,103 @@ constexpr size_t DEFAULT_STACK_SIZE = 512 * 4096; #endif constexpr u32 CANARY_VALUE = 0xDEADBEEF; +#ifdef __EMSCRIPTEN__ struct Fiber::FiberImpl { FiberImpl() {} u32 canary_1 = CANARY_VALUE; std::array stack{}; - std::array rewind_stack{}; + std::array astack{}; u32 canary_2 = CANARY_VALUE; - boost::context::detail::fcontext_t context{}; - boost::context::detail::fcontext_t rewind_context{}; + emscripten_fiber_t* context{nullptr}; std::mutex guard; std::function entry_point; - std::function rewind_point; std::shared_ptr previous_fiber; - - u8* stack_limit = nullptr; - u8* rewind_stack_limit = nullptr; bool is_thread_fiber = false; bool released = false; }; -void Fiber::SetRewindPoint(std::function&& rewind_func) { - impl->rewind_point = std::move(rewind_func); +Fiber::Fiber(std::function&& entry_point_func) : impl{std::make_unique()} { + impl->entry_point = std::move(entry_point_func); + emscripten_fiber_init(impl->context, [](void *user_data) -> void { + auto* fiber = static_cast(user_data); + ASSERT(fiber && fiber->impl && fiber->impl->previous_fiber && fiber->impl->previous_fiber->impl); + ASSERT(fiber->impl->canary_1 == CANARY_VALUE); + ASSERT(fiber->impl->canary_2 == CANARY_VALUE); + fiber->impl->previous_fiber->impl->context = fiber->impl->context; + fiber->impl->previous_fiber->impl->guard.unlock(); + fiber->impl->previous_fiber.reset(); + fiber->impl->entry_point(); + UNREACHABLE(); + }, impl.get(), impl->stack.data(), impl->stack.size(), impl->astack.data(), impl->astack.size()); } +Fiber::Fiber() : impl{std::make_unique()} {} + +Fiber::~Fiber() { + if (!impl->released) { + // Make sure the Fiber is not being used + const bool locked = impl->guard.try_lock(); + ASSERT(locked && "Destroying a fiber that's still running"); + if (locked) { + impl->guard.unlock(); + } + } +} + +void Fiber::Exit() { + ASSERT(impl->is_thread_fiber && "Exiting non main thread fiber"); + if (impl->is_thread_fiber) { + impl->guard.unlock(); + impl->released = true; + } +} + +void Fiber::YieldTo(std::weak_ptr weak_from, Fiber& to) { + to.impl->guard.lock(); + to.impl->previous_fiber = weak_from.lock(); + emscripten_fiber_swap(to.impl->context, to.impl->previous_fiber->impl->context); + // "from" might no longer be valid if the thread was killed + if (auto from = weak_from.lock()) { + if (from->impl->previous_fiber == nullptr) { + ASSERT(false && "previous_fiber is nullptr!"); + } else { + from->impl->previous_fiber->impl->guard.unlock(); + from->impl->previous_fiber.reset(); + } + } +} + +std::shared_ptr Fiber::ThreadToFiber() { + std::shared_ptr fiber = std::shared_ptr{new Fiber()}; + fiber->impl->guard.lock(); + fiber->impl->is_thread_fiber = true; + return fiber; +} +#else +struct Fiber::FiberImpl { + FiberImpl() {} + + u32 canary_1 = CANARY_VALUE; + std::array stack{}; + u32 canary_2 = CANARY_VALUE; + + boost::context::detail::fcontext_t context{}; + + std::mutex guard; + std::function entry_point; + std::shared_ptr previous_fiber; + + u8* stack_limit = nullptr; + bool is_thread_fiber = false; + bool released = false; +}; + Fiber::Fiber(std::function&& entry_point_func) : impl{std::make_unique()} { impl->entry_point = std::move(entry_point_func); impl->stack_limit = impl->stack.data(); - impl->rewind_stack_limit = impl->rewind_stack.data(); u8* stack_base = impl->stack_limit + DEFAULT_STACK_SIZE; impl->context = boost::context::detail::make_fcontext(stack_base, impl->stack.size(), [](boost::context::detail::transfer_t transfer) -> void { auto* fiber = static_cast(transfer.data); @@ -72,7 +144,7 @@ Fiber::~Fiber() { if (!impl->released) { // Make sure the Fiber is not being used const bool locked = impl->guard.try_lock(); - ASSERT_MSG(locked, "Destroying a fiber that's still running"); + ASSERT(locked && "Destroying a fiber that's still running"); if (locked) { impl->guard.unlock(); } @@ -80,7 +152,7 @@ Fiber::~Fiber() { } void Fiber::Exit() { - ASSERT_MSG(impl->is_thread_fiber, "Exiting non main thread fiber"); + ASSERT(impl->is_thread_fiber && "Exiting non main thread fiber"); if (impl->is_thread_fiber) { impl->guard.unlock(); impl->released = true; @@ -110,5 +182,6 @@ std::shared_ptr Fiber::ThreadToFiber() { fiber->impl->is_thread_fiber = true; return fiber; } +#endif } // namespace Common diff --git a/src/common/fiber.h b/src/common/fiber.h index eb128f4bb2..fcaac1d5b8 100644 --- a/src/common/fiber.h +++ b/src/common/fiber.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project @@ -45,7 +45,6 @@ public: /// Fiber 'from' must be the currently running fiber. static void YieldTo(std::weak_ptr weak_from, Fiber& to); [[nodiscard]] static std::shared_ptr ThreadToFiber(); - void SetRewindPoint(std::function&& rewind_func); /// Only call from main thread's fiber void Exit(); private: diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index e04b3dde26..fbe310876c 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -38,10 +38,6 @@ add_library(core STATIC debugger/debugger.cpp debugger/debugger.h debugger/debugger_interface.h - debugger/gdbstub.cpp - debugger/gdbstub.h - debugger/gdbstub_arch.cpp - debugger/gdbstub_arch.h device_memory.cpp device_memory.h device_memory_manager.h @@ -1166,6 +1162,14 @@ add_library(core STATIC tools/freezer.h tools/renderdoc.cpp tools/renderdoc.h) +if (NOT PLATFORM_EMSCRIPTEN) + # incompatible with wasm's async model + target_sources(core PRIVATE + debugger/gdbstub.cpp + debugger/gdbstub.h + debugger/gdbstub_arch.cpp + debugger/gdbstub_arch.h) +endif() if (ENABLE_WIFI_SCAN) target_sources(core PRIVATE internal_network/wifi_scanner.cpp) @@ -1209,7 +1213,10 @@ target_include_directories(core PRIVATE ${OPUS_INCLUDE_DIRS}) target_link_libraries(core PUBLIC common PRIVATE audio_core hid_core network video_core nx_tzdb tz) if (BOOST_NO_HEADERS) - target_link_libraries(core PUBLIC Boost::container Boost::heap Boost::asio Boost::process Boost::crc) + target_link_libraries(core PUBLIC Boost::container Boost::heap Boost::crc) + if (NOT PLATFORM_EMSCRIPTEN) + target_link_libraries(core PRIVATE Boost::asio Boost::process) + endif() else() target_link_libraries(core PUBLIC Boost::headers) endif() diff --git a/src/core/arm/dynarmic/arm_dynarmic.h b/src/core/arm/dynarmic/arm_dynarmic.h index 8e6b1d9766..c8dbf93871 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.h +++ b/src/core/arm/dynarmic/arm_dynarmic.h @@ -6,19 +6,20 @@ #pragma once +#ifndef __EMSCRIPTEN__ #include - +#endif #include "core/arm/arm_interface.h" namespace Core { +#ifndef __EMSCRIPTEN__ constexpr Dynarmic::HaltReason StepThread = Dynarmic::HaltReason::Step; constexpr Dynarmic::HaltReason DataAbort = Dynarmic::HaltReason::MemoryAbort; constexpr Dynarmic::HaltReason BreakLoop = Dynarmic::HaltReason::UserDefined2; constexpr Dynarmic::HaltReason SupervisorCall = Dynarmic::HaltReason::UserDefined3; constexpr Dynarmic::HaltReason InstructionBreakpoint = Dynarmic::HaltReason::UserDefined4; constexpr Dynarmic::HaltReason PrefetchAbort = Dynarmic::HaltReason::UserDefined6; - constexpr HaltReason TranslateHaltReason(Dynarmic::HaltReason hr) { static_assert(u64(HaltReason::StepThread) == u64(StepThread)); static_assert(u64(HaltReason::DataAbort) == u64(DataAbort)); @@ -28,5 +29,6 @@ constexpr HaltReason TranslateHaltReason(Dynarmic::HaltReason hr) { static_assert(u64(HaltReason::PrefetchAbort) == u64(PrefetchAbort)); return HaltReason(hr); } +#endif } // namespace Core diff --git a/src/core/debugger/debugger.cpp b/src/core/debugger/debugger.cpp index d1c767721b..962b60098d 100644 --- a/src/core/debugger/debugger.cpp +++ b/src/core/debugger/debugger.cpp @@ -6,30 +6,52 @@ #include #include + +#ifdef __EMSCRIPTEN__ +// TODO: gdb stub compat with emscripten? +#else #include #include - #if BOOST_VERSION > 108400 && (!defined(_WINDOWS) && !defined(__ANDROID__)) || defined(YUZU_BOOST_v1) #define USE_BOOST_v1 #endif - #ifdef USE_BOOST_v1 #include #else #include #endif +#endif #include "common/logging.h" #include "common/polyfill_thread.h" #include "common/thread.h" #include "core/core.h" #include "core/debugger/debugger.h" +#ifndef __EMSCRIPTEN__ #include "core/debugger/debugger_interface.h" #include "core/debugger/gdbstub.h" +#endif #include "core/hle/kernel/global_scheduler_context.h" #include "core/hle/kernel/k_process.h" #include "core/hle/kernel/k_scheduler.h" +#ifdef __EMSCRIPTEN__ +namespace Core { +// Dummy +struct DebuggerImpl { + char pad; +}; +Debugger::Debugger(Core::System& system, u16 port) {} +Debugger::~Debugger() = default; +bool Debugger::NotifyThreadStopped(Kernel::KThread* thread) { + return false; +} +bool Debugger::NotifyThreadWatchpoint(Kernel::KThread* thread, const Kernel::DebugWatchpoint& watch) { + return false; +} +void Debugger::NotifyShutdown() {} +} // namespace Core +#else template static void AsyncReceiveInto(Readable& r, Buffer& buffer, Callback&& c) { static_assert(std::is_trivial_v); @@ -400,3 +422,4 @@ void Debugger::NotifyShutdown() { } } // namespace Core +#endif diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp index 7308b0ff87..c1b4a7b794 100644 --- a/src/core/hle/kernel/k_process.cpp +++ b/src/core/hle/kernel/k_process.cpp @@ -7,8 +7,14 @@ #include #include "common/scope_exit.h" #include "common/settings.h" + +#include "core/arm/exclusive_monitor.h" +#ifndef __EMSCRIPTEN__ #include "core/arm/dynarmic/arm_dynarmic.h" #include "core/arm/dynarmic/dynarmic_exclusive_monitor.h" +#include "core/arm/dynarmic/arm_dynarmic_32.h" +#include "core/arm/dynarmic/arm_dynarmic_64.h" +#endif #include "core/core.h" #include "core/hle/kernel/k_process.h" #include "core/hle/kernel/k_scoped_resource_reservation.h" @@ -18,8 +24,6 @@ #include "core/hle/kernel/k_thread_queue.h" #include "core/hle/kernel/k_worker_task_manager.h" -#include "core/arm/dynarmic/arm_dynarmic_32.h" -#include "core/arm/dynarmic/arm_dynarmic_64.h" #ifdef HAS_NCE #include "core/arm/nce/arm_nce.h" #endif @@ -1300,9 +1304,11 @@ void KProcess::LoadModule(KernelCore& kernel, CodeSet code_set, KProcessAddress } void KProcess::InitializeInterfaces(KernelCore& kernel) { +#ifdef __EMSCRIPTEN__ + ASSERT(false && "unimplemented"); +#else m_exclusive_monitor = Core::MakeExclusiveMonitor(this->GetMemory(), Core::Hardware::NUM_CPU_CORES); - #ifdef HAS_NCE if (this->IsApplication() && Settings::IsNceEnabled()) { for (size_t i = 0; i < Core::Hardware::NUM_CPU_CORES; i++) @@ -1322,6 +1328,7 @@ void KProcess::InitializeInterfaces(KernelCore& kernel) { static_cast(*m_exclusive_monitor), i); } } +#endif } bool KProcess::InsertWatchpoint(KernelCore& kernel, KProcessAddress addr, u64 size, DebugWatchpointType type) { diff --git a/src/hid_core/resources/abstracted_pad/abstract_mcu_handler.h b/src/hid_core/resources/abstracted_pad/abstract_mcu_handler.h index 44be82cd43..8df5c30150 100644 --- a/src/hid_core/resources/abstracted_pad/abstract_mcu_handler.h +++ b/src/hid_core/resources/abstracted_pad/abstract_mcu_handler.h @@ -28,7 +28,10 @@ enum class NpadMcuState : u32 { struct NpadMcuHolder { NpadMcuState state; INSERT_PADDING_BYTES(0x4); - IAbstractedPad* abstracted_pad; + union { + IAbstractedPad* abstracted_pad; + u64 abstracted_pad_raw; + }; }; static_assert(sizeof(NpadMcuHolder) == 0x10, "NpadMcuHolder is an invalid size"); diff --git a/src/hid_core/resources/shared_memory_holder.h b/src/hid_core/resources/shared_memory_holder.h index 5fcaddecc0..26d5867463 100644 --- a/src/hid_core/resources/shared_memory_holder.h +++ b/src/hid_core/resources/shared_memory_holder.h @@ -33,9 +33,15 @@ public: bool is_created{}; bool is_mapped{}; INSERT_PADDING_BYTES(0x5); - Kernel::KSharedMemory* shared_memory; + union { + Kernel::KSharedMemory* shared_memory = nullptr; + u64 shared_memory_raw; + }; INSERT_PADDING_BYTES(0x38); - SharedMemoryFormat* address = nullptr; + union { + SharedMemoryFormat* address = nullptr; + u64 address_raw; + }; }; // Correct size is 0x50 bytes static_assert(sizeof(SharedMemoryHolder) == 0x50, "SharedMemoryHolder is an invalid size"); diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 840602f4ce..01cf6a52f2 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt @@ -15,8 +15,6 @@ add_library(input_common STATIC drivers/tas_input.h drivers/touch_screen.cpp drivers/touch_screen.h - drivers/udp_client.cpp - drivers/udp_client.h drivers/virtual_amiibo.cpp drivers/virtual_amiibo.h drivers/virtual_gamepad.cpp @@ -34,8 +32,12 @@ add_library(input_common STATIC input_poller.cpp input_poller.h main.cpp - main.h -) + main.h) +if (NOT PLATFORM_EMSCRIPTEN) + target_sources(input_common PRIVATE + drivers/udp_client.cpp + drivers/udp_client.h) +endif() if (MSVC) target_compile_options(input_common PRIVATE diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 6c8443ff62..c643400e70 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -12,7 +12,6 @@ #include "input_common/drivers/mouse.h" #include "input_common/drivers/tas_input.h" #include "input_common/drivers/touch_screen.h" -#include "input_common/drivers/udp_client.h" #include "input_common/drivers/virtual_amiibo.h" #include "input_common/drivers/virtual_gamepad.h" #include "input_common/helpers/stick_from_buttons.h" @@ -21,6 +20,9 @@ #include "input_common/input_mapping.h" #include "input_common/input_poller.h" #include "input_common/main.h" +#ifndef __EMSCRIPTEN__ +#include "input_common/drivers/udp_client.h" +#endif #ifdef ENABLE_LIBUSB #include "input_common/drivers/gc_adapter.h" @@ -82,7 +84,9 @@ struct InputSubsystem::Impl { #ifdef ENABLE_LIBUSB RegisterEngine("gcpad", gcadapter); #endif +#ifndef __EMSCRIPTEN__ RegisterEngine("cemuhookudp", udp_client); +#endif RegisterEngine("tas", tas_input); RegisterEngine("camera", camera); #ifdef __ANDROID__ @@ -116,7 +120,9 @@ struct InputSubsystem::Impl { #ifdef ENABLE_LIBUSB UnregisterEngine(gcadapter); #endif +#ifndef __EMSCRIPTEN__ UnregisterEngine(udp_client); +#endif UnregisterEngine(tas_input); UnregisterEngine(camera); #ifdef __ANDROID__ @@ -152,8 +158,10 @@ struct InputSubsystem::Impl { auto gcadapter_devices = gcadapter->GetInputDevices(); devices.insert(devices.end(), gcadapter_devices.begin(), gcadapter_devices.end()); #endif +#ifndef __EMSCRIPTEN__ auto udp_devices = udp_client->GetInputDevices(); devices.insert(devices.end(), udp_devices.begin(), udp_devices.end()); +#endif #ifdef HAVE_SDL3 auto joycon_devices = joycon->GetInputDevices(); devices.insert(devices.end(), joycon_devices.begin(), joycon_devices.end()); @@ -186,9 +194,11 @@ struct InputSubsystem::Impl { return gcadapter; } #endif +#ifndef __EMSCRIPTEN__ if (engine == udp_client->GetEngineName()) { return udp_client; } +#endif #ifdef HAVE_SDL3 if (engine == sdl->GetEngineName()) { return sdl; @@ -271,9 +281,11 @@ struct InputSubsystem::Impl { return true; } #endif +#ifndef __EMSCRIPTEN__ if (engine == udp_client->GetEngineName()) { return true; } +#endif if (engine == tas_input->GetEngineName()) { return true; } @@ -300,7 +312,9 @@ struct InputSubsystem::Impl { #ifdef ENABLE_LIBUSB gcadapter->BeginConfiguration(); #endif +#ifndef __EMSCRIPTEN__ udp_client->BeginConfiguration(); +#endif #ifdef HAVE_SDL3 sdl->BeginConfiguration(); joycon->BeginConfiguration(); @@ -316,7 +330,9 @@ struct InputSubsystem::Impl { #ifdef ENABLE_LIBUSB gcadapter->EndConfiguration(); #endif +#ifndef __EMSCRIPTEN__ udp_client->EndConfiguration(); +#endif #ifdef HAVE_SDL3 sdl->EndConfiguration(); joycon->EndConfiguration(); @@ -341,7 +357,9 @@ struct InputSubsystem::Impl { std::shared_ptr mouse; std::shared_ptr touch_screen; std::shared_ptr tas_input; +#ifndef __EMSCRIPTEN__ std::shared_ptr udp_client; +#endif std::shared_ptr camera; std::shared_ptr virtual_amiibo; std::shared_ptr virtual_gamepad; @@ -470,7 +488,9 @@ bool InputSubsystem::IsStickInverted(const Common::ParamPackage& params) const { } void InputSubsystem::ReloadInputDevices() { +#ifndef __EMSCRIPTEN__ impl->udp_client.get()->ReloadSockets(); +#endif } void InputSubsystem::BeginMapping(Polling::InputType type) { diff --git a/src/shader_recompiler/CMakeLists.txt b/src/shader_recompiler/CMakeLists.txt index 1e6a4d173a..7591aeffd8 100644 --- a/src/shader_recompiler/CMakeLists.txt +++ b/src/shader_recompiler/CMakeLists.txt @@ -257,8 +257,7 @@ else() # Bracket depth determines maximum size of a fold expression in Clang since 9c9974c3ccb6. # And this in turns limits the size of a std::array. $<$:-fbracket-depth=1024> - $<$:-fbracket-depth=1024> - ) + $<$:-fbracket-depth=1024>) endif() create_target_directory_groups(shader_recompiler) diff --git a/src/shader_recompiler/environment.h b/src/shader_recompiler/environment.h index 184b56ebf3..fe291d67ea 100644 --- a/src/shader_recompiler/environment.h +++ b/src/shader_recompiler/environment.h @@ -31,7 +31,7 @@ struct CbufWordKey { struct CbufWordKeyHash { constexpr size_t operator()(const CbufWordKey& k) const noexcept { - return (size_t(k.index) << 32) ^ k.offset; + return size_t((u64(k.index) << 32) ^ u64(k.offset)); } }; diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_fetch_swizzled.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_fetch_swizzled.cpp index 50e618c2f1..d74eb6d46b 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_fetch_swizzled.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_fetch_swizzled.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -157,16 +160,14 @@ IR::Value Sample(TranslatorVisitor& v, u64 insn) { unsigned Swizzle(u64 insn) { const Encoding texs{insn}; - const size_t encoding{texs.swizzle}; + u8 const encoding = u8(texs.swizzle); if (texs.dest_reg_b == IR::Reg::RZ) { - if (encoding >= RG_LUT.size()) { + if (encoding >= RG_LUT.size()) throw NotImplementedException("Illegal RG encoding {}", encoding); - } return RG_LUT[encoding]; } else { - if (encoding >= RGBA_LUT.size()) { + if (encoding >= RGBA_LUT.size()) throw NotImplementedException("Illegal RGBA encoding {}", encoding); - } return RGBA_LUT[encoding]; } } diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_load_swizzled.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_load_swizzled.cpp index 0362f076af..1b5313711e 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_load_swizzled.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_load_swizzled.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -142,16 +145,14 @@ IR::Value Sample(TranslatorVisitor& v, u64 insn) { unsigned Swizzle(u64 insn) { const Encoding tlds{insn}; - const size_t encoding{tlds.swizzle}; + u8 const encoding = u8(tlds.swizzle); if (tlds.dest_reg_b == IR::Reg::RZ) { - if (encoding >= RG_LUT.size()) { + if (encoding >= RG_LUT.size()) throw NotImplementedException("Illegal RG encoding {}", encoding); - } return RG_LUT[encoding]; } else { - if (encoding >= RGBA_LUT.size()) { + if (encoding >= RGBA_LUT.size()) throw NotImplementedException("Illegal RGBA encoding {}", encoding); - } return RGBA_LUT[encoding]; } } From 9ab9bfb7126dc247ee3980df1d405fb6b59b0d2e Mon Sep 17 00:00:00 2001 From: lizzie Date: Mon, 8 Jun 2026 23:30:24 +0000 Subject: [PATCH 04/25] fix non existant pthread funcs --- src/common/thread.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/common/thread.cpp b/src/common/thread.cpp index 7b4dec3dce..9f546ead3c 100644 --- a/src/common/thread.cpp +++ b/src/common/thread.cpp @@ -490,6 +490,8 @@ void SetCurrentThreadPriority(ThreadPriority new_priority) { LOG_DEBUG(Common, "Could not set thread nice value to {}: {}", nice_value, GetLastErrorMsg()); } +#elif defined(__EMSCRIPTEN__) + // TODO: set priority? #else const s32 max_prio = sched_get_priority_max(SCHED_OTHER); const s32 min_prio = sched_get_priority_min(SCHED_OTHER); @@ -534,6 +536,8 @@ void SetCurrentThreadName(const char* name) { // See for reference // https://gitlab.freedesktop.org/mesa/mesa/-/blame/main/src/util/u_thread.c?ref_type=heads#L75 (void)name; +#elif defined(__EMSCRIPTEN__) + // TODO: set thread name? #else pthread_setname_np(pthread_self(), name); #endif From 5c12446f8daa1e7af8358487109f5ec4daa58933 Mon Sep 17 00:00:00 2001 From: lizzie Date: Mon, 8 Jun 2026 23:33:26 +0000 Subject: [PATCH 05/25] emscripten doesnt have arc4random but wasi does? --- .patch/openssl/0002-wasm-support.patch | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/.patch/openssl/0002-wasm-support.patch b/.patch/openssl/0002-wasm-support.patch index ddf2498c08..4cf7204549 100644 --- a/.patch/openssl/0002-wasm-support.patch +++ b/.patch/openssl/0002-wasm-support.patch @@ -30,16 +30,18 @@ index e62721e..6fcea0d 100644 "uClinux-dist" => { inherit_from => [ "BASE_unix" ], diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c -index d9e8f02..0bd63b0 100644 +index d9e8f02..7faf347 100644 --- a/crypto/rand/rand_lib.c +++ b/crypto/rand/rand_lib.c -@@ -379,17 +379,25 @@ void RAND_add(const void *buf, int num, double randomness) +@@ -379,17 +379,27 @@ void RAND_add(const void *buf, int num, double randomness) #if !defined(OPENSSL_NO_DEPRECATED_1_1_0) int RAND_pseudo_bytes(unsigned char *buf, int num) { -+#ifdef __EMSCRIPTEN__ ++#if defined(__wasi__) + arc4random_buf(buf, num); + return 1; ++#elif defined(__EMSCRIPTEN__) ++ return 1; +#else const RAND_METHOD *meth = RAND_get_rand_method(); @@ -53,13 +55,13 @@ index d9e8f02..0bd63b0 100644 int RAND_status(void) { -+#ifdef __EMSCRIPTEN__ ++#if defined(__EMSCRIPTEN__) || defined(__wasi__) + return 1; +#else EVP_RAND_CTX *rand; #ifndef OPENSSL_NO_DEPRECATED_3_0 const RAND_METHOD *meth = RAND_get_rand_method(); -@@ -401,6 +409,7 @@ int RAND_status(void) +@@ -401,6 +411,7 @@ int RAND_status(void) if ((rand = RAND_get0_primary(NULL)) == NULL) return 0; return EVP_RAND_get_state(rand) == EVP_RAND_STATE_READY; @@ -67,18 +69,20 @@ index d9e8f02..0bd63b0 100644 } #else /* !FIPS_MODULE */ -@@ -420,6 +429,10 @@ const RAND_METHOD *RAND_get_rand_method(void) +@@ -420,6 +431,12 @@ const RAND_METHOD *RAND_get_rand_method(void) int RAND_priv_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, size_t num, unsigned int strength) { -+#ifdef __EMSCRIPTEN__ ++#if defined(__wasi__) + arc4random_buf(buf, num); + return 1; ++#elif defined(__EMSCRIPTEN__) ++ return 1; +#else RAND_GLOBAL *dgbl; EVP_RAND_CTX *rand; #if !defined(OPENSSL_NO_DEPRECATED_3_0) && !defined(FIPS_MODULE) -@@ -451,6 +464,7 @@ int RAND_priv_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, size_t num, +@@ -451,6 +468,7 @@ int RAND_priv_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, size_t num, return EVP_RAND_generate(rand, buf, num, strength, 0, NULL, 0); return 0; From 0e94895536164de74df5612bdb7bdff0e175dffc Mon Sep 17 00:00:00 2001 From: lizzie Date: Mon, 8 Jun 2026 23:55:57 +0000 Subject: [PATCH 06/25] emscripten can't memfd --- src/common/host_memory.cpp | 33 ++++++++++++++++----------------- src/common/host_memory.h | 2 +- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 818981c95a..077049f3e6 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp @@ -394,7 +394,7 @@ private: ::Common::unordered_map placeholder_host_pointers; ///< Placeholder backing offset }; -#elif defined(__OPENORBIS__) || defined(__managarm__) +#elif defined(__OPENORBIS__) || defined(__managarm__) || defined(__wasi__) || defined(__EMSCRIPTEN__) // None of the luxuries of POSIX, all of the suffering // For managarm: see https://github.com/managarm/managarm/issues/1370 #else // ^^^ Windows ^^^ vvv POSIX vvv @@ -689,7 +689,7 @@ HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_) : backing_size(backing_size_) , virtual_size(virtual_size_) { -#if defined(__OPENORBIS__) || defined(__managarm__) +#if defined(__OPENORBIS__) || defined(__managarm__) || defined(__wasi__) || defined(__EMSCRIPTEN__) LOG_WARNING(HW_Memory, "Platform doesn't support fastmem"); fallback_buffer.emplace(backing_size); backing_base = fallback_buffer->data(); @@ -734,8 +734,13 @@ HostMemory::HostMemory(HostMemory&&) noexcept = default; HostMemory& HostMemory::operator=(HostMemory&&) noexcept = default; +#if defined(__OPENORBIS__) || defined(__managarm__) || defined(__wasi__) || defined(__EMSCRIPTEN__) +void HostMemory::Map(size_t virtual_offset, size_t host_offset, size_t length, MemoryPermission perms, bool separate_heap) {} +void HostMemory::Unmap(size_t virtual_offset, size_t length, bool separate_heap) {} +void HostMemory::Protect(size_t virtual_offset, size_t length, MemoryPermission perm) {} +void HostMemory::EnableDirectMappedAddress() {} +#else void HostMemory::Map(size_t virtual_offset, size_t host_offset, size_t length, MemoryPermission perms, bool separate_heap) { -#if !(defined(__OPENORBIS__) || defined(__managarm__)) ASSERT(virtual_offset % PageAlignment == 0); ASSERT(host_offset % PageAlignment == 0); ASSERT(length % PageAlignment == 0); @@ -745,11 +750,9 @@ void HostMemory::Map(size_t virtual_offset, size_t host_offset, size_t length, M return; } impl->Map(virtual_offset + virtual_base_offset, host_offset, length, perms); -#endif } void HostMemory::Unmap(size_t virtual_offset, size_t length, bool separate_heap) { -#if !(defined(__OPENORBIS__) || defined(__managarm__)) ASSERT(virtual_offset % PageAlignment == 0); ASSERT(length % PageAlignment == 0); ASSERT(virtual_offset + length <= virtual_size); @@ -757,11 +760,9 @@ void HostMemory::Unmap(size_t virtual_offset, size_t length, bool separate_heap) return; } impl->Unmap(virtual_offset + virtual_base_offset, length); -#endif } void HostMemory::Protect(size_t virtual_offset, size_t length, MemoryPermission perm) { -#if !(defined(__OPENORBIS__) || defined(__managarm__)) ASSERT(virtual_offset % PageAlignment == 0); ASSERT(length % PageAlignment == 0); ASSERT(virtual_offset + length <= virtual_size); @@ -772,20 +773,18 @@ void HostMemory::Protect(size_t virtual_offset, size_t length, MemoryPermission const bool write = True(perm & MemoryPermission::Write); const bool execute = True(perm & MemoryPermission::Execute); impl->Protect(virtual_offset + virtual_base_offset, length, read, write, execute); -#endif } +void HostMemory::EnableDirectMappedAddress() { + if (impl) { + impl->EnableDirectMappedAddress(); + virtual_size += reinterpret_cast(virtual_base); + } +} +#endif + void HostMemory::ClearBackingRegion(size_t physical_offset, size_t length, u32 fill_value) { std::memset(backing_base + physical_offset, fill_value, length); } -void HostMemory::EnableDirectMappedAddress() { -#if !(defined(__OPENORBIS__) || defined(__managarm__)) - if (impl) { - impl->EnableDirectMappedAddress(); - virtual_size += reinterpret_cast(virtual_base); - } -#endif -} - } // namespace Common diff --git a/src/common/host_memory.h b/src/common/host_memory.h index e003429baf..34e6726f11 100644 --- a/src/common/host_memory.h +++ b/src/common/host_memory.h @@ -77,7 +77,7 @@ private: size_t backing_size{}; size_t virtual_size{}; -#if !(defined(__OPENORBIS__) || defined(__managarm__)) +#if !(defined(__OPENORBIS__) || defined(__managarm__) || defined(__wasi__) || defined(__EMSCRIPTEN__)) // Low level handler for the platform dependent memory routines class Impl; std::unique_ptr impl; From 3d13ef9309eb6bcc5aa36730dc7d3cc3e18779ec Mon Sep 17 00:00:00 2001 From: lizzie Date: Tue, 9 Jun 2026 00:36:19 +0000 Subject: [PATCH 07/25] disable JIT service --- externals/cmake-modules/DetectPlatform.cmake | 17 +++++++++++++++++ src/core/debugger/debugger.cpp | 10 ++++++---- src/core/hle/service/services.cpp | 3 +++ src/yuzu_cmd/CMakeLists.txt | 4 ++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/externals/cmake-modules/DetectPlatform.cmake b/externals/cmake-modules/DetectPlatform.cmake index 10b4378850..5b0035b55d 100644 --- a/externals/cmake-modules/DetectPlatform.cmake +++ b/externals/cmake-modules/DetectPlatform.cmake @@ -100,3 +100,20 @@ if (MINGW) set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${MINGW_FLAGS}") endif() + +if (PLATFORM_EMSCRIPTEN) + set(EMSCRIPTEN_C_FLAGS "-s MEMORY64 -m64 -pipe -sMEMORY64=1") + set(EMSCRIPTEN_LINK_FLAGS "-sMEMORY64=1 -m64 -Wl,-mwasm64 -sASYNCIFY=1") + + # This prevents FFmpeg and other libraries from assuming it's the host's CPU + # Additionally some Emscripten installs may not be very good... generally + set(EMSCRIPTEN_SYSTEM_PROCESSOR wasm) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EMSCRIPTEN_C_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${EMSCRIPTEN_C_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EMSCRIPTEN_LINK_FLAGS}") + set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} ${EMSCRIPTEN_LINK_FLAGS}") + set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} ${EMSCRIPTEN_LINK_FLAGS}") + + unset(EMSCRIPTEN_C_FLAGS) + unset(EMSCRIPTEN_LINK_FLAGS) +endif() diff --git a/src/core/debugger/debugger.cpp b/src/core/debugger/debugger.cpp index 962b60098d..998d98cfe5 100644 --- a/src/core/debugger/debugger.cpp +++ b/src/core/debugger/debugger.cpp @@ -7,7 +7,7 @@ #include #include -#ifdef __EMSCRIPTEN__ +#if defined(__EMSCRIPTEN__) || defined(__wasi__) // TODO: gdb stub compat with emscripten? #else #include @@ -27,7 +27,9 @@ #include "common/thread.h" #include "core/core.h" #include "core/debugger/debugger.h" -#ifndef __EMSCRIPTEN__ +#if defined(__EMSCRIPTEN__) || defined(__wasi__) +// TODO: gdbstub with emscripten? +#else #include "core/debugger/debugger_interface.h" #include "core/debugger/gdbstub.h" #endif @@ -35,10 +37,10 @@ #include "core/hle/kernel/k_process.h" #include "core/hle/kernel/k_scheduler.h" -#ifdef __EMSCRIPTEN__ +#if defined(__EMSCRIPTEN__) || defined(__wasi__) namespace Core { // Dummy -struct DebuggerImpl { +class DebuggerImpl { char pad; }; Debugger::Debugger(Core::System& system, u16 port) {} diff --git a/src/core/hle/service/services.cpp b/src/core/hle/service/services.cpp index b90af960d6..755019bb7f 100644 --- a/src/core/hle/service/services.cpp +++ b/src/core/hle/service/services.cpp @@ -120,7 +120,10 @@ Services::Services(std::shared_ptr& sm, Core::System& system {"glue", &Glue::LoopProcess}, {"grc", &GRC::LoopProcess}, {"hid", &HID::LoopProcess}, +// Must match with src/core/CMakeLists.txt for target_source of jit.cpp +#if defined(ARCHITECTURE_x86_64) || defined(ARCHITECTURE_arm64) || defined(ARCHITECTURE_riscv64) || defined(ARCHITECTURE_loongarch64) {"jit", &JIT::LoopProcess}, +#endif {"lbl", &LBL::LoopProcess}, {"Loader", &LDR::LoopProcess}, {"LogManager.Prod", &LM::LoopProcess}, diff --git a/src/yuzu_cmd/CMakeLists.txt b/src/yuzu_cmd/CMakeLists.txt index 09a9bd6da1..4b097418bb 100644 --- a/src/yuzu_cmd/CMakeLists.txt +++ b/src/yuzu_cmd/CMakeLists.txt @@ -75,3 +75,7 @@ if (NOT MSVC) $<$:-Wno-unused-parameter> $<$:-Wno-missing-field-initializers>) endif() + +if (PLATFORM_EMSCRIPTEN) + set_target_properties(yuzu-cmd PROPERTIES LINK_FLAGS_RELEASE "--global-base=16777216") +endif() From c7dbea0b2263d4328830aaa3b14e4b5b9b2cc9f2 Mon Sep 17 00:00:00 2001 From: lizzie Date: Tue, 9 Jun 2026 00:49:14 +0000 Subject: [PATCH 08/25] fix wasm flags --- .ci/wasm/build.sh | 9 ++++++++- externals/cmake-modules/DetectPlatform.cmake | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.ci/wasm/build.sh b/.ci/wasm/build.sh index bdaab223e0..27ae9cc218 100644 --- a/.ci/wasm/build.sh +++ b/.ci/wasm/build.sh @@ -71,5 +71,12 @@ emcmake cmake -B "$OUTDIR" -G "Unix Makefiles" \ -DYUZU_USE_BUNDLED_OPENSSL=OFF \ -DYUZU_USE_EXTERNAL_FFMPEG=ON \ -Dzstd_FORCE_BUNDLED=ON \ - -DOpenSSL_FORCE_BUNDLED=ON + -DOpenSSL_FORCE_BUNDLED=ON \ + -DEMSCRIPTEN_SYSTEM_PROCESSOR=wasm \ + -DCMAKE_C_FLAGS="-s MEMORY64 -m64 -pipe -sMEMORY64=1" \ + -DCMAKE_CXX_FLAGS="-s MEMORY64 -m64 -pipe -sMEMORY64=1" \ + -DCMAKE_EXE_LINKER_FLAGS="-sMEMORY64=1 -m64 -Wl,-mwasm64 -sASYNCIFY=1" \ + -DCMAKE_C_LINK_FLAGS="-sMEMORY64=1 -m64 -Wl,-mwasm64 -sASYNCIFY=1" \ + -DCMAKE_CXX_LINK_FLAGS="-sMEMORY64=1 -m64 -Wl,-mwasm64 -sASYNCIFY=1" \ + cmake --build "$OUTDIR" -- -j$NUM_JOBS diff --git a/externals/cmake-modules/DetectPlatform.cmake b/externals/cmake-modules/DetectPlatform.cmake index 5b0035b55d..5c081e6f3d 100644 --- a/externals/cmake-modules/DetectPlatform.cmake +++ b/externals/cmake-modules/DetectPlatform.cmake @@ -117,3 +117,8 @@ if (PLATFORM_EMSCRIPTEN) unset(EMSCRIPTEN_C_FLAGS) unset(EMSCRIPTEN_LINK_FLAGS) endif() + +# awesome +if (PLATFORM_FREEBSD OR PLATFORM_DRAGONFLYBSD) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${CMAKE_SYSROOT}/usr/local/lib") +endif() From cd2833a420ac6414371c7761d6328800087481e0 Mon Sep 17 00:00:00 2001 From: lizzie Date: Tue, 9 Jun 2026 04:03:20 +0000 Subject: [PATCH 09/25] 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 57b6098e0e..81ac8ea458 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -377,6 +377,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 b4c7eae343..24cb2753cb 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() From 46a8a76dbb1f275ce640d036a6aa3fc0078c4de6 Mon Sep 17 00:00:00 2001 From: lizzie Date: Tue, 9 Jun 2026 04:26:28 +0000 Subject: [PATCH 10/25] fix openssl --- CMakeLists.txt | 1 + src/yuzu_cmd/CMakeLists.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 81ac8ea458..d87705d26f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -384,6 +384,7 @@ find_package(Threads REQUIRED) # that we prefer the pthread flag; why is that? I don't know. if (PLATFORM_EMSCRIPTEN) add_compile_options($<$:-pthread>) + add_link_options($<$:-pthread>) endif() find_package(RenderDoc MODULE) diff --git a/src/yuzu_cmd/CMakeLists.txt b/src/yuzu_cmd/CMakeLists.txt index 13b00bdebc..ef2e22c5a0 100644 --- a/src/yuzu_cmd/CMakeLists.txt +++ b/src/yuzu_cmd/CMakeLists.txt @@ -78,6 +78,7 @@ endif() if (PLATFORM_EMSCRIPTEN) target_link_options(yuzu-cmd PRIVATE + -sINITIAL_MEMORY=33554432 -sGLOBAL_BASE=16777216 -sPTHREAD_POOL_SIZE_STRICT=0 -sPTHREAD_POOL_SIZE=navigator.hardwareConcurrency) From a08925c5613d16cafa3492153bc49bec0fd05f1d Mon Sep 17 00:00:00 2001 From: lizzie Date: Tue, 9 Jun 2026 05:14:36 +0000 Subject: [PATCH 11/25] small writeup of wasm --- .ci/wasm/build.sh | 15 ++++++++++++--- .patch/openssl-cmake/0005-wasm-support.patch | 4 ++-- .patch/openssl/0002-wasm-support.patch | 10 +++++----- docs/Caveats.md | 13 +++++++++++++ docs/Deps.md | 8 ++++++++ 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/.ci/wasm/build.sh b/.ci/wasm/build.sh index 27ae9cc218..49c1123db6 100644 --- a/.ci/wasm/build.sh +++ b/.ci/wasm/build.sh @@ -54,6 +54,15 @@ done : "${DEVEL:=true}" : "${OUTDIR:=build}" +# -sMEMORY64 must be specified twice, see below +# The CMake toolchain file will match against MEMORY64 but will fail to match if: +# - it's either -sMEMORY64 +# - or it's either -sMEMORY64=1 +# The line in question: +# if (CMAKE_C_FLAGS MATCHES "MEMORY64") +# However why need to specify -sMEMORY64=1 then? Oh that's because if you didn't set +# the =1, it would assume you meant =0, which equates to not specifying it at all +# This seems to be fixed in later versions but occurs atleast on 4.0.3-git and below. emcmake cmake -B "$OUTDIR" -G "Unix Makefiles" \ -DCMAKE_BUILD_TYPE=${TYPE} \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ @@ -75,8 +84,8 @@ emcmake cmake -B "$OUTDIR" -G "Unix Makefiles" \ -DEMSCRIPTEN_SYSTEM_PROCESSOR=wasm \ -DCMAKE_C_FLAGS="-s MEMORY64 -m64 -pipe -sMEMORY64=1" \ -DCMAKE_CXX_FLAGS="-s MEMORY64 -m64 -pipe -sMEMORY64=1" \ - -DCMAKE_EXE_LINKER_FLAGS="-sMEMORY64=1 -m64 -Wl,-mwasm64 -sASYNCIFY=1" \ - -DCMAKE_C_LINK_FLAGS="-sMEMORY64=1 -m64 -Wl,-mwasm64 -sASYNCIFY=1" \ - -DCMAKE_CXX_LINK_FLAGS="-sMEMORY64=1 -m64 -Wl,-mwasm64 -sASYNCIFY=1" \ + -DCMAKE_EXE_LINKER_FLAGS="-sMEMORY64=1 -m64 -Wl,-mwasm64 -sASYNCIFY=1 -pthread" \ + -DCMAKE_C_LINK_FLAGS="-sMEMORY64=1 -m64 -Wl,-mwasm64 -sASYNCIFY=1 -pthread" \ + -DCMAKE_CXX_LINK_FLAGS="-sMEMORY64=1 -m64 -Wl,-mwasm64 -sASYNCIFY=1 -pthread" \ cmake --build "$OUTDIR" -- -j$NUM_JOBS diff --git a/.patch/openssl-cmake/0005-wasm-support.patch b/.patch/openssl-cmake/0005-wasm-support.patch index 35746a3f4b..31eafac9ad 100644 --- a/.patch/openssl-cmake/0005-wasm-support.patch +++ b/.patch/openssl-cmake/0005-wasm-support.patch @@ -1,5 +1,5 @@ diff --git a/cmake/ConfigureOpenSSL.cmake b/cmake/ConfigureOpenSSL.cmake -index 3012e05..eda6cfb 100644 +index 3012e05..2ae23ff 100644 --- a/cmake/ConfigureOpenSSL.cmake +++ b/cmake/ConfigureOpenSSL.cmake @@ -108,7 +108,8 @@ function(configure_openssl) @@ -31,7 +31,7 @@ index 3012e05..eda6cfb 100644 + COMMAND ${EMSCRIPTEN_CMAKE_WRAPPER} ${CMAKE_COMMAND} -E env "CFLAGS=${CMAKE_C_FLAGS}" "CXXFLAGS=${CMAKE_CXX_FLAGS}" -+ "LDFLAGS=${CMAKE_CXX_LINKER_FLAGS}" ++ "LDFLAGS=${CMAKE_CXX_LINK_FLAGS}" + "CC=${CMAKE_C_COMPILER}" + "CXX=${CMAKE_CXX_COMPILER}" + "LD=${EMSCRIPTEN_LINKER}" diff --git a/.patch/openssl/0002-wasm-support.patch b/.patch/openssl/0002-wasm-support.patch index 4cf7204549..4eecec60f1 100644 --- a/.patch/openssl/0002-wasm-support.patch +++ b/.patch/openssl/0002-wasm-support.patch @@ -1,5 +1,5 @@ diff --git a/Configurations/10-main.conf b/Configurations/10-main.conf -index e62721e..6fcea0d 100644 +index e62721e..243feb4 100644 --- a/Configurations/10-main.conf +++ b/Configurations/10-main.conf @@ -1970,6 +1970,26 @@ my %targets = ( @@ -10,8 +10,8 @@ index e62721e..6fcea0d 100644 + inherit_from => [ "BASE_unix" ], + CC => "emcc", + CXX => "emc++", -+ cflags => add("--target=wasm32-unknown-emscripten"), -+ cxxflags => add("--target=wasm32-unknown-emscripten"), ++ cflags => combine("--target=wasm32-unknown-emscripten", threads("-pthread")), ++ cxxflags => combine("--target=wasm32-unknown-emscripten", threads("-pthread")), + lib_cppflags => add("-DL_ENDIAN"), + bn_ops => "THIRTY_TWO_BIT", + }, @@ -19,8 +19,8 @@ index e62721e..6fcea0d 100644 + inherit_from => [ "BASE_unix" ], + CC => "emcc", + CXX => "emc++", -+ cflags => add("--target=wasm64-unknown-emscripten"), -+ cxxflags => add("--target=wasm64-unknown-emscripten"), ++ cflags => combine("--target=wasm64-unknown-emscripten", threads("-pthread")), ++ cxxflags => combine("--target=wasm64-unknown-emscripten", threads("-pthread")), + lib_cppflags => add("-DL_ENDIAN"), + bn_ops => "SIXTY_FOUR_BIT_LONG", + }, diff --git a/docs/Caveats.md b/docs/Caveats.md index b86edf4d75..c03e402141 100644 --- a/docs/Caveats.md +++ b/docs/Caveats.md @@ -12,6 +12,7 @@ - [NetBSD](#netbsd) - [MSYS2](#msys2) - [RedoxOS](#redoxos) +- [WebAssembly](#webassembly) ## Arch Linux @@ -242,3 +243,15 @@ find ./*/ -name "*.dll" | while read -r dll; do deps "$dll"; done The package install may randomly hang at times, in which case it has to be restarted. ALWAYS do a `sudo pkg update` or the chances of it hanging will be close to 90%. If "multiple" installs fail at once, try installing 1 by 1 the packages. When CMake invokes certain file syscalls - it may sometimes cause crashes or corruptions on the (kernel?) address space - so reboot the system if there is a "hang" in CMake. + +## WebAssembly + +**It doesn't run on a browser yet.** + +WebAssembly or "WASM" for short is a *mainly 32-bit* virtual "architecture" which we only bootstrap on 64-bit only. This means not only the program runs 2x slower than it would due to using JS BigInt, it also means we need to go out of our way to enable proper 64-bit support via `-sMEMORY64=1`, however once again, some Emscripten quirks force us to specify `-s MEMORY64` and `-sMEMORY64=1` at the same time: see the [CI build script](../.ci/wasm/build.sh). + +The WebAssembly target is very heavy on resources and requires at least 4 times the normal amount of resources that a native build would. Additionally, the only supported environment is `node.js` and `wasmtime`, with browser support being an afterthought (PRs welcome!). + +To run the binary (after building) you should be fine with `node ./eden-cli.js`. For obvious reasons no Qt frontend is available on WASM, support for Vulkan is done charily via [llvmpipe2wasm](https://github.com/Devsh-Graphics-Programming/llvmpipe2wasm). + +2026-06-09: As of writing, no Dynarmic-based JIT is possible on this target, full interpreted emulation is the only reasonable option. While there is some efforts on making a JIT like [here](https://github.com/wingo/wasm-jit) or [here](https://wingolog.org/archives/2022/08/18/just-in-time-code-generation-within-webassembly), the result is so latency expensive we're better off using an interpreter instead. diff --git a/docs/Deps.md b/docs/Deps.md index 2b73ecb4ac..12adb7837b 100644 --- a/docs/Deps.md +++ b/docs/Deps.md @@ -361,6 +361,14 @@ pkgman install git cmake patch libfmt_devel nlohmann_json lz4_devel opus_devel b [Caveats](./Caveats.md#haikuos). + +
+WebAssembly + +Emscripten: The default installation should provide enough. + +[Caveats](./Caveats.md#wasm). +
RedoxOS From 77bce8f70923f4d1f33a03bee76d091b0ae6edce Mon Sep 17 00:00:00 2001 From: lizzie Date: Tue, 9 Jun 2026 05:50:23 +0000 Subject: [PATCH 12/25] 10gb of ram --- src/yuzu_cmd/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/yuzu_cmd/CMakeLists.txt b/src/yuzu_cmd/CMakeLists.txt index ef2e22c5a0..cf1604293a 100644 --- a/src/yuzu_cmd/CMakeLists.txt +++ b/src/yuzu_cmd/CMakeLists.txt @@ -77,8 +77,9 @@ if (NOT MSVC) endif() if (PLATFORM_EMSCRIPTEN) + # 10GB is required... yikes! target_link_options(yuzu-cmd PRIVATE - -sINITIAL_MEMORY=33554432 + -sINITIAL_MEMORY=10737418240 -sGLOBAL_BASE=16777216 -sPTHREAD_POOL_SIZE_STRICT=0 -sPTHREAD_POOL_SIZE=navigator.hardwareConcurrency) From c25c531f5ddfd361f23512ce3fd30d013ef4b086 Mon Sep 17 00:00:00 2001 From: lizzie Date: Tue, 9 Jun 2026 21:21:22 +0000 Subject: [PATCH 13/25] fixup caveats + add miniserver --- docs/Caveats.md | 4 +- src/yuzu_cmd/CMakeLists.txt | 4 +- tools/README.md | 1 + tools/miniserver.js | 100 ++++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 tools/miniserver.js diff --git a/docs/Caveats.md b/docs/Caveats.md index c03e402141..3b905370e0 100644 --- a/docs/Caveats.md +++ b/docs/Caveats.md @@ -250,7 +250,9 @@ When CMake invokes certain file syscalls - it may sometimes cause crashes or cor WebAssembly or "WASM" for short is a *mainly 32-bit* virtual "architecture" which we only bootstrap on 64-bit only. This means not only the program runs 2x slower than it would due to using JS BigInt, it also means we need to go out of our way to enable proper 64-bit support via `-sMEMORY64=1`, however once again, some Emscripten quirks force us to specify `-s MEMORY64` and `-sMEMORY64=1` at the same time: see the [CI build script](../.ci/wasm/build.sh). -The WebAssembly target is very heavy on resources and requires at least 4 times the normal amount of resources that a native build would. Additionally, the only supported environment is `node.js` and `wasmtime`, with browser support being an afterthought (PRs welcome!). +The WebAssembly target is very heavy on resources and requires at least 4 times the normal amount of resources that a native build would. Additionally, the only supported environment is Firefox at the moment, node.js and `wasmtime are not supported (PRs welcome!) + +If running under Firefox and you hit "out of memory" on dev console, close the entire tab, then open it back again, see [this issue](https://github.com/emscripten-core/emscripten/issues/8126). To run the binary (after building) you should be fine with `node ./eden-cli.js`. For obvious reasons no Qt frontend is available on WASM, support for Vulkan is done charily via [llvmpipe2wasm](https://github.com/Devsh-Graphics-Programming/llvmpipe2wasm). diff --git a/src/yuzu_cmd/CMakeLists.txt b/src/yuzu_cmd/CMakeLists.txt index cf1604293a..8db965b80d 100644 --- a/src/yuzu_cmd/CMakeLists.txt +++ b/src/yuzu_cmd/CMakeLists.txt @@ -79,8 +79,10 @@ endif() if (PLATFORM_EMSCRIPTEN) # 10GB is required... yikes! target_link_options(yuzu-cmd PRIVATE - -sINITIAL_MEMORY=10737418240 + -sALLOW_MEMORY_GROWTH=1 + -sMAXIMUM_MEMORY=10737418240 -sGLOBAL_BASE=16777216 + -sEXPORTED_RUNTIME_METHODS="['FS']" -sPTHREAD_POOL_SIZE_STRICT=0 -sPTHREAD_POOL_SIZE=navigator.hardwareConcurrency) endif() diff --git a/tools/README.md b/tools/README.md index cde6a21464..79cc2c3fb6 100644 --- a/tools/README.md +++ b/tools/README.md @@ -30,6 +30,7 @@ Tools for Eden and other subprojects. When adding new scripts please use `#!/bin - `find-unused-strings.sh`: Find any unused strings in the Android app (XML -> Kotlin). - `cpp-lint.sh`: Homemade dumb C++ linter. - `fuzzsettings.cpp`: Fuzz settings files. +- `miniserver.js`: Make a quick server that serves a page with the WASM on it, takes a single argument which is the path to the build directory containing *both* `eden-cli.js` and `eden-cli.wasm`. Run via `node.js`, `wasmtime` isn't supported. ## Android diff --git a/tools/miniserver.js b/tools/miniserver.js new file mode 100644 index 0000000000..6f4bd35a14 --- /dev/null +++ b/tools/miniserver.js @@ -0,0 +1,100 @@ +#!/usr/local/env node +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +import { createServer } from 'http'; +import { readFile } from 'fs'; +import { join } from 'path'; + +// DO NOT RUN THIS IN ANY PRODUCTION ENVIRONMENT EVER +const server = createServer((req, res) => { + console.log(`reuqest? ${req.url}`); + if (req.url === '/') { + // https://developer.mozilla.org/en-US/docs/WebAssembly/Guides/Loading_and_running + // If your browser doesn't support fetch... HAHA GET FUCKED + res.writeHead(200, { + 'Content-Type': 'text/html', + 'Cross-Origin-Opener-Policy': 'same-origin', + 'Cross-Origin-Embedder-Policy': 'require-corp' + }); + res.end(` + + +eden-cli + + + + +`); + } else if (req.url === '/eden-cli.js') { + readFile(join(build_dir, 'eden-cli.js'), (err, content) => { + res.writeHead(200, { + 'Content-Type': 'application/javascript', + 'Cross-Origin-Opener-Policy': 'same-origin', + 'Cross-Origin-Embedder-Policy': 'require-corp' + }); + res.end(content, 'utf-8'); + }); + } else if (req.url === '/eden-cli.wasm') { + readFile(join(build_dir, 'eden-cli.wasm'), (err, content) => { + res.writeHead(200, { + 'Content-Type': 'application/wasm', + 'Cross-Origin-Opener-Policy': 'same-origin', + 'Cross-Origin-Embedder-Policy': 'require-corp' + }); + res.end(content, 'utf-8'); + }); + } +}); + +const build_dir = process.argv[2]; +if (build_dir === undefined) { + console.log(`Usage: ${process.argv[0]} ${process.argv[1]} [build directory]`); +} else { + server.listen(2210, () => { + console.log(`${process.argv[0]} ${process.argv[1]} http://localhost:2210`); + console.log(`build dir = ${build_dir}`); + }); +} From 7f5051767d4dd8619c5d4d8c5f97746ed5dc29e9 Mon Sep 17 00:00:00 2001 From: lizzie Date: Tue, 9 Jun 2026 21:52:13 +0000 Subject: [PATCH 14/25] fixup make program --- externals/ffmpeg/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/externals/ffmpeg/CMakeLists.txt b/externals/ffmpeg/CMakeLists.txt index 82fd08d7b0..3a1b506125 100644 --- a/externals/ffmpeg/CMakeLists.txt +++ b/externals/ffmpeg/CMakeLists.txt @@ -344,7 +344,7 @@ else() OUTPUT ${FFmpeg_BUILD_LIBRARIES} COMMAND - ${MAKE} ${FFmpeg_MAKE_ARGS} + ${MAKE_PROGRAM} ${FFmpeg_MAKE_ARGS} WORKING_DIRECTORY ${FFmpeg_BUILD_DIR} ) From abc7ad2129601e5d052349e0af522ce9033fea15 Mon Sep 17 00:00:00 2001 From: lizzie Date: Wed, 10 Jun 2026 00:03:43 +0000 Subject: [PATCH 15/25] emscripten friendly sdl loop --- docs/Caveats.md | 2 + src/yuzu_cmd/CMakeLists.txt | 5 +- tools/miniserver.js | 99 +++++++++++++++++++++++-------------- 3 files changed, 66 insertions(+), 40 deletions(-) mode change 100644 => 100755 tools/miniserver.js diff --git a/docs/Caveats.md b/docs/Caveats.md index 3b905370e0..bc393f1593 100644 --- a/docs/Caveats.md +++ b/docs/Caveats.md @@ -256,4 +256,6 @@ If running under Firefox and you hit "out of memory" on dev console, close the e To run the binary (after building) you should be fine with `node ./eden-cli.js`. For obvious reasons no Qt frontend is available on WASM, support for Vulkan is done charily via [llvmpipe2wasm](https://github.com/Devsh-Graphics-Programming/llvmpipe2wasm). +If you run into the error "acorn.js can't be found" check [this associated issue](https://github.com/emscripten-core/emscripten/issues/13368), the fix in short is `npm --global install acorn`. On FreeBSD you could run `npm` under root, or you could do the sane thing and do `sudo chown -R $USER /usr/local/lib/node_modules/ /usr/local/bin/` (remember to restore permissions afterwards!) unless you wish to run `npm` under root which is generally a bad idea. + 2026-06-09: As of writing, no Dynarmic-based JIT is possible on this target, full interpreted emulation is the only reasonable option. While there is some efforts on making a JIT like [here](https://github.com/wingo/wasm-jit) or [here](https://wingolog.org/archives/2022/08/18/just-in-time-code-generation-within-webassembly), the result is so latency expensive we're better off using an interpreter instead. diff --git a/src/yuzu_cmd/CMakeLists.txt b/src/yuzu_cmd/CMakeLists.txt index 8db965b80d..616b865e73 100644 --- a/src/yuzu_cmd/CMakeLists.txt +++ b/src/yuzu_cmd/CMakeLists.txt @@ -77,12 +77,13 @@ if (NOT MSVC) endif() if (PLATFORM_EMSCRIPTEN) - # 10GB is required... yikes! + # 10GB is required at max... yikes! target_link_options(yuzu-cmd PRIVATE -sALLOW_MEMORY_GROWTH=1 + -sINITIAL_MEMORY=33554432 -sMAXIMUM_MEMORY=10737418240 -sGLOBAL_BASE=16777216 - -sEXPORTED_RUNTIME_METHODS="['FS']" + -sEXPORTED_RUNTIME_METHODS=['FS'] -sPTHREAD_POOL_SIZE_STRICT=0 -sPTHREAD_POOL_SIZE=navigator.hardwareConcurrency) endif() diff --git a/tools/miniserver.js b/tools/miniserver.js old mode 100644 new mode 100755 index 6f4bd35a14..f16d463573 --- a/tools/miniserver.js +++ b/tools/miniserver.js @@ -1,4 +1,4 @@ -#!/usr/local/env node +#!/usr/bin/env node // SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later @@ -21,51 +21,61 @@ const server = createServer((req, res) => { eden-cli + + - - `); } else if (req.url === '/eden-cli.js') { @@ -86,12 +96,25 @@ function finished_body() { }); res.end(content, 'utf-8'); }); + } else if (req.url === '/game.nro') { + readFile(nro_file, (err, content) => { + res.writeHead(200, { + 'Content-Type': 'application/wasm', + 'Cross-Origin-Opener-Policy': 'same-origin', + 'Cross-Origin-Embedder-Policy': 'require-corp' + }); + res.end(content, 'utf-8'); + }); + } else { + res.writeHead(404, {}); + res.end('', 'utf-8'); } }); const build_dir = process.argv[2]; -if (build_dir === undefined) { - console.log(`Usage: ${process.argv[0]} ${process.argv[1]} [build directory]`); +const nro_file = process.argv[3]; +if (typeof build_dir == "undefined" || typeof nro_file == "undefined") { + console.log(`Usage: ${process.argv[0]} ${process.argv[1]} [build directory] [NRO file]`); } else { server.listen(2210, () => { console.log(`${process.argv[0]} ${process.argv[1]} http://localhost:2210`); From ff81b362f5e3920a4e1dca2082f5df9acbdc7dde Mon Sep 17 00:00:00 2001 From: lizzie Date: Wed, 10 Jun 2026 00:06:37 +0000 Subject: [PATCH 16/25] --null-renderer --- tools/miniserver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/miniserver.js b/tools/miniserver.js index f16d463573..96dee9aa3a 100755 --- a/tools/miniserver.js +++ b/tools/miniserver.js @@ -48,7 +48,7 @@ var Module = { //do not prepend var }; var tty_stdout = document.createElement('div'); document.body.appendChild(tty_stdout); -Module.arguments = ['game.nro']; +Module.arguments = ['--null-render', 'game.nro']; var gameNroFileBuffer = {}; From eea821c4f368a5d237c8efa6cab7343a5fa1e4f4 Mon Sep 17 00:00:00 2001 From: lizzie Date: Wed, 10 Jun 2026 00:35:39 +0000 Subject: [PATCH 17/25] add filter options --- tools/miniserver.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tools/miniserver.js b/tools/miniserver.js index 96dee9aa3a..44a7d7ca30 100755 --- a/tools/miniserver.js +++ b/tools/miniserver.js @@ -8,7 +8,7 @@ import { join } from 'path'; // DO NOT RUN THIS IN ANY PRODUCTION ENVIRONMENT EVER const server = createServer((req, res) => { - console.log(`reuqest? ${req.url}`); + console.log(`get ${req.url}`); if (req.url === '/') { // https://developer.mozilla.org/en-US/docs/WebAssembly/Guides/Loading_and_running // If your browser doesn't support fetch... HAHA GET FUCKED @@ -22,40 +22,41 @@ const server = createServer((req, res) => { eden-cli - + +
+ +
+
From 04852efa63ca80a25af2b0f50ca683583b82e3e6 Mon Sep 17 00:00:00 2001 From: lizzie Date: Wed, 10 Jun 2026 03:32:01 +0000 Subject: [PATCH 21/25] boost asio fix in android --- src/core/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index fbe310876c..8cd002b2c3 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1215,7 +1215,7 @@ target_link_libraries(core PUBLIC common PRIVATE audio_core hid_core network vid if (BOOST_NO_HEADERS) target_link_libraries(core PUBLIC Boost::container Boost::heap Boost::crc) if (NOT PLATFORM_EMSCRIPTEN) - target_link_libraries(core PRIVATE Boost::asio Boost::process) + target_link_libraries(core PUBLIC Boost::asio Boost::process) endif() else() target_link_libraries(core PUBLIC Boost::headers) From 24fb119204199a2fe17940c9ad275050ca8a9a6b Mon Sep 17 00:00:00 2001 From: lizzie Date: Wed, 10 Jun 2026 04:30:19 +0000 Subject: [PATCH 22/25] ok no broken make --- externals/ffmpeg/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/externals/ffmpeg/CMakeLists.txt b/externals/ffmpeg/CMakeLists.txt index 3a1b506125..82fd08d7b0 100644 --- a/externals/ffmpeg/CMakeLists.txt +++ b/externals/ffmpeg/CMakeLists.txt @@ -344,7 +344,7 @@ else() OUTPUT ${FFmpeg_BUILD_LIBRARIES} COMMAND - ${MAKE_PROGRAM} ${FFmpeg_MAKE_ARGS} + ${MAKE} ${FFmpeg_MAKE_ARGS} WORKING_DIRECTORY ${FFmpeg_BUILD_DIR} ) From 63230d247ea710f027b7367671978d8e3f30023d Mon Sep 17 00:00:00 2001 From: lizzie Date: Wed, 24 Jun 2026 04:19:42 +0000 Subject: [PATCH 23/25] build adjustments --- src/common/host_memory.cpp | 45 ++++++++++++++------------------------ src/common/host_memory.h | 2 -- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 077049f3e6..d2bbbf00b3 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp @@ -695,21 +695,10 @@ HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_) backing_base = fallback_buffer->data(); virtual_base = nullptr; #else - bool has_memfd = true; // all platforms support it -#ifdef _WIN32 - // EXCEPT WINDOWS who may not (Windows 8.1, 7, Vista, etc) - DynamicLibrary kernelbase_dll("KernelBase"); - has_memfd = kernelbase_dll.IsOpen(); - if (has_memfd) { - PFN_CreateFileMapping2 p{}; - GetFuncAddress(kernelbase_dll, "CreateFileMapping2", p); - has_memfd = p != nullptr; - } -#endif // Try to allocate a fastmem arena. // The implementation will fail with std::bad_alloc on errors. impl = std::make_unique(AlignUp(backing_size, PageAlignment), AlignUp(virtual_size, PageAlignment) + HugePageSize); - if (has_memfd && impl->Init()) { + if (impl->Init()) { backing_base = impl->backing_base; virtual_base = impl->virtual_base; if (virtual_base) { @@ -719,8 +708,7 @@ HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_) } } else { impl.reset(); - LOG_WARNING(HW_Memory, "Platform doesn't support fastmem"); -#ifdef _WIN32 + LOG_WARNING(HW_Memory, "Platform can support fastmem, but can't create it"); fallback_buffer.emplace(backing_size); backing_base = fallback_buffer->data(); virtual_base = nullptr; @@ -734,13 +722,8 @@ HostMemory::HostMemory(HostMemory&&) noexcept = default; HostMemory& HostMemory::operator=(HostMemory&&) noexcept = default; -#if defined(__OPENORBIS__) || defined(__managarm__) || defined(__wasi__) || defined(__EMSCRIPTEN__) -void HostMemory::Map(size_t virtual_offset, size_t host_offset, size_t length, MemoryPermission perms, bool separate_heap) {} -void HostMemory::Unmap(size_t virtual_offset, size_t length, bool separate_heap) {} -void HostMemory::Protect(size_t virtual_offset, size_t length, MemoryPermission perm) {} -void HostMemory::EnableDirectMappedAddress() {} -#else void HostMemory::Map(size_t virtual_offset, size_t host_offset, size_t length, MemoryPermission perms, bool separate_heap) { +#if !(defined(__OPENORBIS__) || defined(__managarm__) || defined(__wasi__) || defined(__EMSCRIPTEN__)) ASSERT(virtual_offset % PageAlignment == 0); ASSERT(host_offset % PageAlignment == 0); ASSERT(length % PageAlignment == 0); @@ -750,9 +733,11 @@ void HostMemory::Map(size_t virtual_offset, size_t host_offset, size_t length, M return; } impl->Map(virtual_offset + virtual_base_offset, host_offset, length, perms); +#endif } void HostMemory::Unmap(size_t virtual_offset, size_t length, bool separate_heap) { +#if !(defined(__OPENORBIS__) || defined(__managarm__) || defined(__wasi__) || defined(__EMSCRIPTEN__)) ASSERT(virtual_offset % PageAlignment == 0); ASSERT(length % PageAlignment == 0); ASSERT(virtual_offset + length <= virtual_size); @@ -760,9 +745,11 @@ void HostMemory::Unmap(size_t virtual_offset, size_t length, bool separate_heap) return; } impl->Unmap(virtual_offset + virtual_base_offset, length); +#endif } void HostMemory::Protect(size_t virtual_offset, size_t length, MemoryPermission perm) { +#if !(defined(__OPENORBIS__) || defined(__managarm__) || defined(__wasi__) || defined(__EMSCRIPTEN__)) ASSERT(virtual_offset % PageAlignment == 0); ASSERT(length % PageAlignment == 0); ASSERT(virtual_offset + length <= virtual_size); @@ -773,18 +760,20 @@ void HostMemory::Protect(size_t virtual_offset, size_t length, MemoryPermission const bool write = True(perm & MemoryPermission::Write); const bool execute = True(perm & MemoryPermission::Execute); impl->Protect(virtual_offset + virtual_base_offset, length, read, write, execute); -} - -void HostMemory::EnableDirectMappedAddress() { - if (impl) { - impl->EnableDirectMappedAddress(); - virtual_size += reinterpret_cast(virtual_base); - } -} #endif +} void HostMemory::ClearBackingRegion(size_t physical_offset, size_t length, u32 fill_value) { std::memset(backing_base + physical_offset, fill_value, length); } +void HostMemory::EnableDirectMappedAddress() { +#if !(defined(__OPENORBIS__) || defined(__managarm__) || defined(__wasi__) || defined(__EMSCRIPTEN__)) + if (impl) { + impl->EnableDirectMappedAddress(); + virtual_size += reinterpret_cast(virtual_base); + } +#endif +} + } // namespace Common diff --git a/src/common/host_memory.h b/src/common/host_memory.h index 34e6726f11..00aa75a371 100644 --- a/src/common/host_memory.h +++ b/src/common/host_memory.h @@ -86,9 +86,7 @@ private: u8* virtual_base{}; size_t virtual_base_offset{}; // Windows requires it for kernels whom lack proper support for some functions! -#if defined(__OPENORBIS__) || defined(__managarm__) || defined(_WIN32) || defined(__EMSCRIPTEN__) std::optional> fallback_buffer; -#endif }; } // namespace Common From 59f01af89676a7aab6155f8ce6704b9f9e2adc90 Mon Sep 17 00:00:00 2001 From: lizzie Date: Sat, 27 Jun 2026 17:56:39 +0000 Subject: [PATCH 24/25] prepare --- .ci/wasm/build.sh | 9 +++++---- cpmfile.json | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.ci/wasm/build.sh b/.ci/wasm/build.sh index 49c1123db6..3b6dc932d3 100644 --- a/.ci/wasm/build.sh +++ b/.ci/wasm/build.sh @@ -65,7 +65,6 @@ done # This seems to be fixed in later versions but occurs atleast on 4.0.3-git and below. emcmake cmake -B "$OUTDIR" -G "Unix Makefiles" \ -DCMAKE_BUILD_TYPE=${TYPE} \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -DENABLE_OPENGL=OFF \ -DENABLE_LTO=OFF \ -DENABLE_QT=OFF \ @@ -76,7 +75,9 @@ emcmake cmake -B "$OUTDIR" -G "Unix Makefiles" \ -DENABLE_UPDATE_CHECKER=OFF \ -DENABLE_WEB_SERVICE=OFF \ -DUSE_DISCORD_PRESENCE=OFF \ + -DENABLE_WIFI_SCAN=OFF \ -DUSE_FASTER_LINKER=ON \ + -DYUZU_STATIC_BUILD=ON \ -DYUZU_USE_BUNDLED_OPENSSL=OFF \ -DYUZU_USE_EXTERNAL_FFMPEG=ON \ -Dzstd_FORCE_BUNDLED=ON \ @@ -84,8 +85,8 @@ emcmake cmake -B "$OUTDIR" -G "Unix Makefiles" \ -DEMSCRIPTEN_SYSTEM_PROCESSOR=wasm \ -DCMAKE_C_FLAGS="-s MEMORY64 -m64 -pipe -sMEMORY64=1" \ -DCMAKE_CXX_FLAGS="-s MEMORY64 -m64 -pipe -sMEMORY64=1" \ - -DCMAKE_EXE_LINKER_FLAGS="-sMEMORY64=1 -m64 -Wl,-mwasm64 -sASYNCIFY=1 -pthread" \ - -DCMAKE_C_LINK_FLAGS="-sMEMORY64=1 -m64 -Wl,-mwasm64 -sASYNCIFY=1 -pthread" \ - -DCMAKE_CXX_LINK_FLAGS="-sMEMORY64=1 -m64 -Wl,-mwasm64 -sASYNCIFY=1 -pthread" \ + -DCMAKE_EXE_LINKER_FLAGS="-sMEMORY64=1 -m64 -Wl,-mwasm64 -sASYNCIFY=1" \ + -DCMAKE_C_LINK_FLAGS="-sMEMORY64=1 -m64 -Wl,-mwasm64 -sASYNCIFY=1" \ + -DCMAKE_CXX_LINK_FLAGS="-sMEMORY64=1 -m64 -Wl,-mwasm64 -sASYNCIFY=1" cmake --build "$OUTDIR" -- -j$NUM_JOBS diff --git a/cpmfile.json b/cpmfile.json index 149d73d465..fad2504ad7 100644 --- a/cpmfile.json +++ b/cpmfile.json @@ -115,7 +115,7 @@ "find_args": "MODULE GLOBAL", "hash": "159ed94965018f2a371d45a3bfc1961e5fb1549e501ded70a6b4532d7fe99d0579c18b5195aff6e35f96f399b426cea2650ec9fb75ef80d4c9edeccb51f2e6c9", "options": [ - "HTTPLIB_REQUIRE_OPENSSL ON", + "HTTPLIB_REQUIRE_OPENSSL OFF", "HTTPLIB_DISABLE_MACOSX_AUTOMATIC_ROOT_CERTIFICATES ON" ], "patches": [ @@ -197,7 +197,8 @@ "min_version": "3.0.0", "package": "OpenSSL", "patches": [ - "0001-add-bundled-cert.patch" + "0001-add-bundled-cert.patch", + "0002-wasm-support.patch" ], "repo": "openssl/openssl", "version": "openssl-3.6.2" From ab932a21f524bec1f704c6c16dc1338c79d5e649 Mon Sep 17 00:00:00 2001 From: lizzie Date: Tue, 1 Sep 2026 21:26:37 +0000 Subject: [PATCH 25/25] PLATFORM_EMSCRIPTEN -> EMSCRIPTEN --- CMakeLists.txt | 4 ++-- externals/cmake-modules/DetectPlatform.cmake | 4 ++-- externals/ffmpeg/CMakeLists.txt | 12 +++++------- src/common/CMakeLists.txt | 2 +- src/core/CMakeLists.txt | 4 ++-- src/input_common/CMakeLists.txt | 2 +- src/yuzu_cmd/CMakeLists.txt | 2 +- 7 files changed, 14 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d87705d26f..8cb9698071 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -382,7 +382,7 @@ find_package(Threads REQUIRED) # 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) +if (EMSCRIPTEN) add_compile_options($<$:-pthread>) add_link_options($<$:-pthread>) endif() @@ -414,7 +414,7 @@ set(BUILD_TESTING OFF) set(ENABLE_TESTING OFF) # boost -if (PLATFORM_EMSCRIPTEN) +if (EMSCRIPTEN) set(BOOST_INCLUDE_LIBRARIES algorithm icl pool container heap headers filesystem crc variant) set(BOOST_CONTAINER_HEADER_ONLY ON) else() diff --git a/externals/cmake-modules/DetectPlatform.cmake b/externals/cmake-modules/DetectPlatform.cmake index 5c081e6f3d..52735a1d6f 100644 --- a/externals/cmake-modules/DetectPlatform.cmake +++ b/externals/cmake-modules/DetectPlatform.cmake @@ -101,7 +101,7 @@ if (MINGW) "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${MINGW_FLAGS}") endif() -if (PLATFORM_EMSCRIPTEN) +if (EMSCRIPTEN) set(EMSCRIPTEN_C_FLAGS "-s MEMORY64 -m64 -pipe -sMEMORY64=1") set(EMSCRIPTEN_LINK_FLAGS "-sMEMORY64=1 -m64 -Wl,-mwasm64 -sASYNCIFY=1") @@ -119,6 +119,6 @@ if (PLATFORM_EMSCRIPTEN) endif() # awesome -if (PLATFORM_FREEBSD OR PLATFORM_DRAGONFLYBSD) +if (FREEBSD OR DRAGONFLYBSD) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${CMAKE_SYSROOT}/usr/local/lib") endif() diff --git a/externals/ffmpeg/CMakeLists.txt b/externals/ffmpeg/CMakeLists.txt index 82fd08d7b0..4c969f8714 100644 --- a/externals/ffmpeg/CMakeLists.txt +++ b/externals/ffmpeg/CMakeLists.txt @@ -41,9 +41,8 @@ if (NOT YUZU_USE_BUNDLED_FFMPEG) # If YOUR OS/platform has actual native support: # 1. fucking congrats # 2. feel free to add it on the condition below - if (NOT (PLATFORM_NETBSD OR PLATFORM_SUN OR PLATFORM_FREEBSD - OR PLATFORM_OPENBSD OR PLATFORM_DRAGONFLYBSD OR PLATFORM_HAIKU - OR PLATFORM_LINUX OR PLATFORM_MSYS OR WIN32 OR ANDROID OR APPLE)) + if (NOT (NETBSD OR SOLARIS OR FREEBSD OR OPENBSD OR DRAGONFLYBSD OR HAIKU + OR LINUX OR MSYS OR WIN32 OR ANDROID OR APPLE)) set(FFmpeg_SYSTEM_NAME "none") endif() # TODO: Can we really do better? Auto-detection? Something clever? @@ -51,9 +50,8 @@ if (NOT YUZU_USE_BUNDLED_FFMPEG) --enable-cross-compile --arch="${CMAKE_SYSTEM_PROCESSOR}" --target-os="${FFmpeg_SYSTEM_NAME}") - if (PLATFORM_EMSCRIPTEN) - # funniest trolling from emscripten, such a classic! - # maybe I should PR so they use CMAKE_SYSROOT... y'know? + # Emscripten doesn't use CMAKE_SYSROOT I'm afraid, but it does well use EMSCRIPTEN_SYSROOT + if (EMSCRIPTEN) list(APPEND FFmpeg_CROSS_COMPILE_FLAGS --sysroot="${EMSCRIPTEN_SYSROOT}") else() list(APPEND FFmpeg_CROSS_COMPILE_FLAGS --sysroot="${CMAKE_SYSROOT}") @@ -277,7 +275,7 @@ else() # Some SDKs (especially wasm) require us, actually, WANT us to use their "emconfigure" # otherwise they will cry a billion tears - if (PLATFORM_EMSCRIPTEN) + if (EMSCRIPTEN) find_program(FFmpeg_CONFIGURE_WRAPPER emconfigure REQUIRED) else() find_program(FFmpeg_CONFIGURE_WRAPPER bash REQUIRED) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 961977ff83..4a9e46bcbd 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -237,7 +237,7 @@ else() endif() target_link_libraries(common PRIVATE OpenSSL::SSL) target_link_libraries(common PUBLIC Boost::filesystem httplib::httplib nlohmann_json::nlohmann_json) -if (NOT PLATFORM_EMSCRIPTEN) +if (NOT EMSCRIPTEN) # Emscripten is: "bring your own implementation", boost doesn't add upstream support sadly target_link_libraries(common PRIVATE Boost::context) endif() diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 8cd002b2c3..c7f0e89362 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1162,7 +1162,7 @@ add_library(core STATIC tools/freezer.h tools/renderdoc.cpp tools/renderdoc.h) -if (NOT PLATFORM_EMSCRIPTEN) +if (NOT EMSCRIPTEN) # incompatible with wasm's async model target_sources(core PRIVATE debugger/gdbstub.cpp @@ -1214,7 +1214,7 @@ target_link_libraries(core PUBLIC common PRIVATE audio_core hid_core network vid if (BOOST_NO_HEADERS) target_link_libraries(core PUBLIC Boost::container Boost::heap Boost::crc) - if (NOT PLATFORM_EMSCRIPTEN) + if (NOT EMSCRIPTEN) target_link_libraries(core PUBLIC Boost::asio Boost::process) endif() else() diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 01cf6a52f2..d857a27528 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt @@ -33,7 +33,7 @@ add_library(input_common STATIC input_poller.h main.cpp main.h) -if (NOT PLATFORM_EMSCRIPTEN) +if (NOT EMSCRIPTEN) target_sources(input_common PRIVATE drivers/udp_client.cpp drivers/udp_client.h) diff --git a/src/yuzu_cmd/CMakeLists.txt b/src/yuzu_cmd/CMakeLists.txt index 616b865e73..7ad9c05715 100644 --- a/src/yuzu_cmd/CMakeLists.txt +++ b/src/yuzu_cmd/CMakeLists.txt @@ -76,7 +76,7 @@ if (NOT MSVC) $<$:-Wno-missing-field-initializers>) endif() -if (PLATFORM_EMSCRIPTEN) +if (EMSCRIPTEN) # 10GB is required at max... yikes! target_link_options(yuzu-cmd PRIVATE -sALLOW_MEMORY_GROWTH=1