diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 19217d54..eaca04f9 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -1,6 +1,7 @@ -set(UNICORN_ARCH "x86" CACHE STRING "") - -add_subdirectory(unicorn) +if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + set(UNICORN_ARCH "x86" CACHE STRING "") + add_subdirectory(unicorn) +endif() ########################################## diff --git a/src/backends/CMakeLists.txt b/src/backends/CMakeLists.txt index 12d192df..49734038 100644 --- a/src/backends/CMakeLists.txt +++ b/src/backends/CMakeLists.txt @@ -1,4 +1,6 @@ -add_subdirectory(unicorn-emulator) +if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + add_subdirectory(unicorn-emulator) +endif() if (MOMO_ENABLE_RUST_CODE) add_subdirectory(icicle-emulator) diff --git a/src/backends/icicle-emulator/icicle-bridge/CMakeLists.txt b/src/backends/icicle-emulator/icicle-bridge/CMakeLists.txt index 73ea9f1d..d64c0d21 100644 --- a/src/backends/icicle-emulator/icicle-bridge/CMakeLists.txt +++ b/src/backends/icicle-emulator/icicle-bridge/CMakeLists.txt @@ -13,7 +13,9 @@ endif() set(CARGO_TRIPLE) set(CARGO_OPTIONS) -if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 4) +if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + set(CARGO_TRIPLE "wasm32-unknown-emscripten") +elseif(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 4) set(CARGO_TRIPLE "i686-pc-windows-msvc") elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS") set(CARGO_TRIPLE "aarch64-apple-ios") diff --git a/src/common/platform/compiler.hpp b/src/common/platform/compiler.hpp index 5cece6a8..07fc82c2 100644 --- a/src/common/platform/compiler.hpp +++ b/src/common/platform/compiler.hpp @@ -13,6 +13,8 @@ #define OS_MAC #elif defined(__linux__) #define OS_LINUX +#elif defined(__EMSCRIPTEN__) +#define OS_EMSCRIPTEN #else #error "Unsupported platform" #endif diff --git a/src/windows-emulator/CMakeLists.txt b/src/windows-emulator/CMakeLists.txt index 16167e84..94ec8aa2 100644 --- a/src/windows-emulator/CMakeLists.txt +++ b/src/windows-emulator/CMakeLists.txt @@ -14,9 +14,11 @@ if(NOT MOMO_ENABLE_CLANG_TIDY) target_precompile_headers(windows-emulator PRIVATE std_include.hpp) endif() +if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") target_link_libraries(windows-emulator PRIVATE unicorn-emulator ) +endif() if (MOMO_ENABLE_RUST_CODE) target_link_libraries(windows-emulator PRIVATE diff --git a/src/windows-emulator/windows_emulator.cpp b/src/windows-emulator/windows_emulator.cpp index 4cb8b45f..372d1d19 100644 --- a/src/windows-emulator/windows_emulator.cpp +++ b/src/windows-emulator/windows_emulator.cpp @@ -3,7 +3,9 @@ #include "cpu_context.hpp" +#ifndef OS_EMSCRIPTEN #include +#endif #if MOMO_ENABLE_RUST_CODE #include @@ -263,6 +265,10 @@ namespace std::unique_ptr create_default_x64_emulator() { +#ifdef OS_EMSCRIPTEN + return icicle::create_x64_emulator(); +#else + #if MOMO_ENABLE_RUST_CODE const auto* env = getenv("EMULATOR_ICICLE"); if (env && (env == "1"sv || env == "true"sv)) @@ -270,8 +276,8 @@ std::unique_ptr create_default_x64_emulator() return icicle::create_x64_emulator(); } #endif - return unicorn::create_x64_emulator(); +#endif } windows_emulator::windows_emulator(application_settings app_settings, const emulator_settings& settings,