Skip to content

Commit

Permalink
Merge pull request #80 from CommitteeOfZero/android-build
Browse files Browse the repository at this point in the history
Android build
  • Loading branch information
MrRevo3D authored Oct 16, 2024
2 parents 47ea372 + 66a066f commit 378a2a8
Show file tree
Hide file tree
Showing 66 changed files with 6,770 additions and 125 deletions.
100 changes: 78 additions & 22 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ on:
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}

permissions:
checks: write
contents: write

jobs:
lint:
name: Run linters
permissions:
checks: write
contents: write
runs-on: ubuntu-latest
outputs:
commitid: ${{ steps.commit.outputs.commitid }}
Expand Down Expand Up @@ -50,34 +50,65 @@ jobs:
runs-on: ${{ matrix.os }}
timeout-minutes: 120
needs: lint
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
os_name: windows
triplet: x64-windows-release
host_triplet: x64-windows-release
- os: ubuntu-latest
os_name: linux
triplet: x64-linux-dynamic
triplet: x64-linux-ci
host_triplet: x64-linux-ci
- os: macos-latest
os_name: macos-arm64
triplet: arm64-osx-dynamic
triplet: arm64-osx-ci
host_triplet: arm64-osx-ci
- os: macos-13
os_name: macos-x64
triplet: x64-osx-dynamic
triplet: x64-osx-ci
host_triplet: x64-osx-ci
- os: ubuntu-latest
os_name: switch
triplet: none
host_triplet: none
- os: ubuntu-latest
os_name: android
triplet: arm64-android-ci
host_triplet: x64-linux-ci
env:
VCPKG_DEFAULT_TRIPLET: ${{ matrix.triplet }}
vcpkgCommitId: '0f88ecb8528605f91980b90a2c5bad88e3cb565f'
PresetName: ${{ (matrix.os_name == 'android') && 'ci-release-android' || 'ci-release' }}

steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.lint.outputs.commitid }}

- name: Setup Android Environment
if: matrix.os_name == 'android'
run: |
export ABI=arm64-v8a
export MINSDKVERSION=28
echo "MINSDKVERSION=$MINSDKVERSION" >> $GITHUB_ENV
echo "ABI=$ABI" >> $GITHUB_ENV
echo "CC=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=aarch64-linux-android$MINSDKVERSION -fPIC" >> $GITHUB_ENV
echo "VULKAN_SDK=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr" >> $GITHUB_ENV
shell: bash

- name: Set up Java
uses: actions/setup-java@v4
if: matrix.os_name == 'android'
with:
java-version: 17
distribution: "temurin"
cache: 'gradle'

- name: Download Switch deps
if: matrix.os_name == 'switch'
uses: blauqs/actions-download-asset@master
Expand Down Expand Up @@ -105,12 +136,12 @@ jobs:
vcpkgGitCommitId: '${{ env.vcpkgCommitId }}'
vcpkgJsonGlob: '**/vcpkg.json'
- name: Build Atrac9 Windows
if: matrix.os == 'windows-latest'
if: matrix.os_name == 'windows'
run: |
./build-deps.ps1 -Arg1 x64
shell: pwsh
- name: Setup Dependencies Linux/MacOS
if: contains(matrix.os_name, 'macos') || contains(matrix.os_name, 'linux')
- name: Setup Dependencies Linux/MacOS/Android
if: contains(matrix.os_name, 'macos') || contains(matrix.os_name, 'linux') || contains(matrix.os_name, 'android')
run: |-
pushd vendor
if [ ! -d "LibAtrac9" ]; then
Expand All @@ -120,16 +151,17 @@ jobs:
if [[ "${{ matrix.os_name }}" == "macos"* ]]; then
sed -i '' -e 's/,--version-script=libatrac9.version//g' Makefile
fi
make
make CC="$CC"
mkdir -p ../include/libatrac9
mkdir -p ../libs
cp bin/libatrac9.a ../libs/
cp src/libatrac9.h ../include/libatrac9/
popd
echo "LIBATRAC9DIR=${{ github.workspace }}/vendor/LibAtrac9" >> $GITHUB_ENV
find "${{ github.workspace }}/vendor/LibAtrac9"
- name: Install Dependencies Linux
run: sudo apt-get install nasm libx11-dev libxft-dev libxext-dev libwayland-dev libxkbcommon-dev libegl1-mesa-dev libibus-1.0-dev libxrandr-dev
if: matrix.os_name == 'linux'
if: matrix.os_name == 'linux' || matrix.os_name == 'android'
- name: Install Dependencies Mac
run: brew install nasm
if: contains(matrix.os_name, 'macos')
Expand All @@ -138,9 +170,13 @@ jobs:
uses: lukka/run-cmake@v10
with:
cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt'
configurePreset: ci-release
configurePresetAdditionalArgs: "['-DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }}', '-DVCPKG_HOST_TRIPLET=${{ matrix.triplet }}', '-DVCPKG_BUILD_TYPE=release']"
buildPreset: CI-Build
configurePreset: ${{ env.PresetName }}
configurePresetAdditionalArgs: >-
[
'-DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }}',
'-DVCPKG_HOST_TRIPLET=${{ matrix.host_triplet }}',
]
buildPreset: ${{ env.PresetName }}

