Skip to content

Commit bbda9a2

Browse files
committed
Add Android build support to CI workflow
- Introduced `android-build` job in GitHub Actions for building Android chapters. - Added caching for Gradle, KTX, tinygltf, and ccache to optimize builds. - Integrated setup steps for Android SDK, NDK, KTX library, and tinygltf. - Enabled dynamic chapter builds with Gradle based on supported chapters in `CMakeLists.txt`.
1 parent 466d65d commit bbda9a2

1 file changed

Lines changed: 127 additions & 29 deletions

File tree

.github/workflows/workflow.yml

Lines changed: 127 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
branches: [ main ]
88

99
jobs:
10+
1011
build:
1112
strategy:
1213
fail-fast: false
@@ -16,34 +17,26 @@ jobs:
1617
- os: ubuntu-latest
1718
ccache: ccache
1819
vulkan-install: |
19-
# Download and install Vulkan SDK using the tar.gz method
2020
VULKAN_VERSION=$(curl -s https://vulkan.lunarg.com/sdk/latest/linux.txt)
2121
echo "Using Vulkan SDK version: $VULKAN_VERSION"
2222
23-
# Create a temporary directory for the SDK
2423
mkdir -p vulkan-sdk
2524
cd vulkan-sdk
2625
27-
# Download the SDK
2826
curl -O "https://sdk.lunarg.com/sdk/download/$VULKAN_VERSION/linux/vulkansdk-linux-x86_64-$VULKAN_VERSION.tar.xz"
2927
30-
# Extract the SDK - use tar with J flag for xz compression
3128
tar -xJf vulkansdk-linux-x86_64-$VULKAN_VERSION.tar.xz
3229
33-
# Set up environment variables
3430
echo "VULKAN_SDK=$PWD/$VULKAN_VERSION/x86_64" >> $GITHUB_ENV
3531
echo "PATH=$PWD/$VULKAN_VERSION/x86_64/bin:$PATH" >> $GITHUB_ENV
3632
echo "LD_LIBRARY_PATH=$PWD/$VULKAN_VERSION/x86_64/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
3733
echo "VK_LAYER_PATH=$PWD/$VULKAN_VERSION/x86_64/etc/vulkan/explicit_layer.d" >> $GITHUB_ENV
3834
39-
# Return to the original directory
4035
cd ..
4136
deps-install: |
42-
# Use our existing dependency installation script
4337
chmod +x scripts/install_dependencies_linux.sh
4438
./scripts/install_dependencies_linux.sh
4539
test-cmd: |
46-
# Check if some of the expected executables were built
4740
if [ -f "00_base_code/00_base_code" ]; then
4841
echo "00_base_code built successfully"
4942
else
@@ -67,27 +60,22 @@ jobs:
6760
- os: windows-latest
6861
ccache: sccache
6962
vulkan-install: |
70-
# Download the Vulkan SDK installer
7163
Invoke-WebRequest -Uri "https://sdk.lunarg.com/sdk/download/latest/windows/vulkan-sdk.exe" -OutFile "$env:TEMP\vulkan-sdk.exe"
7264
73-
# Run the installer with silent options
7465
Start-Process -FilePath "$env:TEMP\vulkan-sdk.exe" -ArgumentList "--accept-licenses --default-answer --confirm-command install" -Wait -NoNewWindow
7566
76-
# Find the actual installed SDK version
77-
$vulkanPath = Get-ChildItem "C:\VulkanSDK" | Sort-Object -Property Name -Descending | Select-Object -First 1 -ExpandProperty FullName
67+
$vulkanPath = Get-ChildItem "C:\VulkanSDK" | Sort-Object -Property Name -Descending | Select-Object -First 1 -ExpandProperty FullName
7868
7969
if (-not $vulkanPath) {
8070
$vulkanPath = "C:\VulkanSDK\latest"
8171
}
8272
83-
# Set environment variables with correct Windows-style paths
8473
echo "VULKAN_SDK=$vulkanPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
8574
echo "$vulkanPath\Bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
8675
echo "CMAKE_PREFIX_PATH=$vulkanPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
8776
echo "Vulkan_INCLUDE_DIR=$vulkanPath\Include" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
8877
echo "Vulkan_LIBRARY=$vulkanPath\Lib\vulkan-1.lib" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
8978
90-
# Display debug information
9179
Write-Host "Vulkan SDK path: $vulkanPath"
9280
if (Test-Path "$vulkanPath\Lib") {
9381
Write-Host "Lib directory exists"
@@ -100,11 +88,9 @@ jobs:
10088
Write-Host "Include directory does not exist"
10189
}
10290
deps-install: |
103-
# Use our existing dependency installation script
10491
.\scripts\install_dependencies_windows.bat
10592
echo "CMAKE_TOOLCHAIN_FILE=$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" >> $env:GITHUB_ENV
10693
test-cmd: |
107-
# Check if some of the expected executables were built
10894
if (Test-Path "00_base_code/Release/00_base_code.exe") {
10995
echo "00_base_code built successfully"
11096
} else {
@@ -131,7 +117,6 @@ jobs:
131117
steps:
132118
- uses: actions/checkout@v3
133119

134-
# Cache vcpkg packages for Windows
135120
- name: Cache vcpkg packages (Windows)
136121
if: runner.os == 'Windows'
137122
uses: actions/cache@v3
@@ -145,7 +130,6 @@ jobs:
145130
${{ runner.os }}-vcpkg-${{ hashFiles('**/CMakeLists.txt') }}-
146131
${{ runner.os }}-vcpkg-
147132
148-
# Cache Vulkan SDK for Windows
149133
- name: Cache Vulkan SDK (Windows)
150134
if: runner.os == 'Windows'
151135
uses: actions/cache@v3
@@ -155,7 +139,6 @@ jobs:
155139
restore-keys: |
156140
${{ runner.os }}-vulkan-sdk-
157141
158-
# Cache apt packages for Ubuntu
159142
- name: Cache apt packages (Ubuntu)
160143
if: runner.os == 'Linux'
161144
uses: actions/cache@v3
@@ -165,7 +148,6 @@ jobs:
165148
restore-keys: |
166149
${{ runner.os }}-apt-
167150
168-
# Cache ccache files
169151
- name: Cache ccache files
170152
uses: actions/cache@v3
171153
with:
@@ -176,7 +158,6 @@ jobs:
176158
restore-keys: |
177159
${{ runner.os }}-${{ matrix.ccache }}-
178160
179-
# Cache Vulkan SDK for Ubuntu
180161
- name: Cache Vulkan SDK (Ubuntu)
181162
if: runner.os == 'Linux'
182163
uses: actions/cache@v3
@@ -188,7 +169,6 @@ jobs:
188169
${{ runner.os }}-vulkan-sdk-${{ hashFiles('**/CMakeLists.txt') }}-
189170
${{ runner.os }}-vulkan-sdk-
190171
191-
# Install ccache or sccache
192172
- name: Install ccache (Ubuntu)
193173
if: runner.os == 'Linux'
194174
run: |
@@ -221,7 +201,6 @@ jobs:
221201
if (Test-Path $env:VULKAN_SDK) {
222202
echo "Vulkan SDK found at: $env:VULKAN_SDK"
223203
224-
# Check for critical directories and files
225204
$criticalPaths = @(
226205
"$env:VULKAN_SDK\Include",
227206
"$env:VULKAN_SDK\Lib",
@@ -252,7 +231,6 @@ jobs:
252231
exit 1
253232
}
254233
255-
# Cache CMake build directory for Windows
256234
- name: Cache build artifacts (Windows)
257235
if: runner.os == 'Windows'
258236
uses: actions/cache@v3
@@ -275,13 +253,11 @@ jobs:
275253
-DCMAKE_C_COMPILER_LAUNCHER=sccache `
276254
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache
277255
278-
# Display CMake cache to debug Vulkan detection
279256
if (Test-Path "build/CMakeCache.txt") {
280257
Write-Host "CMake cache contents:"
281258
Get-Content "build/CMakeCache.txt" | Select-String -Pattern "Vulkan"
282259
}
283260
284-
# Verify Vulkan Installation for Ubuntu
285261
- name: Verify Vulkan Installation (Ubuntu)
286262
if: runner.os == 'Linux'
287263
run: |
@@ -293,7 +269,6 @@ jobs:
293269
exit 1
294270
fi
295271
296-
# Cache CMake build directory for Ubuntu
297272
- name: Cache build artifacts (Ubuntu)
298273
if: runner.os == 'Linux'
299274
uses: actions/cache@v3
@@ -308,7 +283,6 @@ jobs:
308283
working-directory: ${{github.workspace}}/attachments
309284
if: runner.os != 'Windows'
310285
run: |
311-
# Use Clang for better C++20 module support
312286
export CC="ccache clang"
313287
export CXX="ccache clang++"
314288
@@ -322,7 +296,6 @@ jobs:
322296
working-directory: ${{github.workspace}}/attachments
323297
run: cmake --build build --config Release
324298

325-
# Display ccache/sccache statistics
326299
- name: ccache statistics
327300
if: runner.os == 'Linux'
328301
run: ccache -s
@@ -334,3 +307,128 @@ jobs:
334307
- name: Test Build Output
335308
working-directory: ${{github.workspace}}/attachments/build
336309
run: ${{ matrix.test-cmd }}
310+
311+
312+
android-build:
313+
name: Android Build
314+
runs-on: ubuntu-latest
315+
316+
steps:
317+
- uses: actions/checkout@v3
318+
319+
- name: Cache ccache files
320+
uses: actions/cache@v3
321+
with:
322+
path: ~/.ccache
323+
key: android-ccache-${{ github.sha }}
324+
restore-keys: |
325+
android-ccache-
326+
327+
- name: Cache KTX and tinygltf
328+
uses: actions/cache@v3
329+
with:
330+
path: |
331+
/usr/local/include/ktx
332+
/usr/local/lib/libktx*
333+
/usr/local/include/tinygltf
334+
key: android-libs-${{ hashFiles('**/workflow.yml') }}
335+
restore-keys: |
336+
android-libs-
337+
338+
- name: Cache Gradle packages
339+
uses: actions/cache@v3
340+
with:
341+
path: |
342+
~/.gradle/caches
343+
~/.gradle/wrapper
344+
${{github.workspace}}/attachments/android/.gradle
345+
${{github.workspace}}/attachments/android/app/build/intermediates
346+
${{github.workspace}}/attachments/android/app/build/outputs
347+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}-${{ hashFiles('**/*.cpp', '**/*.h') }}
348+
restore-keys: |
349+
${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}-
350+
${{ runner.os }}-gradle-
351+
352+
- name: Install ccache
353+
run: |
354+
sudo apt-get update
355+
sudo apt-get install -y ccache
356+
ccache --max-size=2G
357+
ccache -z
358+
echo "CCACHE_DIR=$HOME/.ccache" >> $GITHUB_ENV
359+
echo "PATH=/usr/lib/ccache:$PATH" >> $GITHUB_ENV
360+
361+
- name: Set up Android SDK and NDK
362+
run: |
363+
echo "Using pre-installed Android SDK and NDK on GitHub runner"
364+
echo "ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT" >> $GITHUB_ENV
365+
echo "ANDROID_NDK_HOME=$ANDROID_NDK_ROOT" >> $GITHUB_ENV
366+
echo "Android SDK location: $ANDROID_SDK_ROOT"
367+
echo "Android NDK location: $ANDROID_NDK_ROOT"
368+
369+
- name: Install KTX library
370+
run: |
371+
if [ -d "/usr/local/include/ktx" ] && [ -f "/usr/local/lib/libktx.so" ]; then
372+
echo "KTX library already installed from cache"
373+
else
374+
echo "Installing KTX library..."
375+
git clone https://github.com/KhronosGroup/KTX-Software.git
376+
cd KTX-Software
377+
git checkout v4.1.0
378+
mkdir build && cd build
379+
cmake .. -DCMAKE_BUILD_TYPE=Release -DKTX_FEATURE_TOOLS=OFF
380+
cmake --build . --config Release
381+
sudo cmake --install .
382+
cd ../..
383+
fi
384+
385+
- name: Install tinygltf
386+
run: |
387+
if [ -d "/usr/local/include/tinygltf" ]; then
388+
echo "tinygltf library already installed from cache"
389+
else
390+
echo "Installing tinygltf..."
391+
git clone https://github.com/syoyo/tinygltf.git
392+
cd tinygltf
393+
mkdir build && cd build
394+
cmake .. -DCMAKE_BUILD_TYPE=Release -DTINYGLTF_BUILD_LOADER_EXAMPLE=OFF
395+
cmake --build . --config Release
396+
sudo cmake --install .
397+
cd ../..
398+
fi
399+
400+
- name: Build Android Chapters
401+
working-directory: ${{github.workspace}}/attachments/android
402+
run: |
403+
if [ ! -f "gradlew" ]; then
404+
echo "Generating Gradle wrapper..."
405+
gradle wrapper
406+
fi
407+
408+
SUPPORTED_CHAPTERS=$(grep -A 20 "set(SUPPORTED_CHAPTERS" app/src/main/cpp/CMakeLists.txt |
409+
sed -n '/set(SUPPORTED_CHAPTERS/,/)/p' |
410+
grep -o '"[^"]*"' |
411+
sed 's/"//g')
412+
413+
readarray -t CHAPTERS <<< "$SUPPORTED_CHAPTERS"
414+
415+
echo "Detected supported Android chapters: ${CHAPTERS[@]}"
416+
417+
for chapter in "${CHAPTERS[@]}"; do
418+
if [ -n "$chapter" ]; then
419+
echo "Building $chapter chapter..."
420+
421+
if [ "$chapter" != "${CHAPTERS[0]}" ]; then
422+
./gradlew clean
423+
fi
424+
425+
./gradlew assembleDebug -Pchapter=$chapter
426+
427+
if [ -f "app/build/outputs/apk/debug/app-debug.apk" ]; then
428+
echo "$chapter built successfully"
429+
else
430+
echo "$chapter build failed"
431+
exit 1
432+
fi
433+
fi
434+
done

0 commit comments

Comments
 (0)