-
Notifications
You must be signed in to change notification settings - Fork 86
562 lines (487 loc) · 23 KB
/
workflow.yml
File metadata and controls
562 lines (487 loc) · 23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
name: CMake CI
# Optimized workflow for faster builds
# Optimizations include:
# 1. Improved caching strategy with more specific cache keys
# 2. Optimized ccache/sccache configuration for better performance
# 3. Minimal Vulkan SDK installation (only necessary components)
# 4. Parallel builds for all platforms
# 5. Dynamic chapter detection from CMakeLists.txt for future extensibility
# 6. Eliminated unnecessary clean steps between builds
# 7. Optimized build configuration for better performance
# 8. Linux: Using ccache with clang for faster builds
# 9. Windows: Using MSVC for better performance and compatibility
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
include:
- os: ubuntu-latest
ccache: ccache
vulkan-install: |
VULKAN_VERSION=$(curl -s https://vulkan.lunarg.com/sdk/latest/linux.txt)
echo "Using Vulkan SDK version: $VULKAN_VERSION"
mkdir -p vulkan-sdk
cd vulkan-sdk
curl -O "https://sdk.lunarg.com/sdk/download/$VULKAN_VERSION/linux/vulkansdk-linux-x86_64-$VULKAN_VERSION.tar.xz"
tar -xJf vulkansdk-linux-x86_64-$VULKAN_VERSION.tar.xz
echo "VULKAN_SDK=$PWD/$VULKAN_VERSION/x86_64" >> $GITHUB_ENV
echo "PATH=$PWD/$VULKAN_VERSION/x86_64/bin:$PATH" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=$PWD/$VULKAN_VERSION/x86_64/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
echo "VK_LAYER_PATH=$PWD/$VULKAN_VERSION/x86_64/etc/vulkan/explicit_layer.d" >> $GITHUB_ENV
cd ..
deps-install: |
chmod +x scripts/install_dependencies_linux.sh
./scripts/install_dependencies_linux.sh
test-cmd: |
if [ -f "00_base_code/00_base_code" ]; then
echo "00_base_code built successfully"
else
echo "00_base_code build failed"
exit 1
fi
if [ -f "15_hello_triangle/15_hello_triangle" ]; then
echo "15_hello_triangle built successfully"
else
echo "15_hello_triangle build failed"
exit 1
fi
if [ -f "31_compute_shader/31_compute_shader" ]; then
echo "31_compute_shader built successfully"
else
echo "31_compute_shader build failed"
exit 1
fi
- os: windows-latest
ccache: sccache
vulkan-install: |
# Download the Vulkan SDK installer
Invoke-WebRequest -Uri "https://sdk.lunarg.com/sdk/download/latest/windows/vulkan-sdk.exe" -OutFile "$env:TEMP\vulkan-sdk.exe"
# Install only the necessary components of Vulkan SDK
# --components argument specifies only the components we need:
# - VulkanRT: Vulkan Runtime
# - VulkanSDK32: Core 32-bit SDK
# - VulkanSDK64: Core 64-bit SDK
# - VulkanDXC: DirectX Shader Compiler
# - VulkanTools: Vulkan Tools (includes glslangValidator)
Start-Process -FilePath "$env:TEMP\vulkan-sdk.exe" -ArgumentList "--accept-licenses --default-answer --confirm-command install --components VulkanRT,VulkanSDK64,VulkanDXC,VulkanTools" -Wait -NoNewWindow
# Find the installed Vulkan SDK path
$vulkanPath = Get-ChildItem "C:\VulkanSDK" | Sort-Object -Property Name -Descending | Select-Object -First 1 -ExpandProperty FullName
if (-not $vulkanPath) {
$vulkanPath = "C:\VulkanSDK\latest"
}
# Set environment variables
echo "VULKAN_SDK=$vulkanPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "$vulkanPath\Bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "CMAKE_PREFIX_PATH=$vulkanPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "Vulkan_INCLUDE_DIR=$vulkanPath\Include" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "Vulkan_LIBRARY=$vulkanPath\Lib\vulkan-1.lib" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
# Verify installation
Write-Host "Vulkan SDK path: $vulkanPath"
if (Test-Path "$vulkanPath\Lib") {
Write-Host "Lib directory exists"
} else {
Write-Host "Lib directory does not exist"
}
if (Test-Path "$vulkanPath\Include") {
Write-Host "Include directory exists"
} else {
Write-Host "Include directory does not exist"
}
deps-install: |
.\scripts\install_dependencies_windows.bat
echo "CMAKE_TOOLCHAIN_FILE=$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" >> $env:GITHUB_ENV
test-cmd: |
if (Test-Path "00_base_code/Release/00_base_code.exe") {
echo "00_base_code built successfully"
} else {
echo "00_base_code build failed"
exit 1
}
if (Test-Path "15_hello_triangle/Release/15_hello_triangle.exe") {
echo "15_hello_triangle built successfully"
} else {
echo "15_hello_triangle build failed"
exit 1
}
if (Test-Path "31_compute_shader/Release/31_compute_shader.exe") {
echo "31_compute_shader built successfully"
} else {
echo "31_compute_shader build failed"
exit 1
}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Cache vcpkg packages (Windows)
if: runner.os == 'Windows'
uses: actions/cache@v3
with:
path: |
${{ env.VCPKG_INSTALLATION_ROOT }}/installed
${{ env.VCPKG_INSTALLATION_ROOT }}/packages
${{ env.VCPKG_INSTALLATION_ROOT }}/buildtrees
${{ env.VCPKG_INSTALLATION_ROOT }}/downloads
key: ${{ runner.os }}-vcpkg-${{ hashFiles('scripts/install_dependencies_windows.bat', '**/CMakeLists.txt') }}-${{ hashFiles('**/*.cpp', '**/*.h') }}
restore-keys: |
${{ runner.os }}-vcpkg-${{ hashFiles('scripts/install_dependencies_windows.bat', '**/CMakeLists.txt') }}-
${{ runner.os }}-vcpkg-${{ hashFiles('scripts/install_dependencies_windows.bat') }}-
${{ runner.os }}-vcpkg-
- name: Cache Vulkan SDK (Windows)
if: runner.os == 'Windows'
uses: actions/cache@v3
with:
path: C:\VulkanSDK
key: ${{ runner.os }}-vulkan-sdk-${{ hashFiles('**/CMakeLists.txt', '**/*.cpp', '**/*.h') }}
restore-keys: |
${{ runner.os }}-vulkan-sdk-${{ hashFiles('**/CMakeLists.txt') }}-
${{ runner.os }}-vulkan-sdk-
- name: Cache apt packages (Ubuntu)
if: runner.os == 'Linux'
uses: actions/cache@v3
with:
path: /var/cache/apt/archives
key: ${{ runner.os }}-apt-${{ hashFiles('**/workflow.yml') }}
restore-keys: |
${{ runner.os }}-apt-
- name: Cache ccache files
uses: actions/cache@v3
with:
path: |
~/.ccache
~/.cache/sccache
key: ${{ runner.os }}-${{ matrix.ccache }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ matrix.ccache }}-
- name: Cache Vulkan SDK (Ubuntu)
if: runner.os == 'Linux'
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/vulkan-sdk
key: ${{ runner.os }}-vulkan-sdk-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('**/*.cpp') }}
restore-keys: |
${{ runner.os }}-vulkan-sdk-${{ hashFiles('**/CMakeLists.txt') }}-
${{ runner.os }}-vulkan-sdk-
- name: Install and configure ccache (Ubuntu)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y ccache clang clang-18
# Configure ccache for optimal performance
ccache --max-size=4G
ccache --set-config=compression=true
ccache --set-config=compression_level=9
ccache --set-config=sloppiness=file_macro,time_macros,include_file_mtime,include_file_ctime
ccache --set-config=hash_dir=false
ccache -z
echo "CCACHE_DIR=$HOME/.ccache" >> $GITHUB_ENV
echo "PATH=/usr/lib/ccache:$PATH" >> $GITHUB_ENV
# Set environment variables for better ccache performance
echo "CCACHE_COMPRESS=1" >> $GITHUB_ENV
echo "CCACHE_COMPRESSLEVEL=9" >> $GITHUB_ENV
echo "CCACHE_MAXSIZE=4G" >> $GITHUB_ENV
- name: Install and configure sccache (Windows)
if: runner.os == 'Windows'
run: |
# Download and extract sccache
Invoke-WebRequest -Uri "https://github.com/mozilla/sccache/releases/download/v0.5.4/sccache-v0.5.4-x86_64-pc-windows-msvc.tar.gz" -OutFile "sccache.tar.gz"
tar -xzf sccache.tar.gz
$sccachePath = Join-Path -Path (Get-Location) -ChildPath "sccache-v0.5.4-x86_64-pc-windows-msvc"
echo "$sccachePath" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
# Configure sccache for optimal performance
echo "SCCACHE_DIR=$HOME/.cache/sccache" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "SCCACHE_CACHE_SIZE=4G" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "SCCACHE_ERROR_LOG=$HOME/.cache/sccache/sccache.log" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "SCCACHE_LOG=info" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
# Create cache directory if it doesn't exist
New-Item -ItemType Directory -Force -Path "$HOME/.cache/sccache"
# Set environment variables for better sccache performance
echo "RUST_LOG=sccache=info" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Install dependencies
run: ${{ matrix.deps-install }}
- name: Install Vulkan SDK
run: ${{ matrix.vulkan-install }}
- name: Verify Vulkan Installation (Windows)
if: runner.os == 'Windows'
run: |
if (Test-Path $env:VULKAN_SDK) {
echo "Vulkan SDK found at: $env:VULKAN_SDK"
$criticalPaths = @(
"$env:VULKAN_SDK\Include",
"$env:VULKAN_SDK\Lib",
"$env:VULKAN_SDK\Bin",
"$env:VULKAN_SDK\Include\vulkan\vulkan.h",
"$env:VULKAN_SDK\Lib\vulkan-1.lib",
"$env:VULKAN_SDK\Bin\glslangValidator.exe"
)
$allPathsExist = $true
foreach ($path in $criticalPaths) {
if (Test-Path $path) {
echo "✓ Found: $path"
} else {
echo "✗ Missing: $path"
$allPathsExist = $false
}
}
if ($allPathsExist) {
echo "Vulkan SDK installation verified successfully"
} else {
echo "Vulkan SDK installation is incomplete!"
exit 1
}
} else {
echo "Vulkan SDK not found!"
exit 1
}
- name: Cache build artifacts (Windows)
if: runner.os == 'Windows'
uses: actions/cache@v3
with:
path: |
${{github.workspace}}/attachments/build
key: ${{ runner.os }}-build-msvc-${{ hashFiles('**/CMakeLists.txt', 'scripts/install_dependencies_windows.bat') }}-${{ hashFiles('**/*.cpp', '**/*.h', '**/*.hpp') }}
restore-keys: |
${{ runner.os }}-build-msvc-${{ hashFiles('**/CMakeLists.txt', 'scripts/install_dependencies_windows.bat') }}-
${{ runner.os }}-build-msvc-${{ hashFiles('**/CMakeLists.txt') }}-
${{ runner.os }}-build-msvc-
- name: Configure CMake with MSVC (Windows)
working-directory: ${{github.workspace}}/attachments
if: runner.os == 'Windows'
run: |
# Configure CMake with MSVC generator for faster builds
cmake -B build -DCMAKE_BUILD_TYPE=Release `
-DVulkan_INCLUDE_DIR="$env:Vulkan_INCLUDE_DIR" `
-DVulkan_LIBRARY="$env:Vulkan_LIBRARY" `
-DCMAKE_PREFIX_PATH="$env:VULKAN_SDK" `
-DCMAKE_TOOLCHAIN_FILE="$env:CMAKE_TOOLCHAIN_FILE" `
-DCMAKE_C_COMPILER_LAUNCHER=sccache `
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache `
-DCMAKE_CXX_FLAGS="/MP /EHsc /Zi /W3 /O2" `
-DCMAKE_SHARED_LINKER_FLAGS="/DEBUG:FASTLINK" `
-DCMAKE_EXE_LINKER_FLAGS="/DEBUG:FASTLINK"
if (Test-Path "build/CMakeCache.txt") {
Write-Host "CMake cache contents:"
Get-Content "build/CMakeCache.txt" | Select-String -Pattern "Vulkan"
}
- name: Verify Vulkan Installation (Ubuntu)
if: runner.os == 'Linux'
run: |
if [ -d "$VULKAN_SDK" ]; then
echo "Vulkan SDK found at: $VULKAN_SDK"
echo "Vulkan SDK installation verified"
else
echo "Vulkan SDK not found!"
exit 1
fi
- name: Cache build artifacts (Ubuntu)
if: runner.os == 'Linux'
uses: actions/cache@v3
with:
path: |
${{github.workspace}}/attachments/build
${{github.workspace}}/attachments/build/.ninja_deps
${{github.workspace}}/attachments/build/.ninja_log
key: ${{ runner.os }}-build-ninja-${{ hashFiles('**/CMakeLists.txt', 'scripts/install_dependencies_linux.sh') }}-${{ hashFiles('**/*.cpp', '**/*.h', '**/*.hpp') }}
restore-keys: |
${{ runner.os }}-build-ninja-${{ hashFiles('**/CMakeLists.txt', 'scripts/install_dependencies_linux.sh') }}-
${{ runner.os }}-build-ninja-${{ hashFiles('**/CMakeLists.txt') }}-
${{ runner.os }}-build-ninja-
- name: Configure CMake (Unix)
working-directory: ${{github.workspace}}/attachments
if: runner.os != 'Windows'
run: |
export CC="ccache clang"
export CXX="ccache clang++"
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_SCAN_FOR_MODULES=ON \
-DCMAKE_CXX_FLAGS="-std=c++20" \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
- name: Build with parallel jobs
working-directory: ${{github.workspace}}/attachments
run: cmake --build build --config Release --parallel 4
- name: ccache statistics
if: runner.os == 'Linux'
run: ccache -s
- name: sccache statistics
if: runner.os == 'Windows'
run: sccache -s
- name: Test Build Output
working-directory: ${{github.workspace}}/attachments/build
run: ${{ matrix.test-cmd }}
android-build:
name: Android Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache ccache files
uses: actions/cache@v3
with:
path: ~/.ccache
key: android-ccache-${{ hashFiles('attachments/android/app/src/main/cpp/CMakeLists.txt', 'attachments/34_android.cpp', 'attachments/35_gltf_ktx.cpp') }}
restore-keys: |
android-ccache-${{ hashFiles('attachments/android/app/src/main/cpp/CMakeLists.txt') }}
android-ccache-
- name: Cache KTX and tinygltf
uses: actions/cache@v3
with:
path: |
/usr/local/include/ktx
/usr/local/lib/libktx*
/usr/local/include/tinygltf
key: android-libs-${{ hashFiles('attachments/android/app/src/main/cpp/CMakeLists.txt') }}
restore-keys: |
android-libs-
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
${{github.workspace}}/attachments/android/.gradle
${{github.workspace}}/attachments/android/app/.cxx
${{github.workspace}}/attachments/android/app/build/intermediates
${{github.workspace}}/attachments/android/app/build/outputs
${{github.workspace}}/attachments/android/app/build/generated
key: ${{ runner.os }}-gradle-${{ hashFiles('attachments/android/app/src/main/cpp/CMakeLists.txt', 'attachments/34_android.cpp', 'attachments/35_gltf_ktx.cpp', 'attachments/android/app/build.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-${{ hashFiles('attachments/android/app/src/main/cpp/CMakeLists.txt') }}
${{ runner.os }}-gradle-
- name: Install and configure ccache
run: |
sudo apt-get update
sudo apt-get install -y ccache
# Configure ccache for optimal performance
ccache --max-size=4G
ccache --set-config=compression=true
ccache --set-config=compression_level=9
ccache --set-config=sloppiness=file_macro,time_macros,include_file_mtime,include_file_ctime
ccache --set-config=hash_dir=false
ccache -z
echo "CCACHE_DIR=$HOME/.ccache" >> $GITHUB_ENV
echo "PATH=/usr/lib/ccache:$PATH" >> $GITHUB_ENV
# Set environment variables for better ccache performance
echo "CCACHE_COMPRESS=1" >> $GITHUB_ENV
echo "CCACHE_COMPRESSLEVEL=9" >> $GITHUB_ENV
echo "CCACHE_MAXSIZE=4G" >> $GITHUB_ENV
- name: Set up Android SDK and NDK
run: |
echo "Using pre-installed Android SDK and NDK on GitHub runner"
echo "ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT" >> $GITHUB_ENV
echo "ANDROID_NDK_HOME=$ANDROID_NDK_ROOT" >> $GITHUB_ENV
echo "Android SDK location: $ANDROID_SDK_ROOT"
echo "Android NDK location: $ANDROID_NDK_ROOT"
# Install CMake 4.0.2 using sdkmanager
echo "Installing CMake 4.0.2 from Android SDK..."
yes | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --install "cmake;4.0.2"
echo "CMake installation completed"
- name: Install Vulkan SDK and glslangValidator
run: |
echo "Installing Vulkan SDK for Android build..."
# Check if glslangValidator is already installed from cache
if command -v glslangValidator &> /dev/null; then
echo "glslangValidator already installed:"
glslangValidator --version
else
# Install only glslang-tools instead of full Vulkan SDK
echo "Installing glslang-tools package..."
sudo apt-get update
sudo apt-get install -y glslang-tools
which glslangValidator
glslangValidator --version
fi
# Set minimal Vulkan environment variables needed for the build
echo "VULKAN_SDK=/usr" >> $GITHUB_ENV
echo "PATH=/usr/bin:$PATH" >> $GITHUB_ENV
- name: Install KTX library
run: |
if [ -d "/usr/local/include/ktx" ] && [ -f "/usr/local/lib/libktx.so" ]; then
echo "KTX library already installed from cache"
else
echo "Installing KTX library..."
git clone --depth 1 --branch v4.1.0 https://github.com/KhronosGroup/KTX-Software.git
cd KTX-Software
mkdir build && cd build
# Configure with minimal features and use ccache
cmake .. -DCMAKE_BUILD_TYPE=Release \
-DKTX_FEATURE_TOOLS=OFF \
-DKTX_FEATURE_DOC=OFF \
-DKTX_FEATURE_LOADTEST_APPS=OFF \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
# Build with parallel jobs
cmake --build . --config Release --parallel 4
sudo cmake --install .
cd ../..
fi
- name: Install tinygltf
run: |
if [ -d "/usr/local/include/tinygltf" ]; then
echo "tinygltf library already installed from cache"
else
echo "Installing tinygltf..."
git clone --depth 1 https://github.com/syoyo/tinygltf.git
cd tinygltf
mkdir build && cd build
# Configure with minimal features and use ccache
cmake .. -DCMAKE_BUILD_TYPE=Release \
-DTINYGLTF_BUILD_LOADER_EXAMPLE=OFF \
-DTINYGLTF_BUILD_GL_EXAMPLES=OFF \
-DTINYGLTF_BUILD_VALIDATOR_EXAMPLE=OFF \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
# Build with parallel jobs
cmake --build . --config Release --parallel 4
sudo cmake --install .
cd ../..
fi
- name: Build Android Chapters
working-directory: ${{github.workspace}}/attachments/android
run: |
if [ ! -f "gradlew" ]; then
echo "Generating Gradle wrapper..."
gradle wrapper
fi
SUPPORTED_CHAPTERS=$(grep -A 20 "set(SUPPORTED_CHAPTERS" app/src/main/cpp/CMakeLists.txt |
sed -n '/set(SUPPORTED_CHAPTERS/,/)/p' |
grep -o '"[^"]*"' |
sed 's/"//g')
readarray -t CHAPTERS <<< "$SUPPORTED_CHAPTERS"
echo "Detected supported Android chapters: ${CHAPTERS[@]}"
# Configure Gradle for optimal performance
echo "org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError" > gradle.properties
echo "org.gradle.parallel=true" >> gradle.properties
echo "org.gradle.caching=true" >> gradle.properties
echo "org.gradle.configureondemand=true" >> gradle.properties
# Enable AndroidX support (required for androidx.appcompat and other AndroidX dependencies)
echo "android.useAndroidX=true" >> gradle.properties
echo "android.enableJetifier=false" >> gradle.properties
echo "kotlin.incremental=true" >> gradle.properties
# Create directory for build outputs
mkdir -p build-outputs
# Build each chapter without cleaning between builds
for ((i=0; i<${#CHAPTERS[@]}; i++)); do
chapter="${CHAPTERS[$i]}"
if [ -n "$chapter" ]; then
echo "Building $chapter chapter..."
# Build with parallel execution and caching
./gradlew assembleDebug --parallel --max-workers=4 --build-cache -Pchapter=$chapter
if [ -f "app/build/outputs/apk/debug/app-debug.apk" ]; then
echo "$chapter built successfully"
# Rename the APK to avoid overwriting
cp app/build/outputs/apk/debug/app-debug.apk build-outputs/${chapter}.apk
else
echo "$chapter build failed"
exit 1
fi
fi
done
# Print ccache statistics after builds
ccache -s