diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5eb98ca5..f144feca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -166,6 +166,7 @@ jobs: platform: - Windows x86 - Windows x86_64 + - MinGW x86_64 - Linux x86_64 GCC - Linux x86_64 GCC Sanitizer - Linux x86_64 Clang @@ -190,6 +191,10 @@ jobs: - platform: Windows x86_64 runner: windows-latest devcmd_arch: x64 + - platform: MinGW x86_64 + runner: ubuntu-24.04 + rust-target: x86_64-pc-windows-gnu + cmake-options: "-DCMAKE_TOOLCHAIN_FILE=$GITHUB_WORKSPACE/cmake/toolchain/mingw-w64.cmake" - platform: Linux x86_64 GCC Sanitizer runner: ubuntu-24.04 cmake-options: "-DMOMO_ENABLE_SANITIZER=On" @@ -251,6 +256,12 @@ jobs: sudo update-alternatives --set cc /usr/bin/clang-${{ matrix.clang-version }} sudo update-alternatives --set c++ /usr/bin/clang++-${{ matrix.clang-version }} + - name: Set up MinGW + uses: egor-tensin/setup-mingw@v2 + if: "${{ startsWith(matrix.platform, 'MinGW') }}" + with: + platform: x64 + - name: Enable Developer Command Prompt uses: ilammy/msvc-dev-cmd@v1.13.0 if: ${{ startsWith(matrix.platform, 'Windows') }} @@ -329,6 +340,7 @@ jobs: platform: - Windows x86 - Windows x86_64 + - MinGW x86_64 - Linux x86_64 GCC - Linux x86_64 GCC Sanitizer - Linux x86_64 Clang @@ -353,6 +365,8 @@ jobs: runner: windows-latest - platform: Windows x86_64 runner: windows-latest + - platform: MinGW x86_64 + runner: windows-latest - platform: Linux x86_64 GCC runner: ubuntu-24.04 - platform: Linux x86_64 GCC Sanitizer @@ -390,7 +404,7 @@ jobs: - name: Download Windows Artifacts uses: pyTooling/download-artifact@v4 - if: "${{ matrix.platform != 'Windows x86_64' }}" + if: "${{ matrix.platform != 'Windows x86_64' && matrix.platform != 'MinGW x86_64' }}" with: name: Windows x86_64 Release Artifacts path: build/${{matrix.preset}}/artifacts @@ -405,7 +419,7 @@ jobs: run: cp build/${{matrix.preset}}/artifacts/test-sample.exe build/${{matrix.preset}}/artifacts/root/filesys/c/ - name: CMake Test - if: ${{ matrix.emulator != 'Icicle' || matrix.platform != 'Windows x86' }} + if: ${{ matrix.emulator != 'Icicle' || (matrix.platform != 'Windows x86' && matrix.platform != 'MinGW x86_64') }} run: cd build/${{matrix.preset}} && ctest --verbose -j env: EMULATOR_ROOT: ${{github.workspace}}/build/${{matrix.preset}}/artifacts/root diff --git a/cmake/compiler-env.cmake b/cmake/compiler-env.cmake index 1075875e..1918272d 100644 --- a/cmake/compiler-env.cmake +++ b/cmake/compiler-env.cmake @@ -25,21 +25,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) ########################################## -if(MINGW) - # Minimum version check for MinGW compiler - set(MINGW_C_COMPILER_MIN_VERSION "14.0.0") - set(MINGW_CXX_COMPILER_MIN_VERSION "14.0.0") - - if (${CMAKE_C_COMPILER_VERSION} VERSION_LESS_EQUAL ${MINGW_C_COMPILER_MIN_VERSION}) - message(FATAL_ERROR "${CMAKE_C_COMPILER} version should >= ${MINGW_C_COMPILER_MIN_VERSION}") - endif() - if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS_EQUAL ${MINGW_CXX_COMPILER_MIN_VERSION}) - message(FATAL_ERROR "${CMAKE_C_COMPILER} version should >= ${MINGW_CXX_COMPILER_MIN_VERSION}") - endif() - - # MinGW LTO will cause errors in compile stage, We just disable it - set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF) -elseif(NOT CMAKE_SYSTEM_NAME MATCHES "Emscripten") +if(NOT MINGW AND NOT CMAKE_SYSTEM_NAME MATCHES "Emscripten") set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) endif() @@ -53,7 +39,14 @@ endif() ########################################## -if(MOMO_ENABLE_RUST_CODE) +set(MOMO_ENABLE_RUST OFF) +if(MOMO_ENABLE_RUST_CODE AND NOT MINGW AND NOT CMAKE_SYSTEM_NAME MATCHES "Emscripten") + set(MOMO_ENABLE_RUST ON) +endif() + +########################################## + +if(MOMO_ENABLE_RUST) add_compile_definitions(MOMO_ENABLE_RUST_CODE=1) else() add_compile_definitions(MOMO_ENABLE_RUST_CODE=0) diff --git a/src/backend-selection/CMakeLists.txt b/src/backend-selection/CMakeLists.txt index 3a2956d2..a0523c6d 100644 --- a/src/backend-selection/CMakeLists.txt +++ b/src/backend-selection/CMakeLists.txt @@ -16,7 +16,7 @@ target_link_libraries(backend-selection PRIVATE unicorn-emulator ) -if (MOMO_ENABLE_RUST_CODE) +if (MOMO_ENABLE_RUST) target_link_libraries(backend-selection PRIVATE icicle-emulator ) diff --git a/src/backends/CMakeLists.txt b/src/backends/CMakeLists.txt index 12d192df..9c590e1c 100644 --- a/src/backends/CMakeLists.txt +++ b/src/backends/CMakeLists.txt @@ -1,5 +1,5 @@ add_subdirectory(unicorn-emulator) -if (MOMO_ENABLE_RUST_CODE) +if (MOMO_ENABLE_RUST) add_subdirectory(icicle-emulator) endif() diff --git a/src/backends/icicle-emulator/icicle-bridge/CMakeLists.txt b/src/backends/icicle-emulator/icicle-bridge/CMakeLists.txt index 8399c7bc..8ce651a3 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 (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") +if (MINGW) + set(CARGO_TRIPLE "x86_64-pc-windows-gnu") +elseif (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") diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 036793eb..9423e8f1 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -17,7 +17,7 @@ target_link_libraries(emulator-common PUBLIC zlibstatic ) -if(MINGW) +if(WIN) target_link_libraries(emulator-common PUBLIC ws2_32 ) diff --git a/src/common/network/address.hpp b/src/common/network/address.hpp index 6b332699..86415a76 100644 --- a/src/common/network/address.hpp +++ b/src/common/network/address.hpp @@ -34,7 +34,6 @@ #ifdef _WIN32 using socklen_t = int; -#pragma comment(lib, "ws2_32.lib") #endif namespace network diff --git a/src/fuzzer/CMakeLists.txt b/src/fuzzer/CMakeLists.txt index 6fb50eff..0eecd77c 100644 --- a/src/fuzzer/CMakeLists.txt +++ b/src/fuzzer/CMakeLists.txt @@ -19,7 +19,7 @@ target_link_libraries(fuzzer PRIVATE windows-emulator ) -if (MOMO_ENABLE_RUST_CODE) +if (MOMO_ENABLE_RUST) target_link_libraries(fuzzer PRIVATE icicle-emulator )