android.yml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. name: Build (Android)
  2. on: [push, pull_request]
  3. concurrency:
  4. group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
  5. cancel-in-progress: true
  6. jobs:
  7. android:
  8. name: ${{ matrix.platform.name }}
  9. runs-on: ubuntu-latest
  10. strategy:
  11. fail-fast: false
  12. matrix:
  13. platform:
  14. - { name: "Android.mk", ndk-build: 1 }
  15. - { name: "Gradle", gradle: 1 }
  16. - { name: "CMake", cmake: 1, android_abi: "arm64-v8a", android_platform: 23, arch: "aarch64", artifact: "SDL-android-arm64", apk-artifact: "SDL-android-apks-arm64" }
  17. - { name: "CMake (lean and mean)", cmake: 1, cppflags: "-DSDL_LEAN_AND_MEAN=1", android_abi: "arm64-v8a", android_platform: 23, arch: "aarch64", artifact: "SDL-lean-android-arm64", apk-artifact: "SDL-lean-android-apks-arm64" }
  18. steps:
  19. - uses: actions/checkout@v4
  20. - uses: nttld/setup-ndk@v1
  21. if: ${{ matrix.platform.cmake || matrix.platform.ndk-build }}
  22. id: setup_ndk
  23. with:
  24. local-cache: true
  25. ndk-version: r21e
  26. - name: Build (Android.mk)
  27. if: ${{ matrix.platform.ndk-build }}
  28. run: |
  29. ./build-scripts/androidbuildlibs.sh
  30. - uses: actions/setup-java@v4
  31. if: ${{ matrix.platform.cmake || matrix.platform.gradle }}
  32. with:
  33. distribution: 'temurin'
  34. java-version: '17'
  35. - name: Create Gradle project
  36. if: ${{ matrix.platform.gradle }}
  37. run: |
  38. python build-scripts/create-android-project.py \
  39. --output "build" \
  40. --variant copy \
  41. org.libsdl.testspriteminimal \
  42. test/testspriteminimal.c test/icon.h
  43. echo ""
  44. echo "Project contents:"
  45. echo ""
  46. find "build/org.libsdl.testspriteminimal"
  47. - name: Build app (Gradle & ndk-build)
  48. if: ${{ matrix.platform.gradle }}
  49. run: |
  50. cd build/org.libsdl.testspriteminimal
  51. ./gradlew -i assembleRelease
  52. - name: Build app (Gradle & CMake)
  53. if: ${{ matrix.platform.gradle }}
  54. run: |
  55. cd build/org.libsdl.testspriteminimal
  56. ./gradlew -i assembleRelease -PBUILD_WITH_CMAKE=1
  57. # - name: Build library (Gradle)
  58. # if: ${{ matrix.platform.gradle }}
  59. # run: |
  60. # cd build/org.libsdl.testspriteminimal
  61. # ./gradlew -i assembleRelease -PBUILD_AS_LIBRARY=1
  62. - name: Setup (CMake)
  63. if: ${{ matrix.platform.cmake }}
  64. run: |
  65. sudo apt-get update
  66. sudo apt-get install ninja-build pkg-config
  67. - name: Configure (CMake)
  68. if: ${{ matrix.platform.cmake }}
  69. run: |
  70. cmake -S . -B build \
  71. -DCMAKE_C_FLAGS="${{ matrix.platform.cppflags }}" \
  72. -DCMAKE_CXX_FLAGS="${{ matrix.platform.cppflags }}" \
  73. -Wdeprecated -Wdev -Werror \
  74. -DCMAKE_TOOLCHAIN_FILE=${{ steps.setup_ndk.outputs.ndk-path }}/build/cmake/android.toolchain.cmake \
  75. -DSDL_WERROR=ON \
  76. -DSDL_TESTS=ON \
  77. -DSDL_INSTALL_TESTS=ON \
  78. -DSDL_EXAMPLES=ON \
  79. -DSDL_CLANG_TIDY=ON \
  80. -DSDL_DISABLE_INSTALL_DOCS=OFF \
  81. -DANDROID_PLATFORM=${{ matrix.platform.android_platform }} \
  82. -DANDROID_ABI=${{ matrix.platform.android_abi }} \
  83. -DSDL_SHARED=ON \
  84. -DSDL_STATIC=ON \
  85. -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
  86. -DSDL_VENDOR_INFO="Github Workflow" \
  87. -DCMAKE_INSTALL_PREFIX=prefix \
  88. -DCMAKE_BUILD_TYPE=Release \
  89. -GNinja
  90. - name: Build (CMake)
  91. if: ${{ matrix.platform.cmake }}
  92. run: |
  93. cmake --build build --config Release --parallel --verbose
  94. - name: Build test apk's (CMake)
  95. if: ${{ matrix.platform.cmake }}
  96. run: |
  97. cmake --build build --config Release --parallel \
  98. --target \
  99. testaudiorecording-apk \
  100. testautomation-apk \
  101. testcontroller-apk \
  102. testmultiaudio-apk \
  103. testsprite-apk \
  104. --verbose
  105. - name: Install (CMake)
  106. if: ${{ matrix.platform.cmake }}
  107. run: |
  108. cmake --install build --config Release
  109. echo "SDL3_DIR=$(pwd)/prefix" >> $GITHUB_ENV
  110. ( cd prefix; find ) | LC_ALL=C sort -u
  111. - name: Package (CPack)
  112. if: ${{ matrix.platform.cmake }}
  113. run: |
  114. cmake --build build/ --config Release --target package
  115. - name: Verify CMake configuration files
  116. if: ${{ matrix.platform.cmake }}
  117. run: |
  118. cmake -S cmake/test -B cmake_config_build -G Ninja \
  119. -DCMAKE_TOOLCHAIN_FILE=${{ steps.setup_ndk.outputs.ndk-path }}/build/cmake/android.toolchain.cmake \
  120. -DANDROID_PLATFORM=${{ matrix.platform.android_platform }} \
  121. -DANDROID_ABI=${{ matrix.platform.android_abi }} \
  122. -DCMAKE_BUILD_TYPE=Release \
  123. -DCMAKE_PREFIX_PATH=${{ env.SDL3_DIR }}
  124. cmake --build cmake_config_build --verbose
  125. - name: Verify sdl3.pc
  126. if: ${{ matrix.platform.cmake }}
  127. run: |
  128. export CC="${{ steps.setup_ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=${{ matrix.platform.arch }}-none-linux-androideabi${{ matrix.platform.android_platform }}"
  129. export PKG_CONFIG_PATH=${{ env.SDL3_DIR }}/lib/pkgconfig
  130. cmake/test/test_pkgconfig.sh
  131. - uses: actions/upload-artifact@v4
  132. if: ${{ matrix.platform.cmake }}
  133. with:
  134. if-no-files-found: error
  135. name: ${{ matrix.platform.artifact }}
  136. path: build/dist/SDL3*
  137. - uses: actions/upload-artifact@v4
  138. if: ${{ matrix.platform.cmake }}
  139. with:
  140. if-no-files-found: error
  141. name: ${{ matrix.platform.apk-artifact }}
  142. path: build/test/*.apk