From 5041bab9f8731b72e3e65789a0d6165c59d64a2f Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 09:44:04 +0200 Subject: [PATCH 01/20] Setup sccache --- .github/workflows/build.yml | 16 ++++++++++++++++ CMakeLists.txt | 3 +++ cmake/sccache.cmake | 15 +++++++++++++++ .../icicle-emulator/icicle-bridge/CMakeLists.txt | 7 ++++++- 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 cmake/sccache.cmake diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 27fe8104..61a10823 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -86,6 +86,14 @@ jobs: - name: Enable Developer Command Prompt uses: ilammy/msvc-dev-cmd@v1.13.0 + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.8 + + - name: Setup Environment Variables + shell: bash + run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + - name: CMake Build run: cmake --preset=release && cmake --build --preset=release -t dump-apiset @@ -255,7 +263,15 @@ jobs: ndk-version: r26d add-to-path: false + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.8 + - name: Setup Environment Variables + shell: bash + run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + + - name: Setup Android Environment Variables shell: bash if: ${{ startsWith(matrix.platform, 'Android') }} run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index ec3e355d..3ddb0b99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,9 @@ endif() # It doesn't support it, even if it thinks it does... set(ENV{ARCHFLAGS} "nope") +########################################## + +include(cmake/sccache.cmake) ########################################## diff --git a/cmake/sccache.cmake b/cmake/sccache.cmake new file mode 100644 index 00000000..4c442585 --- /dev/null +++ b/cmake/sccache.cmake @@ -0,0 +1,15 @@ +include_guard() + +if(CMAKE_GENERATOR STREQUAL "Ninja") + find_program(SCCACHE sccache REQUIRED) + + if (SCCACHE) + set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE}) + set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE}) + set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT Embedded) + + if(POLICY CMP0141) + cmake_policy(SET CMP0141 NEW) + endif() + endif() +endif() diff --git a/src/backends/icicle-emulator/icicle-bridge/CMakeLists.txt b/src/backends/icicle-emulator/icicle-bridge/CMakeLists.txt index d64c0d21..8399c7bc 100644 --- a/src/backends/icicle-emulator/icicle-bridge/CMakeLists.txt +++ b/src/backends/icicle-emulator/icicle-bridge/CMakeLists.txt @@ -35,13 +35,18 @@ endif() set(ICICLE_RUST_LIB ${ICICLE_ARTIFACT_DIR}/${ICICLE_RUST_LIBNAME}) +set(SCCACHE_ENV "MOMO_DUMMY_ENV=1") +if (SCCACHE) + set(SCCACHE_ENV "RUSTC_WRAPPER=${SCCACHE}") +endif() + ExternalProject_Add( icicle-rust-project PREFIX ${CMAKE_CURRENT_BINARY_DIR} SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR} BINARY_DIR ${CMAKE_CURRENT_LIST_DIR} CONFIGURE_COMMAND "" - BUILD_COMMAND ${CMAKE_COMMAND} -E env "CARGO_TARGET_DIR=${ICICLE_BUILD_DIR}" cargo build ${CARGO_OPTIONS} --lib --profile $,dev,release> + BUILD_COMMAND ${CMAKE_COMMAND} -E env "CARGO_TARGET_DIR=${ICICLE_BUILD_DIR}" "${SCCACHE_ENV}" -- cargo build ${CARGO_OPTIONS} --lib --profile $,dev,release> INSTALL_COMMAND "" USES_TERMINAL_CONFIGURE 1 USES_TERMINAL_BUILD 1 From 5022e3049ae3ca73f069ddce9f256c4fe38d4abd Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 09:58:51 +0200 Subject: [PATCH 02/20] Fix sccache --- .github/workflows/build.yml | 8 ++++++++ cmake/compiler-env.cmake | 4 ++-- cmake/sccache.cmake | 15 ++++----------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 61a10823..8836f96e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,6 +52,14 @@ jobs: sudo update-alternatives --set cc /usr/bin/clang-${{ env.LLVM_VERSION }} sudo update-alternatives --set c++ /usr/bin/clang++-${{ env.LLVM_VERSION }} + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.8 + + - name: Setup Environment Variables + shell: bash + run: | + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + - name: CMake Build run: cmake --preset=release -DMOMO_ENABLE_CLANG_TIDY=On && cmake --build --preset=release diff --git a/cmake/compiler-env.cmake b/cmake/compiler-env.cmake index 4d897103..3d48bc0c 100644 --- a/cmake/compiler-env.cmake +++ b/cmake/compiler-env.cmake @@ -203,8 +203,8 @@ set(OPT_DEBUG "-O0 -g") set(OPT_RELEASE "-O3 -g") if(MSVC) - set(OPT_DEBUG "/Od /Ob0 /Zi") - set(OPT_RELEASE "/O2 /Ob2 /Zi") + set(OPT_DEBUG "/Od /Ob0 /Z7") + set(OPT_RELEASE "/O2 /Ob2 /Z7") add_link_options(/DEBUG) endif() diff --git a/cmake/sccache.cmake b/cmake/sccache.cmake index 4c442585..8d5b6db2 100644 --- a/cmake/sccache.cmake +++ b/cmake/sccache.cmake @@ -1,15 +1,8 @@ include_guard() -if(CMAKE_GENERATOR STREQUAL "Ninja") - find_program(SCCACHE sccache REQUIRED) +find_program(SCCACHE sccache) - if (SCCACHE) - set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE}) - set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE}) - set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT Embedded) - - if(POLICY CMP0141) - cmake_policy(SET CMP0141 NEW) - endif() - endif() +if (SCCACHE) + set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE}) + set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE}) endif() From b5f84a3623a87e74b9a0f61e580ec8f94edc5eaf Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 10:13:17 +0200 Subject: [PATCH 03/20] Use RelWithDebInfo --- CMakePresets.json | 2 +- cmake/compiler-env.cmake | 22 ---------------------- cmake/sccache.cmake | 5 +++++ 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index d7a107f3..5e0e6de9 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -23,7 +23,7 @@ "build" ], "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release" + "CMAKE_BUILD_TYPE": "RelWithDebInfo" } }, { diff --git a/cmake/compiler-env.cmake b/cmake/compiler-env.cmake index 3d48bc0c..f8d770e5 100644 --- a/cmake/compiler-env.cmake +++ b/cmake/compiler-env.cmake @@ -145,10 +145,6 @@ if(MSVC) /INCREMENTAL:NO ) - momo_add_c_and_cxx_release_compile_options( - /Ob2 - ) - add_compile_definitions( _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_WARNINGS @@ -199,24 +195,6 @@ endif() ########################################## -set(OPT_DEBUG "-O0 -g") -set(OPT_RELEASE "-O3 -g") - -if(MSVC) - set(OPT_DEBUG "/Od /Ob0 /Z7") - set(OPT_RELEASE "/O2 /Ob2 /Z7") - - add_link_options(/DEBUG) -endif() - -set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${OPT_DEBUG}") -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${OPT_DEBUG}") - -set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${OPT_RELEASE}") -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${OPT_RELEASE}") - -########################################## - if(CMAKE_GENERATOR MATCHES "Visual Studio") momo_add_c_and_cxx_compile_options(/MP) endif() diff --git a/cmake/sccache.cmake b/cmake/sccache.cmake index 8d5b6db2..11179d16 100644 --- a/cmake/sccache.cmake +++ b/cmake/sccache.cmake @@ -5,4 +5,9 @@ find_program(SCCACHE sccache) if (SCCACHE) set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE}) set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE}) + set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT Embedded) + + if(POLICY CMP0141) + cmake_policy(SET CMP0141 NEW) + endif() endif() From a1b690f0cc13d719b0a23c1047897b1a96c2c28b Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 10:23:09 +0200 Subject: [PATCH 04/20] Use newer version --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8836f96e..ea58039b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,7 +53,7 @@ jobs: sudo update-alternatives --set c++ /usr/bin/clang++-${{ env.LLVM_VERSION }} - name: Run sccache-cache - uses: mozilla-actions/sccache-action@v0.0.8 + uses: mozilla-actions/sccache-action@v0.0.9 - name: Setup Environment Variables shell: bash @@ -95,7 +95,7 @@ jobs: uses: ilammy/msvc-dev-cmd@v1.13.0 - name: Run sccache-cache - uses: mozilla-actions/sccache-action@v0.0.8 + uses: mozilla-actions/sccache-action@v0.0.9 - name: Setup Environment Variables shell: bash @@ -272,7 +272,7 @@ jobs: add-to-path: false - name: Run sccache-cache - uses: mozilla-actions/sccache-action@v0.0.8 + uses: mozilla-actions/sccache-action@v0.0.9 - name: Setup Environment Variables shell: bash From 1605d48a185d5f91b5b55efca11777673c8bb165 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 11:33:02 +0200 Subject: [PATCH 05/20] Better sccache --- .github/workflows/build.yml | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ea58039b..9dea71b4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,14 +52,6 @@ jobs: sudo update-alternatives --set cc /usr/bin/clang-${{ env.LLVM_VERSION }} sudo update-alternatives --set c++ /usr/bin/clang++-${{ env.LLVM_VERSION }} - - name: Run sccache-cache - uses: mozilla-actions/sccache-action@v0.0.9 - - - name: Setup Environment Variables - shell: bash - run: | - echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV - - name: CMake Build run: cmake --preset=release -DMOMO_ENABLE_CLANG_TIDY=On && cmake --build --preset=release @@ -94,14 +86,6 @@ jobs: - name: Enable Developer Command Prompt uses: ilammy/msvc-dev-cmd@v1.13.0 - - name: Run sccache-cache - uses: mozilla-actions/sccache-action@v0.0.9 - - - name: Setup Environment Variables - shell: bash - run: | - echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV - - name: CMake Build run: cmake --preset=release && cmake --build --preset=release -t dump-apiset @@ -274,10 +258,22 @@ jobs: - name: Run sccache-cache uses: mozilla-actions/sccache-action@v0.0.9 - - name: Setup Environment Variables + - name: Initialize sccache environnement shell: bash run: | - echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + echo SCCACHE_CACHE=$(sccache --show-stats | grep Local | cut -d '"' -f2) >> $GITHUB_ENV + sccache --stop-server || true + + - name: Recover sccache cache + uses: actions/cache@v3 + with: + path: ${{env.SCCACHE_CACHE}} + key: sccache-cache-${{runner.os}} + + - name: Start sccache + shell: bash + working-directory: ${{github.workspace}} + run: sccache --start-server - name: Setup Android Environment Variables shell: bash @@ -304,6 +300,11 @@ jobs: path: "build/${{matrix.preset}}/**/CTestTestfile.cmake" retention-days: 1 + - name: Cleanup sccache + working-directory: ${{github.workspace}} + shell: bash + run: sccache --stop-server + test: name: Test runs-on: ${{ matrix.runner }} From 900fb582a8a655ebad7db6d7288ff92f9d2cc54e Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 11:43:43 +0200 Subject: [PATCH 06/20] More fixes --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9dea71b4..c747f0de 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -268,7 +268,7 @@ jobs: uses: actions/cache@v3 with: path: ${{env.SCCACHE_CACHE}} - key: sccache-cache-${{runner.os}} + key: sccache-cache-${{runner.os}}-${{matrix.platform}}-${{matrix.configuration}} - name: Start sccache shell: bash @@ -303,7 +303,7 @@ jobs: - name: Cleanup sccache working-directory: ${{github.workspace}} shell: bash - run: sccache --stop-server + run: sccache -s && sccache --stop-server test: name: Test From bdee8b8584c961737c1808e8429b74d183a26785 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 11:59:59 +0200 Subject: [PATCH 07/20] More cache tests --- .github/workflows/build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c747f0de..e594ac1a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -262,13 +262,17 @@ jobs: shell: bash run: | echo SCCACHE_CACHE=$(sccache --show-stats | grep Local | cut -d '"' -f2) >> $GITHUB_ENV + echo SCCACHE_CACHE_SIZE=1G >> $GITHUB_ENV sccache --stop-server || true - name: Recover sccache cache uses: actions/cache@v3 with: path: ${{env.SCCACHE_CACHE}} - key: sccache-cache-${{runner.os}}-${{matrix.platform}}-${{matrix.configuration}} + key: sccache ${{matrix.platform}} ${{matrix.configuration}} ${{ github.head_ref || github.ref_name }} + restore-keys: | + sccache ${{matrix.platform}} ${{matrix.configuration}} ${{ github.event.repository.default_branch }} + sccache-cache-${{runner.os}}-${{matrix.platform}}-${{matrix.configuration}} - name: Start sccache shell: bash From 4b891e701de8d7c38493cac7799094ac8ceb7494 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 12:18:18 +0200 Subject: [PATCH 08/20] Optimize sccache --- .github/workflows/build.yml | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e594ac1a..4f22685f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -255,29 +255,22 @@ jobs: ndk-version: r26d add-to-path: false - - name: Run sccache-cache - uses: mozilla-actions/sccache-action@v0.0.9 - - name: Initialize sccache environnement shell: bash run: | - echo SCCACHE_CACHE=$(sccache --show-stats | grep Local | cut -d '"' -f2) >> $GITHUB_ENV - echo SCCACHE_CACHE_SIZE=1G >> $GITHUB_ENV - sccache --stop-server || true + echo SCCACHE_DIR=${{github.workspace}}/sccache >> $GITHUB_ENV + echo SCCACHE_CACHE_SIZE=500M >> $GITHUB_ENV - name: Recover sccache cache uses: actions/cache@v3 with: - path: ${{env.SCCACHE_CACHE}} + path: ${{env.SCCACHE_DIR}} key: sccache ${{matrix.platform}} ${{matrix.configuration}} ${{ github.head_ref || github.ref_name }} restore-keys: | sccache ${{matrix.platform}} ${{matrix.configuration}} ${{ github.event.repository.default_branch }} - sccache-cache-${{runner.os}}-${{matrix.platform}}-${{matrix.configuration}} - - name: Start sccache - shell: bash - working-directory: ${{github.workspace}} - run: sccache --start-server + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.9 - name: Setup Android Environment Variables shell: bash @@ -304,11 +297,6 @@ jobs: path: "build/${{matrix.preset}}/**/CTestTestfile.cmake" retention-days: 1 - - name: Cleanup sccache - working-directory: ${{github.workspace}} - shell: bash - run: sccache -s && sccache --stop-server - test: name: Test runs-on: ${{ matrix.runner }} From 4392d960e2111f25f259577d357a6d9ec2ae6706 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 12:26:03 +0200 Subject: [PATCH 09/20] Small fixes --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4f22685f..3c9c2914 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -255,13 +255,13 @@ jobs: ndk-version: r26d add-to-path: false - - name: Initialize sccache environnement + - name: Setup sccache environement shell: bash run: | echo SCCACHE_DIR=${{github.workspace}}/sccache >> $GITHUB_ENV echo SCCACHE_CACHE_SIZE=500M >> $GITHUB_ENV - - name: Recover sccache cache + - name: Recover sccache uses: actions/cache@v3 with: path: ${{env.SCCACHE_DIR}} @@ -269,7 +269,7 @@ jobs: restore-keys: | sccache ${{matrix.platform}} ${{matrix.configuration}} ${{ github.event.repository.default_branch }} - - name: Run sccache-cache + - name: Install sccache uses: mozilla-actions/sccache-action@v0.0.9 - name: Setup Android Environment Variables From 6e3a9132e49224eba92ac196e83068b27beccd6d Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 12:43:11 +0200 Subject: [PATCH 10/20] Add cache for api set dumper --- .github/workflows/build.yml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3c9c2914..57e2b96c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -86,6 +86,25 @@ jobs: - name: Enable Developer Command Prompt uses: ilammy/msvc-dev-cmd@v1.13.0 + - name: Setup sccache environement + shell: bash + run: | + echo SCCACHE_DIR=${{github.workspace}}/sccache >> $GITHUB_ENV + echo SCCACHE_CACHE_SIZE=300M >> $GITHUB_ENV + + - name: Recover sccache + uses: actions/cache@v3 + with: + path: ${{env.SCCACHE_DIR}} + key: sccache dumper ${{ github.head_ref || github.ref_name }} + restore-keys: | + sccache dumper ${{ github.event.repository.default_branch }} + + - name: Install sccache + uses: mozilla-actions/sccache-action@v0.0.9 + with: + disable_annotations: true + - name: CMake Build run: cmake --preset=release && cmake --build --preset=release -t dump-apiset @@ -259,7 +278,7 @@ jobs: shell: bash run: | echo SCCACHE_DIR=${{github.workspace}}/sccache >> $GITHUB_ENV - echo SCCACHE_CACHE_SIZE=500M >> $GITHUB_ENV + echo SCCACHE_CACHE_SIZE=300M >> $GITHUB_ENV - name: Recover sccache uses: actions/cache@v3 @@ -271,6 +290,8 @@ jobs: - name: Install sccache uses: mozilla-actions/sccache-action@v0.0.9 + with: + disable_annotations: true - name: Setup Android Environment Variables shell: bash From 15a47c92cd1bb823dc183ff890443ad01f639b18 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 12:57:19 +0200 Subject: [PATCH 11/20] Fix windows caches --- .github/workflows/build.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 57e2b96c..3107b0ea 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -89,8 +89,10 @@ jobs: - name: Setup sccache environement shell: bash run: | - echo SCCACHE_DIR=${{github.workspace}}/sccache >> $GITHUB_ENV - echo SCCACHE_CACHE_SIZE=300M >> $GITHUB_ENV + WORKSPACE_PATH="${{github.workspace}}" + WORKSPACE_PATH="${WORKSPACE_PATH//\\//}" + echo "SCCACHE_DIR=${WORKSPACE_PATH}/sccache" >> $GITHUB_ENV + echo "SCCACHE_CACHE_SIZE=300M" >> $GITHUB_ENV - name: Recover sccache uses: actions/cache@v3 @@ -277,8 +279,10 @@ jobs: - name: Setup sccache environement shell: bash run: | - echo SCCACHE_DIR=${{github.workspace}}/sccache >> $GITHUB_ENV - echo SCCACHE_CACHE_SIZE=300M >> $GITHUB_ENV + WORKSPACE_PATH="${{github.workspace}}" + WORKSPACE_PATH="${WORKSPACE_PATH//\\//}" + echo "SCCACHE_DIR=${WORKSPACE_PATH}/sccache" >> $GITHUB_ENV + echo "SCCACHE_CACHE_SIZE=300M" >> $GITHUB_ENV - name: Recover sccache uses: actions/cache@v3 From 61806bb9c41cb2f2c25b79149ea51381239915a1 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 13:37:48 +0200 Subject: [PATCH 12/20] Remove old caches --- .github/workflows/build.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3107b0ea..397b632e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,6 +21,10 @@ on: - "true" - "false" +permissions: + contents: read + actions: write + concurrency: group: ${{ github.ref }} cancel-in-progress: true @@ -118,6 +122,19 @@ jobs: path: "*" retention-days: 1 + + - name: Remove old cache + uses: actions/github-script@v7.0.1 + continue-on-error: true + with: + script: | + github.rest.actions.deleteActionsCacheByKey({ + owner: context.repo.owner, + repo: context.repo.repo, + key: "sccache dumper ${{ github.head_ref || github.ref_name }}", + }).catch(e => {}) + + create-emulation-root: name: Create Emulation Root runs-on: ${{ matrix.runner }} @@ -322,6 +339,17 @@ jobs: path: "build/${{matrix.preset}}/**/CTestTestfile.cmake" retention-days: 1 + - name: Remove old cache + uses: actions/github-script@v7.0.1 + continue-on-error: true + with: + script: | + github.rest.actions.deleteActionsCacheByKey({ + owner: context.repo.owner, + repo: context.repo.repo, + key: "sccache ${{matrix.platform}} ${{matrix.configuration}} ${{ github.head_ref || github.ref_name }}", + }).catch(e => {}) + test: name: Test runs-on: ${{ matrix.runner }} From 202461c5bdddacfb092fcdc7c38abbb24613f263 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 13:46:59 +0200 Subject: [PATCH 13/20] Update caches --- .github/workflows/build.yml | 50 +++++++++++++++---------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 397b632e..9cbc2a24 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -99,12 +99,13 @@ jobs: echo "SCCACHE_CACHE_SIZE=300M" >> $GITHUB_ENV - name: Recover sccache - uses: actions/cache@v3 + uses: actions/cache/restore@v3 with: path: ${{env.SCCACHE_DIR}} - key: sccache dumper ${{ github.head_ref || github.ref_name }} + key: sccache-dumper-${{ github.head_ref || github.ref_name }}- restore-keys: | - sccache dumper ${{ github.event.repository.default_branch }} + sccache-dumper-${{ github.event.repository.default_branch }}- + sccache dumper ${{ github.head_ref || github.ref_name }}- - name: Install sccache uses: mozilla-actions/sccache-action@v0.0.9 @@ -114,6 +115,12 @@ jobs: - name: CMake Build run: cmake --preset=release && cmake --build --preset=release -t dump-apiset + - name: Save sccache + uses: actions/cache/save@v3 + with: + path: ${{env.SCCACHE_DIR}} + key: sccache-dumper-${{ github.head_ref || github.ref_name }}-${{github.run_id}}-${{github.run_attempt}} + - name: Upload Artifacts uses: pyTooling/upload-artifact@v4 with: @@ -122,19 +129,6 @@ jobs: path: "*" retention-days: 1 - - - name: Remove old cache - uses: actions/github-script@v7.0.1 - continue-on-error: true - with: - script: | - github.rest.actions.deleteActionsCacheByKey({ - owner: context.repo.owner, - repo: context.repo.repo, - key: "sccache dumper ${{ github.head_ref || github.ref_name }}", - }).catch(e => {}) - - create-emulation-root: name: Create Emulation Root runs-on: ${{ matrix.runner }} @@ -302,12 +296,13 @@ jobs: echo "SCCACHE_CACHE_SIZE=300M" >> $GITHUB_ENV - name: Recover sccache - uses: actions/cache@v3 + uses: actions/cache/restore@v3 with: path: ${{env.SCCACHE_DIR}} - key: sccache ${{matrix.platform}} ${{matrix.configuration}} ${{ github.head_ref || github.ref_name }} + key: sccache-${{matrix.platform}}-${{matrix.configuration}}-${{ github.head_ref || github.ref_name }}- restore-keys: | - sccache ${{matrix.platform}} ${{matrix.configuration}} ${{ github.event.repository.default_branch }} + sccache-${{matrix.platform}}-${{matrix.configuration}}-${{ github.event.repository.default_branch }}- + sccache ${{matrix.platform}} ${{matrix.configuration}} ${{ github.head_ref || github.ref_name }}- - name: Install sccache uses: mozilla-actions/sccache-action@v0.0.9 @@ -324,6 +319,12 @@ jobs: - name: CMake Build run: cmake --preset=${{matrix.preset}} ${{matrix.cmake-options}} && cmake --build --preset=${{matrix.preset}} + - name: Save sccache + uses: actions/cache/save@v3 + with: + path: ${{env.SCCACHE_DIR}} + key: sccache ${{matrix.platform}} ${{matrix.configuration}} ${{ github.head_ref || github.ref_name }}-${{github.run_id}}-${{github.run_attempt}} + - name: Upload Artifacts uses: pyTooling/upload-artifact@v4 with: @@ -339,17 +340,6 @@ jobs: path: "build/${{matrix.preset}}/**/CTestTestfile.cmake" retention-days: 1 - - name: Remove old cache - uses: actions/github-script@v7.0.1 - continue-on-error: true - with: - script: | - github.rest.actions.deleteActionsCacheByKey({ - owner: context.repo.owner, - repo: context.repo.repo, - key: "sccache ${{matrix.platform}} ${{matrix.configuration}} ${{ github.head_ref || github.ref_name }}", - }).catch(e => {}) - test: name: Test runs-on: ${{ matrix.runner }} From d7aaf6ac25f0c9f1b3f9ef9e17004d41545c1390 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 13:57:13 +0200 Subject: [PATCH 14/20] Fix sccache path --- .github/workflows/build.yml | 4 +--- cmake/sccache.cmake | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9cbc2a24..4a87f60b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -105,7 +105,6 @@ jobs: key: sccache-dumper-${{ github.head_ref || github.ref_name }}- restore-keys: | sccache-dumper-${{ github.event.repository.default_branch }}- - sccache dumper ${{ github.head_ref || github.ref_name }}- - name: Install sccache uses: mozilla-actions/sccache-action@v0.0.9 @@ -302,7 +301,6 @@ jobs: key: sccache-${{matrix.platform}}-${{matrix.configuration}}-${{ github.head_ref || github.ref_name }}- restore-keys: | sccache-${{matrix.platform}}-${{matrix.configuration}}-${{ github.event.repository.default_branch }}- - sccache ${{matrix.platform}} ${{matrix.configuration}} ${{ github.head_ref || github.ref_name }}- - name: Install sccache uses: mozilla-actions/sccache-action@v0.0.9 @@ -323,7 +321,7 @@ jobs: uses: actions/cache/save@v3 with: path: ${{env.SCCACHE_DIR}} - key: sccache ${{matrix.platform}} ${{matrix.configuration}} ${{ github.head_ref || github.ref_name }}-${{github.run_id}}-${{github.run_attempt}} + key: sccache-${{matrix.platform}}-${{matrix.configuration}}-${{ github.head_ref || github.ref_name }}-${{github.run_id}}-${{github.run_attempt}} - name: Upload Artifacts uses: pyTooling/upload-artifact@v4 diff --git a/cmake/sccache.cmake b/cmake/sccache.cmake index 11179d16..732330d5 100644 --- a/cmake/sccache.cmake +++ b/cmake/sccache.cmake @@ -3,6 +3,7 @@ include_guard() find_program(SCCACHE sccache) if (SCCACHE) + file(TO_CMAKE_PATH "${SCCACHE}" SCCACHE) set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE}) set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE}) set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT Embedded) From 9cdbb549979efc15c056490c40b4c5ec896d695b Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 14:03:17 +0200 Subject: [PATCH 15/20] Cache fixes --- .github/workflows/build.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4a87f60b..7bfaed99 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -102,9 +102,9 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{env.SCCACHE_DIR}} - key: sccache-dumper-${{ github.head_ref || github.ref_name }}- + key: sccache-${{github.job}}-${{ github.head_ref || github.ref_name }}- restore-keys: | - sccache-dumper-${{ github.event.repository.default_branch }}- + sccache-${{github.job}}-${{ github.event.repository.default_branch }}- - name: Install sccache uses: mozilla-actions/sccache-action@v0.0.9 @@ -118,7 +118,7 @@ jobs: uses: actions/cache/save@v3 with: path: ${{env.SCCACHE_DIR}} - key: sccache-dumper-${{ github.head_ref || github.ref_name }}-${{github.run_id}}-${{github.run_attempt}} + key: sccache-${{github.job}}-${{ github.head_ref || github.ref_name }}-${{github.run_id}}-${{github.run_attempt}} - name: Upload Artifacts uses: pyTooling/upload-artifact@v4 @@ -298,9 +298,9 @@ jobs: uses: actions/cache/restore@v3 with: path: ${{env.SCCACHE_DIR}} - key: sccache-${{matrix.platform}}-${{matrix.configuration}}-${{ github.head_ref || github.ref_name }}- + key: sccache-${{github.job}}-${{matrix.platform}}-${{matrix.configuration}}-${{ github.head_ref || github.ref_name }}- restore-keys: | - sccache-${{matrix.platform}}-${{matrix.configuration}}-${{ github.event.repository.default_branch }}- + sccache-${{github.job}}-${{matrix.platform}}-${{matrix.configuration}}-${{ github.event.repository.default_branch }}- - name: Install sccache uses: mozilla-actions/sccache-action@v0.0.9 @@ -321,7 +321,7 @@ jobs: uses: actions/cache/save@v3 with: path: ${{env.SCCACHE_DIR}} - key: sccache-${{matrix.platform}}-${{matrix.configuration}}-${{ github.head_ref || github.ref_name }}-${{github.run_id}}-${{github.run_attempt}} + key: sccache-${{github.job}}-${{matrix.platform}}-${{matrix.configuration}}-${{ github.head_ref || github.ref_name }}-${{github.run_id}}-${{github.run_attempt}} - name: Upload Artifacts uses: pyTooling/upload-artifact@v4 From d509ae849978e9309c960f010383e0934a3184c6 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 14:05:30 +0200 Subject: [PATCH 16/20] Fixes --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7bfaed99..8209a58d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -90,7 +90,7 @@ jobs: - name: Enable Developer Command Prompt uses: ilammy/msvc-dev-cmd@v1.13.0 - - name: Setup sccache environement + - name: Setup sccache environment shell: bash run: | WORKSPACE_PATH="${{github.workspace}}" @@ -286,7 +286,7 @@ jobs: ndk-version: r26d add-to-path: false - - name: Setup sccache environement + - name: Setup sccache environment shell: bash run: | WORKSPACE_PATH="${{github.workspace}}" From bee2f0989439c83601db9d3ccf3a40a9ac652bf7 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 14:14:46 +0200 Subject: [PATCH 17/20] More sccache optimizations --- .github/workflows/build.yml | 39 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8209a58d..5eb98ca5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -90,22 +90,6 @@ jobs: - name: Enable Developer Command Prompt uses: ilammy/msvc-dev-cmd@v1.13.0 - - name: Setup sccache environment - shell: bash - run: | - WORKSPACE_PATH="${{github.workspace}}" - WORKSPACE_PATH="${WORKSPACE_PATH//\\//}" - echo "SCCACHE_DIR=${WORKSPACE_PATH}/sccache" >> $GITHUB_ENV - echo "SCCACHE_CACHE_SIZE=300M" >> $GITHUB_ENV - - - name: Recover sccache - uses: actions/cache/restore@v3 - with: - path: ${{env.SCCACHE_DIR}} - key: sccache-${{github.job}}-${{ github.head_ref || github.ref_name }}- - restore-keys: | - sccache-${{github.job}}-${{ github.event.repository.default_branch }}- - - name: Install sccache uses: mozilla-actions/sccache-action@v0.0.9 with: @@ -114,12 +98,6 @@ jobs: - name: CMake Build run: cmake --preset=release && cmake --build --preset=release -t dump-apiset - - name: Save sccache - uses: actions/cache/save@v3 - with: - path: ${{env.SCCACHE_DIR}} - key: sccache-${{github.job}}-${{ github.head_ref || github.ref_name }}-${{github.run_id}}-${{github.run_attempt}} - - name: Upload Artifacts uses: pyTooling/upload-artifact@v4 with: @@ -292,7 +270,7 @@ jobs: WORKSPACE_PATH="${{github.workspace}}" WORKSPACE_PATH="${WORKSPACE_PATH//\\//}" echo "SCCACHE_DIR=${WORKSPACE_PATH}/sccache" >> $GITHUB_ENV - echo "SCCACHE_CACHE_SIZE=300M" >> $GITHUB_ENV + echo "SCCACHE_CACHE_SIZE=200M" >> $GITHUB_ENV - name: Recover sccache uses: actions/cache/restore@v3 @@ -317,12 +295,6 @@ jobs: - name: CMake Build run: cmake --preset=${{matrix.preset}} ${{matrix.cmake-options}} && cmake --build --preset=${{matrix.preset}} - - name: Save sccache - uses: actions/cache/save@v3 - with: - path: ${{env.SCCACHE_DIR}} - key: sccache-${{github.job}}-${{matrix.platform}}-${{matrix.configuration}}-${{ github.head_ref || github.ref_name }}-${{github.run_id}}-${{github.run_attempt}} - - name: Upload Artifacts uses: pyTooling/upload-artifact@v4 with: @@ -338,6 +310,15 @@ jobs: path: "build/${{matrix.preset}}/**/CTestTestfile.cmake" retention-days: 1 + - name: Print sccache stats + run: sccache -s && sccache --stop-server + + - name: Save sccache + uses: actions/cache/save@v3 + with: + path: ${{env.SCCACHE_DIR}} + key: sccache-${{github.job}}-${{matrix.platform}}-${{matrix.configuration}}-${{ github.head_ref || github.ref_name }}-${{github.run_id}}-${{github.run_attempt}} + test: name: Test runs-on: ${{ matrix.runner }} From 1724bdd95951c7717e0427509237d29d23de971b Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 16:08:22 +0200 Subject: [PATCH 18/20] Use shallow cloning for all submodules --- .gitmodules | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitmodules b/.gitmodules index 39d3ee49..1af1ba95 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,17 +10,22 @@ [submodule "deps/googletest"] path = deps/googletest url = https://github.com/google/googletest.git + shallow = true [submodule "deps/zlib"] path = deps/zlib url = https://github.com/madler/zlib.git branch = develop ignore = dirty + shallow = true [submodule "deps/gtest-parallel"] path = deps/gtest-parallel url = https://github.com/google/gtest-parallel.git + shallow = true [submodule "deps/flatbuffers"] path = deps/flatbuffers url = https://github.com/google/flatbuffers.git + shallow = true [submodule "deps/base64"] path = deps/base64 url = https://github.com/tobiaslocker/base64.git + shallow = true From e760b1e3dd5de71a425ff099325fd9d20577ee92 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 17:04:20 +0200 Subject: [PATCH 19/20] Use full url for unicorn submodule to fix forks --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 1af1ba95..385ca7f2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "deps/unicorn"] path = deps/unicorn - url = ../unicorn.git + url = https://github.com/momo5502/unicorn.git shallow = true branch = wasm [submodule "deps/reflect"] From 28de07ac8f9b99d0be18ca861807cf9c02dfbfcd Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 29 May 2025 19:49:53 +0200 Subject: [PATCH 20/20] Explicitly pass desired backend to emulator --- src/CMakeLists.txt | 1 + src/analyzer/CMakeLists.txt | 1 + src/analyzer/main.cpp | 5 +-- src/backend-selection/CMakeLists.txt | 23 ++++++++++++++ src/backend-selection/backend_selection.cpp | 23 ++++++++++++++ src/backend-selection/backend_selection.hpp | 6 ++++ src/fuzzer/CMakeLists.txt | 6 ++++ src/fuzzer/main.cpp | 19 ++++++++++-- src/windows-emulator-test/CMakeLists.txt | 1 + .../emulation_test_utils.hpp | 3 ++ src/windows-emulator/CMakeLists.txt | 10 ------ src/windows-emulator/windows_emulator.cpp | 31 ++++--------------- src/windows-emulator/windows_emulator.hpp | 13 +++----- 13 files changed, 94 insertions(+), 48 deletions(-) create mode 100644 src/backend-selection/CMakeLists.txt create mode 100644 src/backend-selection/backend_selection.cpp create mode 100644 src/backend-selection/backend_selection.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 870f20e1..300b763d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,7 @@ add_subdirectory(emulator) add_subdirectory(gdb-stub) add_subdirectory(windows-emulator) add_subdirectory(windows-gdb-stub) +add_subdirectory(backend-selection) momo_add_subdirectory_and_get_targets("backends" BACKEND_TARGETS) momo_targets_set_folder("backends" ${BACKEND_TARGETS}) diff --git a/src/analyzer/CMakeLists.txt b/src/analyzer/CMakeLists.txt index 036e614e..a0ed8607 100644 --- a/src/analyzer/CMakeLists.txt +++ b/src/analyzer/CMakeLists.txt @@ -19,6 +19,7 @@ target_link_libraries(analyzer PRIVATE debugger windows-emulator windows-gdb-stub + backend-selection ) set_property(GLOBAL PROPERTY VS_STARTUP_PROJECT analyzer) diff --git a/src/analyzer/main.cpp b/src/analyzer/main.cpp index 363fb450..a9690f93 100644 --- a/src/analyzer/main.cpp +++ b/src/analyzer/main.cpp @@ -1,6 +1,7 @@ #include "std_include.hpp" #include +#include #include #include "object_watching.hpp" @@ -217,7 +218,7 @@ namespace std::unique_ptr create_empty_emulator(const analysis_options& options) { const auto settings = create_emulator_settings(options); - return std::make_unique(settings); + return std::make_unique(create_x86_64_emulator(), settings); } std::unique_ptr create_application_emulator(const analysis_options& options, @@ -234,7 +235,7 @@ namespace }; const auto settings = create_emulator_settings(options); - return std::make_unique(std::move(app_settings), settings); + return std::make_unique(create_x86_64_emulator(), std::move(app_settings), settings); } std::unique_ptr setup_emulator(const analysis_options& options, diff --git a/src/backend-selection/CMakeLists.txt b/src/backend-selection/CMakeLists.txt new file mode 100644 index 00000000..3a2956d2 --- /dev/null +++ b/src/backend-selection/CMakeLists.txt @@ -0,0 +1,23 @@ +file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS + *.cpp + *.hpp + *.rc +) + +list(SORT SRC_FILES) + +add_library(backend-selection ${SRC_FILES}) + +momo_assign_source_group(${SRC_FILES}) + +target_include_directories(backend-selection INTERFACE "${CMAKE_CURRENT_LIST_DIR}") + +target_link_libraries(backend-selection PRIVATE + unicorn-emulator +) + +if (MOMO_ENABLE_RUST_CODE) + target_link_libraries(backend-selection PRIVATE + icicle-emulator + ) +endif() \ No newline at end of file diff --git a/src/backend-selection/backend_selection.cpp b/src/backend-selection/backend_selection.cpp new file mode 100644 index 00000000..77b252d7 --- /dev/null +++ b/src/backend-selection/backend_selection.cpp @@ -0,0 +1,23 @@ +#include "backend_selection.hpp" + +#include +#include + +#if MOMO_ENABLE_RUST_CODE +#include +#endif + +using namespace std::literals; + +std::unique_ptr create_x86_64_emulator() +{ +#if MOMO_ENABLE_RUST_CODE + const auto* env = getenv("EMULATOR_ICICLE"); + if (env && (env == "1"sv || env == "true"sv)) + { + return icicle::create_x86_64_emulator(); + } +#endif + + return unicorn::create_x86_64_emulator(); +} diff --git a/src/backend-selection/backend_selection.hpp b/src/backend-selection/backend_selection.hpp new file mode 100644 index 00000000..607e54a9 --- /dev/null +++ b/src/backend-selection/backend_selection.hpp @@ -0,0 +1,6 @@ +#pragma once + +#include +#include + +std::unique_ptr create_x86_64_emulator(); diff --git a/src/fuzzer/CMakeLists.txt b/src/fuzzer/CMakeLists.txt index 2ffc31a0..6fb50eff 100644 --- a/src/fuzzer/CMakeLists.txt +++ b/src/fuzzer/CMakeLists.txt @@ -19,4 +19,10 @@ target_link_libraries(fuzzer PRIVATE windows-emulator ) +if (MOMO_ENABLE_RUST_CODE) + target_link_libraries(fuzzer PRIVATE + icicle-emulator + ) +endif() + momo_strip_target(fuzzer) diff --git a/src/fuzzer/main.cpp b/src/fuzzer/main.cpp index 5f9c047a..2bb4cb5c 100644 --- a/src/fuzzer/main.cpp +++ b/src/fuzzer/main.cpp @@ -3,7 +3,11 @@ #include #include -#include "utils/finally.hpp" +#include + +#if MOMO_ENABLE_RUST_CODE +#include +#endif #ifdef _MSC_VER #pragma warning(disable : 4702) @@ -13,6 +17,15 @@ bool use_gdb = false; namespace { + std::unique_ptr create_emulator_backend() + { +#if MOMO_ENABLE_RUST_CODE + return icicle::create_x86_64_emulator(); +#else + throw std::runtime_error("Fuzzer requires rust code to be enabled"); +#endif + } + void run_emulation(windows_emulator& win_emu) { try @@ -47,7 +60,7 @@ namespace struct fuzzer_executer : fuzzer::executer { - windows_emulator emu{}; // TODO: Fix root directory + windows_emulator emu{create_emulator_backend()}; std::span emulator_data{}; std::unordered_set visited_blocks{}; const std::function* handler{nullptr}; @@ -148,7 +161,7 @@ namespace .application = application, }; - windows_emulator win_emu{std::move(settings)}; + windows_emulator win_emu{create_emulator_backend(), std::move(settings)}; forward_emulator(win_emu); run_fuzzer(win_emu); diff --git a/src/windows-emulator-test/CMakeLists.txt b/src/windows-emulator-test/CMakeLists.txt index 8bea4b26..e00f862f 100644 --- a/src/windows-emulator-test/CMakeLists.txt +++ b/src/windows-emulator-test/CMakeLists.txt @@ -14,6 +14,7 @@ target_link_libraries(windows-emulator-test PRIVATE gtest gtest_main windows-emulator + backend-selection ) if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 8) diff --git a/src/windows-emulator-test/emulation_test_utils.hpp b/src/windows-emulator-test/emulation_test_utils.hpp index d972de71..8aa201ab 100644 --- a/src/windows-emulator-test/emulation_test_utils.hpp +++ b/src/windows-emulator-test/emulation_test_utils.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -72,6 +73,7 @@ namespace test std::filesystem::temp_directory_path() / ("emulator-test-file-" + std::to_string(getpid()) + ".txt"); return windows_emulator{ + create_x86_64_emulator(), settings, std::move(callbacks), emulator_interfaces{ @@ -97,6 +99,7 @@ namespace test std::filesystem::temp_directory_path() / ("emulator-test-file-" + std::to_string(getpid()) + ".txt"); return windows_emulator{ + create_x86_64_emulator(), get_sample_app_settings(config), settings, std::move(callbacks), diff --git a/src/windows-emulator/CMakeLists.txt b/src/windows-emulator/CMakeLists.txt index 16167e84..93a25074 100644 --- a/src/windows-emulator/CMakeLists.txt +++ b/src/windows-emulator/CMakeLists.txt @@ -14,16 +14,6 @@ if(NOT MOMO_ENABLE_CLANG_TIDY) target_precompile_headers(windows-emulator PRIVATE std_include.hpp) endif() -target_link_libraries(windows-emulator PRIVATE - unicorn-emulator -) - -if (MOMO_ENABLE_RUST_CODE) -target_link_libraries(windows-emulator PRIVATE - icicle-emulator -) -endif() - target_link_libraries(windows-emulator PUBLIC emulator) target_include_directories(windows-emulator INTERFACE "${CMAKE_CURRENT_LIST_DIR}") diff --git a/src/windows-emulator/windows_emulator.cpp b/src/windows-emulator/windows_emulator.cpp index 76e6cc79..1b518afd 100644 --- a/src/windows-emulator/windows_emulator.cpp +++ b/src/windows-emulator/windows_emulator.cpp @@ -3,12 +3,6 @@ #include "cpu_context.hpp" -#include - -#if MOMO_ENABLE_RUST_CODE -#include -#endif - #include #include #include @@ -268,30 +262,17 @@ namespace } } -std::unique_ptr create_default_x86_64_emulator() -{ -#if MOMO_ENABLE_RUST_CODE - const auto* env = getenv("EMULATOR_ICICLE"); - if (env && (env == "1"sv || env == "true"sv)) - { - return icicle::create_x86_64_emulator(); - } -#endif - - return unicorn::create_x86_64_emulator(); -} - -windows_emulator::windows_emulator(application_settings app_settings, const emulator_settings& settings, - emulator_callbacks callbacks, emulator_interfaces interfaces, - std::unique_ptr emu) - : windows_emulator(settings, std::move(callbacks), std::move(interfaces), std::move(emu)) +windows_emulator::windows_emulator(std::unique_ptr emu, application_settings app_settings, + const emulator_settings& settings, emulator_callbacks callbacks, + emulator_interfaces interfaces) + : windows_emulator(std::move(emu), settings, std::move(callbacks), std::move(interfaces)) { fixup_application_settings(app_settings); this->setup_process(app_settings); } -windows_emulator::windows_emulator(const emulator_settings& settings, emulator_callbacks callbacks, - emulator_interfaces interfaces, std::unique_ptr emu) +windows_emulator::windows_emulator(std::unique_ptr emu, const emulator_settings& settings, + emulator_callbacks callbacks, emulator_interfaces interfaces) : emu_(std::move(emu)), clock_(get_clock(interfaces, this->executed_instructions_, settings.use_relative_time)), socket_factory_(get_socket_factory(interfaces)), diff --git a/src/windows-emulator/windows_emulator.hpp b/src/windows-emulator/windows_emulator.hpp index 520e1c80..ac0f20c6 100644 --- a/src/windows-emulator/windows_emulator.hpp +++ b/src/windows-emulator/windows_emulator.hpp @@ -13,8 +13,6 @@ #include "module/module_manager.hpp" #include "network/socket_factory.hpp" -std::unique_ptr create_default_x86_64_emulator(); - struct emulator_callbacks : module_manager::callbacks, process_context::callbacks { utils::optional_function emu = create_default_x86_64_emulator()); - windows_emulator(application_settings app_settings, const emulator_settings& settings = {}, - emulator_callbacks callbacks = {}, emulator_interfaces interfaces = {}, - std::unique_ptr emu = create_default_x86_64_emulator()); + windows_emulator(std::unique_ptr emu, const emulator_settings& settings = {}, + emulator_callbacks callbacks = {}, emulator_interfaces interfaces = {}); + windows_emulator(std::unique_ptr emu, application_settings app_settings, + const emulator_settings& settings = {}, emulator_callbacks callbacks = {}, + emulator_interfaces interfaces = {}); windows_emulator(windows_emulator&&) = delete; windows_emulator(const windows_emulator&) = delete;