From 9954763c022e4ec76dbf5391b007630a7db82199 Mon Sep 17 00:00:00 2001 From: mio Date: Wed, 6 Oct 2021 23:22:02 +0200 Subject: [PATCH 1/2] Add MSVC 32bit and Android x86_64 CI. --- .github/workflows/PyPI-publishing.yml | 15 ++- .github/workflows/build-uc2.yml | 144 ++++++++++++++++++-------- 2 files changed, 117 insertions(+), 42 deletions(-) diff --git a/.github/workflows/PyPI-publishing.yml b/.github/workflows/PyPI-publishing.yml index 2a3fd208..76751f2b 100644 --- a/.github/workflows/PyPI-publishing.yml +++ b/.github/workflows/PyPI-publishing.yml @@ -1,6 +1,19 @@ name: PyPI 📦 Distribution -on: [push] +on: + push: + paths-ignore: + - ".github/**" + - ".gitignore" + - "docs/**" + - "README" + - "CREDITS.TXT" + - "COPYING_GLIB" + - "COPYING.LGPL2" + - "AUTHORS.TXT" + - "CHANGELOG" + - "COPYING" + pull_request: jobs: build: diff --git a/.github/workflows/build-uc2.yml b/.github/workflows/build-uc2.yml index 46a6de51..8cff3884 100644 --- a/.github/workflows/build-uc2.yml +++ b/.github/workflows/build-uc2.yml @@ -1,19 +1,5 @@ name: Build UC2 -on: - push: - tags-ignore: - - "*" - paths-ignore: - - ".github/**" - - ".gitignore" - - "docs/**" - - "README" - - "CREDITS.TXT" - - "COPYING_GLIB" - - "COPYING.LGPL2" - - "AUTHORS.TXT" - - "CHANGELOG" - - "COPYING" +on: [push, pull_request] env: CI: true @@ -21,7 +7,7 @@ env: jobs: Windows: runs-on: ${{ matrix.config.os }} - name: ${{ matrix.config.name }} - ${{ matrix.compiler }} + name: ${{ matrix.config.name }} strategy: fail-fast: false matrix: @@ -64,15 +50,22 @@ jobs: archiver: '7z a', generators: 'Visual Studio 16 2019' } + - { + os: windows-latest, + arch: x86, + python-arch: x86, + python-ver: '3.8', + name: 'windows-x86 MSVC 32bit', + msvc-arch: x86, + artifact: 'windows_msvc32.7z', + build_type: 'Debug', + archiver: '7z a', + generators: 'Visual Studio 16 2019' + } compiler: [ gcc ] steps: - uses: actions/checkout@v2 - # - name: '🛠️ Python setup' - # uses: actions/setup-python@v2 - # with: - # python-version: ${{ matrix.config.python-ver }} - - name: '🛠️ Win MINGW setup' if: contains(matrix.config.mingw, 'MINGW') uses: msys2/setup-msys2@v2 @@ -86,12 +79,12 @@ jobs: mingw-w64-${{ matrix.config.mingw-arch }}-${{ matrix.compiler }} mingw-w64-${{ matrix.config.mingw-arch }}-toolchain - - name: '🛠️ Win MSVC setup' - if: contains(matrix.config.name, 'MSVC') + - name: '🛠️ Win MSVC 64 setup' + if: contains(matrix.config.name, 'MSVC 64') uses: microsoft/setup-msbuild@v1 - - name: '🚧 Win MSVC build' - if: contains(matrix.config.name, 'MSVC') + - name: '🚧 Win MSVC 64 build' + if: contains(matrix.config.name, 'MSVC 64') shell: bash run: | choco install ninja cmake @@ -109,6 +102,32 @@ jobs: ctest -C ${{ matrix.config.build_type }} mv Debug instdir + - name: '🛠️ Win MSVC 32 setup' + if: contains(matrix.config.name, 'MSVC 32') + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x86 + + - name: '🚧 Win MSVC 32 build' + if: contains(matrix.config.name, 'MSVC 32') + shell: bash + run: | + choco install ninja cmake + ninja --version + cmake --version + mkdir build + cmake \ + -S . \ + -B . \ + -A "win32" \ + -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \ + -G "${{ matrix.config.generators }}" \ + -DCMAKE_INSTALL_PREFIX:PATH=instdir + cmake --build . --config ${{ matrix.config.build_type }} + cmake --install . --strip --config ${{ matrix.config.build_type }} + ctest -C ${{ matrix.config.build_type }} + mv Debug instdir + - name: '🚧 Win MINGW build' if: contains(matrix.config.mingw, 'MINGW') shell: msys2 {0} @@ -166,6 +185,17 @@ jobs: archiver: '7za a', generators: 'Ninja' } + - { + os: macos-11, + arch: x86_64, + python-arch: x86_64, + python-ver: '3.8', + name: 'android cmake', + artifact: 'Android-x86_64.7z', + build_type: 'Debug', + archiver: '7za a', + generators: 'Ninja' + } compiler: [ gcc ] steps: - uses: actions/checkout@v2 @@ -176,24 +206,56 @@ jobs: # python-version: ${{ matrix.config.python-ver }} - name: '🚧 Mac build' - if: contains(matrix.config.os, 'macos') + if: contains(matrix.config.name, 'macos-x64') shell: bash run: | - brew install p7zip cmake ninja - ninja --version - cmake --version - mkdir build - mkdir instdir - cmake \ - -S . \ - -B . \ - -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \ - -G "${{ matrix.config.generators }}" \ - -DCMAKE_INSTALL_PREFIX:PATH=instdir - cmake --build . --config ${{ matrix.config.build_type }} - cmake --install . --strip - ctest -C ${{ matrix.config.build_type }} + brew install p7zip cmake ninja + ninja --version + cmake --version + mkdir build + mkdir instdir + cmake \ + -S . \ + -B . \ + -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \ + -G "${{ matrix.config.generators }}" \ + -DCMAKE_INSTALL_PREFIX:PATH=instdir + cmake --build . --config ${{ matrix.config.build_type }} + cmake --install . --strip + ctest -C ${{ matrix.config.build_type }} + - name: '🚧 Android x86_64 build' + if: contains(matrix.config.name, 'android') + shell: bash + run: | + brew install p7zip cmake ninja + mkdir build + mkdir instdir + cmake . -DCMAKE_TOOLCHAIN_FILE="$ANDROID_HOME/ndk/21.4.7075529/build/cmake/android.toolchain.cmake" \ + -DANDROID_PLATFORM=android-28 \ + -DANDROID_NDK="$ANDROID_HOME/ndk/21.4.7075529" \ + -DANDROID_ABI=${{ matrix.config.arch }} \ + -DOLP_SDK_ENABLE_TESTING=NO \ + -DOLP_SDK_BUILD_EXAMPLES=ON \ + -S . \ + -B . \ + -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \ + -G "${{ matrix.config.generators }}" \ + -DCMAKE_INSTALL_PREFIX:PATH=instdir + cmake --build . --config ${{ matrix.config.build_type }} + cmake --install . --strip + + - name: '🚧 Android x86_64 tests' + if: contains(matrix.config.name, 'android') + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: 28 + arch: ${{ matrix.config.arch }} + target: default + profile: Nexus 6 + emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -verbose -show-kernel + script: ctest -C ${{ matrix.config.build_type }} + - name: '📦 Pack artifact' shell: bash working-directory: instdir @@ -330,4 +392,4 @@ jobs: uses: actions/upload-artifact@v1 with: path: ./${{ matrix.config.artifact }} - name: ${{ matrix.config.artifact }} \ No newline at end of file + name: ${{ matrix.config.artifact }} From bc5efc9ee553ba8f5ff594ac1ba3fd8f10663700 Mon Sep 17 00:00:00 2001 From: mio Date: Sat, 16 Oct 2021 20:35:23 +0200 Subject: [PATCH 2/2] Fix Android x86_64 build Note: At this time, both arm32 and arm64 emulation doesn't work on either macOS and Ubuntu so we could only have x86_64 --- .github/workflows/build-uc2.yml | 29 ++++++++++++++++++++++-- CMakeLists.txt | 39 ++++++++++++++++++++------------- 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build-uc2.yml b/.github/workflows/build-uc2.yml index 8cff3884..8953c7bf 100644 --- a/.github/workflows/build-uc2.yml +++ b/.github/workflows/build-uc2.yml @@ -223,7 +223,7 @@ jobs: cmake --build . --config ${{ matrix.config.build_type }} cmake --install . --strip ctest -C ${{ matrix.config.build_type }} - + - name: '🚧 Android x86_64 build' if: contains(matrix.config.name, 'android') shell: bash @@ -245,16 +245,41 @@ jobs: cmake --build . --config ${{ matrix.config.build_type }} cmake --install . --strip + - name: '🚧 AVD Cache' + if: contains(matrix.config.name, 'android') + uses: actions/cache@v2 + id: avd-cache + with: + path: | + ~/.android/avd/* + ~/.android/adb* + key: avd-28 + + - name: '🚧 Create x86_64 tests environment' + if: contains(matrix.config.name, 'android') && steps.avd-cache.outputs.cache-hit != 'true' + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: 28 + arch: ${{ matrix.config.arch }} + force-avd-creation: false + disable-animations: false + target: default + profile: Nexus 6 + emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -verbose -show-kernel + script: echo "Generated AVD snapshot for caching." + - name: '🚧 Android x86_64 tests' if: contains(matrix.config.name, 'android') uses: reactivecircus/android-emulator-runner@v2 with: api-level: 28 + force-avd-creation: false + disable-animations: true arch: ${{ matrix.config.arch }} target: default profile: Nexus 6 emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -verbose -show-kernel - script: ctest -C ${{ matrix.config.build_type }} + script: bash ./adb.sh - name: '📦 Pack artifact' shell: bash diff --git a/CMakeLists.txt b/CMakeLists.txt index b561cf5c..e8f23054 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,7 @@ else() endif() elseif(ANDROID_ABI) string(FIND "${ANDROID_ABI}" "arm64" UC_RET) + file(WRITE ${CMAKE_BINARY_DIR}/adb.sh "#!/bin/bash\n\nadb shell mkdir -p /data/local/tmp/build\n") if (${UC_RET} GREATER_EQUAL "0") set(UNICORN_TARGET_ARCH "aarch64") @@ -1023,6 +1024,9 @@ if (UNICORN_BUILD_SHARED) add_library(unicorn SHARED ${UNICORN_SRCS} ) + if (ANDROID_ABI) + file(APPEND ${CMAKE_BINARY_DIR}/adb.sh "adb push ./libunicorn.so /data/local/tmp/build/\n") + endif() else() add_library(unicorn STATIC ${UNICORN_SRCS} @@ -1159,22 +1163,27 @@ if(UNICORN_FUZZ) endforeach() else() foreach(SAMPLE_FILE ${UNICORN_SAMPLE_FILE}) - add_executable(${SAMPLE_FILE} - ${CMAKE_CURRENT_SOURCE_DIR}/samples/${SAMPLE_FILE}.c - ) - target_link_libraries(${SAMPLE_FILE} - ${SAMPLES_LIB} - ) - endforeach(SAMPLE_FILE) + add_executable(${SAMPLE_FILE} + ${CMAKE_CURRENT_SOURCE_DIR}/samples/${SAMPLE_FILE}.c + ) + target_link_libraries(${SAMPLE_FILE} + ${SAMPLES_LIB} + ) + endforeach(SAMPLE_FILE) - foreach(TEST_FILE ${UNICORN_TEST_FILE}) - add_executable(${TEST_FILE} - ${CMAKE_CURRENT_SOURCE_DIR}/tests/unit/${TEST_FILE}.c - ) - target_link_libraries(${TEST_FILE} - ${SAMPLES_LIB} - ) - add_test(${TEST_FILE} ${TEST_FILE}) + foreach(TEST_FILE ${UNICORN_TEST_FILE}) + add_executable(${TEST_FILE} + ${CMAKE_CURRENT_SOURCE_DIR}/tests/unit/${TEST_FILE}.c + ) + target_link_libraries(${TEST_FILE} + ${SAMPLES_LIB} + ) + add_test(${TEST_FILE} ${TEST_FILE}) + if (ANDROID_ABI) + file(APPEND ${CMAKE_BINARY_DIR}/adb.sh "adb push ${TEST_FILE} /data/local/tmp/build/\n") + file(APPEND ${CMAKE_BINARY_DIR}/adb.sh "adb shell \"chmod +x /data/local/tmp/build/${TEST_FILE}\"\n") + file(APPEND ${CMAKE_BINARY_DIR}/adb.sh "adb shell \'LD_LIBRARY_PATH=/data/local/tmp/build:$LD_LIBRARY_PATH /data/local/tmp/build/${TEST_FILE}\' || exit -1\n") + endif() endforeach(TEST_FILE) endif()