- name: Run Switch build
if: matrix.os_name == 'switch'
Expand All @@ -152,20 +188,37 @@ jobs:
cmake . -DCMAKE_TOOLCHAIN_FILE=HorizonNX.toolchain
make -j2
elf2nro impacto impacto.nro
mkdir -p "${{ github.workspace }}/release/ci-release"
cp impacto.nro "${{ github.workspace }}/release/ci-release"
cp -r profiles "${{ github.workspace }}/release/ci-release"
cp -r games "${{ github.workspace }}/release/ci-release"
mkdir -p "${{ github.workspace }}/release/${{ env.PresetName }}"
cp impacto.nro "${{ github.workspace }}/release/${{ env.PresetName }}"
cp -r profiles "${{ github.workspace }}/release/${{ env.PresetName }}"
cp -r games "${{ github.workspace }}/release/${{ env.PresetName }}"
- name: Copy Shaders
run: cp -r src/shaders "${{ github.workspace }}/release/ci-release"
run: cp -r src/shaders "${{ github.workspace }}/release/${{ env.PresetName }}"
shell: bash
- name: Copy docs
run: |
cp THIRDPARTY.md README.md LICENSE "${{ github.workspace }}/release/ci-release"
cp THIRDPARTY.md README.md LICENSE "${{ github.workspace }}/release/${{ env.PresetName }}"
shell: bash
- name: Build Android
if: matrix.os_name == 'android'
run: |
pushd "${{ github.workspace }}/release/${{ env.PresetName }}"
ls
mkdir -p "${{ github.workspace }}/android/app/src/main/assets/"
mv profiles "${{ github.workspace }}/android/app/src/main/assets/"
mv games "${{ github.workspace }}/android/app/src/main/assets/"
mv shaders "${{ github.workspace }}/android/app/src/main/assets/"
mkdir -p "${{ github.workspace }}/android/app/src/main/jniLibs/$ABI/"
popd
pushd "${{ github.workspace }}/android/"
./gradlew assemble
find "${{ github.workspace }}/android" -name "*.apk"
cp "${{ github.workspace }}/android/distribution/android/app/outputs/apk/debug/app-debug.apk" "${{ github.workspace }}/release/${{ env.PresetName }}/impacto-debug.apk"
cp "${{ github.workspace }}/android/distribution/android/app/outputs/apk/release/app-release-unsigned.apk" "${{ github.workspace }}/release/${{ env.PresetName }}/impacto-unsigned.apk"
shell: bash
- name: Archive Artifacts
run: |
7z u impacto-${{ matrix.os_name }}-${{ vars.VERSION }}${{ github.run_number }}-${{ github.sha }}.zip release/ci-release/*
7z u impacto-${{ matrix.os_name }}-${{ vars.VERSION }}${{ github.run_number }}-${{ github.sha }}.zip release/${{ env.PresetName }}/*
- name: Upload Artifact
uses: actions/upload-artifact@v4.1.0
with:
Expand All @@ -176,6 +229,8 @@ jobs:
publish_artifacts:
name: Publish Artifacts
runs-on: ubuntu-22.04
permissions:
contents: write
needs:
- job-matrix
if: needs.job-matrix.result == 'success' && github.event_name != 'pull_request_target' && ((startsWith(github.ref, 'refs/tags') || github.ref_name == 'master'))
Expand Down Expand Up @@ -236,7 +291,7 @@ jobs:
name_conclusion_array=($(echo "$json_data" | jq -r '
.jobs[] |
select(.name | IN("macos-arm64", "linux", "windows", "switch", "macos-x64")) |
select(.name | IN("macos-arm64", "linux", "windows", "switch", "macos-x64", "android")) |
"\(.name).\(.conclusion)"'))
for item in "${name_conclusion_array[@]}"; do
Expand Down Expand Up @@ -267,6 +322,7 @@ jobs:
macos-arm64: ${{steps.get_jobs_status.outputs.macos-arm64}}
macos-x64: ${{steps.get_jobs_status.outputs.macos-x64}}
switch: ${{steps.get_jobs_status.outputs.switch}}
android: ${{steps.get_jobs_status.outputs.android}}
Details:
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ cmake_install.cmake
include/
Makefile
.DS_Store
.cache

# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
Expand Down Expand Up @@ -273,6 +274,9 @@ paket-files/
__pycache__/
*.pyc

# VSCode
.vscode

###

compile_commands.json
Expand Down
36 changes: 32 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,10 @@ if (NX OR EMSCRIPTEN)
set(IMPACTO_DISABLE_DX9 ON)
endif ()

if(ANDROID)
set(IMPACTO_DISABLE_IMGUI ON)
endif ()

if (UNIX AND NOT CYGWIN)
set(IMPACTO_DISABLE_DX9 ON)
endif ()
Expand Down Expand Up @@ -682,6 +686,7 @@ FetchContent_Declare(
GIT_TAG "11.0.2"
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vendor/fmtlib
SYSTEM
EXCLUDE_FROM_ALL
)

FetchContent_Declare(
Expand All @@ -690,6 +695,7 @@ FetchContent_Declare(
GIT_TAG "v1.14"
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vendor/pugixml
SYSTEM
EXCLUDE_FROM_ALL
)

FetchContent_Declare(
Expand All @@ -698,6 +704,7 @@ FetchContent_Declare(
GIT_TAG "v4.0.5"
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vendor/utf8-cpp
SYSTEM
EXCLUDE_FROM_ALL
)

FetchContent_MakeAvailable(fmt)
Expand All @@ -715,7 +722,6 @@ if (NOT DEFINED IMPACTO_DISABLE_IMGUI)
FetchContent_MakeAvailable(ImGui)
endif ()


if (WIN32)
# Workaround for RelWithDebInfo builds not installing all the libraries
set(CMAKE_MAP_IMPORTED_CONFIG_MINSIZEREL Release)
Expand All @@ -733,6 +739,7 @@ if (WIN32)
set(LIBATRAC9_LIBRARY "${CMAKE_CURRENT_SOURCE_DIR}/vendor/LibAtrac9/bin/${LIBATRAC9_ARCH}/libatrac9.lib")
endif ()


find_package(Libatrac9 REQUIRED)
find_package(glm REQUIRED)

Expand All @@ -747,6 +754,18 @@ else ()
)
endif ()

if(ANDROID)
set(SDL2_LIBRARIES SDL2::SDL2-static SDL2::SDL2main)

if (NOT DEFINED IMPACTO_DISABLE_OPENGL)
find_library(GLESv3 GLESv3)
list(APPEND Impacto_Libs
GLESv3
)

endif ()
endif ()

if (NOT DEFINED IMPACTO_DISABLE_OPENAL)
find_package(OpenAL REQUIRED)

Expand Down Expand Up @@ -1040,9 +1059,14 @@ if (NOT DEFINED IMPACTO_DISABLE_DX9)
)
endif ()

add_executable(impacto ${Impacto_Src} ${Impacto_Header})
if(ANDROID)
add_library(impacto SHARED ${Impacto_Src} ${Impacto_Header})
target_link_options(impacto PRIVATE "LINKER:--build-id=sha1")
else()
add_executable(impacto ${Impacto_Src} ${Impacto_Header})
endif()

target_link_libraries(impacto PUBLIC ${Impacto_Libs})
target_link_libraries(impacto PRIVATE ${Impacto_Libs})

# compiler/dependency configuration

Expand Down Expand Up @@ -1095,7 +1119,11 @@ target_include_directories(impacto PRIVATE ${PROJECT_BINARY_DIR}/include)

# binary install

install(TARGETS impacto RUNTIME DESTINATION .)
if (ANDROID)
install(TARGETS impacto LIBRARY DESTINATION ${CMAKE_SOURCE_DIR}/android/app/src/main/jniLibs/${CMAKE_ANDROID_ARCH_ABI}/)
else ()
install(TARGETS impacto RUNTIME DESTINATION .)
endif ()

if (WIN32)
x_vcpkg_install_local_dependencies(TARGETS impacto DESTINATION .)
Expand Down
31 changes: 29 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,46 @@
"installDir": "release/${presetName}",
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
"CMAKE_BUILD_TYPE": "Release",
"VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/triplets"
}
},
{
"name": "ci-release-android",
"description": "Android Release build for CI",
"hidden": false,
"inherits": [
"ci-release"
],
"cacheVariables": {
"VCPKG_TARGET_TRIPLET":"arm64-android-ci",
"VCPKG_CHAINLOAD_TOOLCHAIN_FILE":"$env{VCPKG_ROOT}/scripts/toolchains/android.cmake",
"CMAKE_FIND_ROOT_PATH_MODE_LIBRARY": "BOTH",
"CMAKE_FIND_ROOT_PATH_MODE_INCLUDE": "BOTH",
"CMAKE_FIND_ROOT_PATH_MODE_PACKAGE": "BOTH",
"ANDROID_PLATFORM":"android-$env{MINSDKVERSION}",
"ANDROID_ABI": "arm64-v8a",
"ANDROID_STL": "c++_static"
}
}
],
"buildPresets": [
{
"name": "CI-Build",
"name": "ci-release",
"description": "x64 Release",
"configurePreset": "ci-release",
"targets": [
"install"
]
},
{
"name": "ci-release-android",
"description": "x64 Release Android",
"configurePreset": "ci-release-android",
"targets": [
"install"
]
},
{
"name": "x64-Release",
"description": "x64 Release with Debug Symbols",
Expand Down
Loading

0 comments on commit 378a2a8

Please sign in to comment.