Skip to content

Commit 220dae2

Browse files
committed
Add configuration for jitpack.
Jitpack is a pseudo-repository for Android (and other) artifacts that builds AARs from GitHub repos for projects that do not themselves publish their artifacts to somewhere like Maven Central. Adding this allows Android app developers to add a dependency on com.github.khronos:vulkan-validationlayers:$TAG to their build.gradle file rather than needing to manage the VVL libraries themselves. See the comment at the top of jitpack.yml for more information. Fixes #8167
1 parent 31118fe commit 220dae2

File tree

4 files changed

+294
-41
lines changed

4 files changed

+294
-41
lines changed

.github/workflows/sdk_android_build.yml

Lines changed: 103 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ name: SDK Android Build
1919
# artifacts to the release when a Vulkan SDK tag is pushed. The
2020
# Vulkan SDK does not include binaries for Android, so we publish
2121
# them here to provide Android binaries built from the same source
22-
# used to build the Vulkan SDK.
22+
# used to build the Vulkan SDK. The artifacts will also be bundled into an AAR
23+
# (the library counterpart the APK application format) and uploaded to GitHub
24+
# Packages so app developers can include the validation layers in their
25+
# application the same way they would any Java dependencies.
2326
#
2427
# The tag needs to be pushed by name, as `git push --tags` to push all
2528
# tags does not appear to trigger the action.
@@ -48,7 +51,23 @@ on:
4851
tags:
4952
- vulkan-sdk-*
5053

54+
env:
55+
MIN_SDK_VERSION: 26
56+
ARTIFACT_ID: vulkan-validation-layers
57+
5158
jobs:
59+
sdk-version:
60+
name: Get SDK version
61+
runs-on: ubuntu-22.04
62+
outputs:
63+
sdk_version: ${{ steps.get_sdk_version.outputs.sdk_version}}
64+
steps:
65+
- name: Get sdk version string
66+
id: get_sdk_version
67+
run: |
68+
sdk_version=`echo "${{ github.ref }}" | cut -d "-" -f 3`
69+
echo "sdk_version=$sdk_version" >> $GITHUB_OUTPUT
70+
5271
android:
5372
name: Android SDK Release
5473
runs-on: ubuntu-22.04
@@ -63,36 +82,105 @@ jobs:
6382
with:
6483
python-version: '3.10'
6584
- name: CMake Build
66-
run: python scripts/android.py --config Release --app-abi ${{ matrix.abi }} --app-stl c++_static
85+
run: python scripts/android.py --config Release --app-abi ${{ matrix.abi }} --app-stl c++_static --min-sdk-version $MIN_SDK_VERSION
6786
- name: Upload artifacts
6887
uses: actions/upload-artifact@v4
6988
with:
7089
name: vvl-android-${{ matrix.abi }}
7190
path: ./build-android/libs/lib/
7291

92+
aar:
93+
name: Create AAR
94+
runs-on: ubuntu-22.04
95+
needs: [android, sdk-version]
96+
steps:
97+
- name: Clone repository
98+
uses: actions/checkout@v4
99+
- uses: actions/setup-python@v5
100+
with:
101+
python-version: '3.10'
102+
- name: Download artifacts
103+
uses: actions/download-artifact@v4
104+
with:
105+
path: ./libs
106+
merge-multiple: true
107+
pattern: vvl-android-*
108+
- name: Assemble AAR
109+
# GROUP_ID must be configured as a repoistory variable in Settings ->
110+
# Actions -> Variables.
111+
run: |
112+
python scripts/aar.py \
113+
--group-id ${{ vars.GROUP_ID }} \
114+
--artifact-id ${{ env.ARTIFACT_ID }} \
115+
--min-sdk-version $MIN_SDK_VERSION \
116+
-o vulkan-validation-layers-${{ needs.sdk-version.outputs.sdk_version }}.aar \
117+
libs
118+
- name: Upload AAR
119+
uses: actions/upload-artifact@v4
120+
with:
121+
name: vulkan-validation-layers-aar
122+
path: vulkan-validation-layers-${{ needs.sdk-version.outputs.sdk_version }}.aar
123+
if-no-files-found: error
124+
125+
maven:
126+
name: Push AAR to GitHub Packages
127+
runs-on: ubuntu-22.04
128+
needs: [aar, sdk-version]
129+
steps:
130+
- name: Set up Java
131+
uses: actions/setup-java@v4
132+
with:
133+
# Neither are really important. We need the mvn tool, but we aren't
134+
# going to use it to build anything.
135+
distribution: "temurin"
136+
java-version: "21"
137+
- name: Download artifacts
138+
uses: actions/download-artifact@v4
139+
with:
140+
path: aar
141+
name: vulkan-validation-layers-aar
142+
- name: Publish
143+
# Useful docs for this section:
144+
# https://maven.apache.org/guides/mini/guide-3rd-party-jars-remote.html
145+
# https://docs.github.com/en/actions/publishing-packages/publishing-java-packages-with-maven
146+
run: |
147+
mvn --batch-mode deploy:deploy-file \
148+
-DgroupId=${{ vars.GROUP_ID }} \
149+
-DartifactId=$ARTIFACT_ID \
150+
-Dversion=${{ needs.sdk-version.outputs.sdk_version }} \
151+
-Dpackaging=aar \
152+
-DrepositoryId=github \
153+
-Durl=https://maven.pkg.github.com/${{ github.repository }} \
154+
-Dfile=aar/vulkan-validation-layers-${{ needs.sdk-version.outputs.sdk_version }}.aar
155+
env:
156+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
157+
73158
release:
74159
name: Create Release for Tag
75160
permissions: write-all
76161
runs-on: ubuntu-22.04
77-
needs: android
162+
needs: [android, sdk-version]
78163
steps:
79-
- name: Get sdk version string
80-
id: get_sdk_version
81-
run: |
82-
sdk_version=`echo "${{ github.ref }}" | cut -d "-" -f 3`
83-
echo "sdk_version=$sdk_version" >> $GITHUB_OUTPUT
84164
- name: Create release
85165
id: create_release
86166
uses: actions/create-release@v1
87167
env:
88168
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89169
with:
90170
tag_name: ${{ github.ref }}
91-
release_name: Android binaries for ${{ steps.get_sdk_version.outputs.sdk_version }} SDK release
171+
release_name: Android binaries for ${{ needs.sdk-version.outputs.sdk_version }} SDK release
92172
body: |
93173
These Android Validation Layer binaries were built with ndk version 25.2.9519653
94174
95-
The validation binaries can only be used with a device that supports Android API version 26 or higher.
175+
The validation binaries can only be used with a device that supports Android API version ${{ env.MIN_SDK_VERSION }} or higher.
176+
177+
If you're using Android Gradle to build your app, it will be easier
178+
to use the validation layers direcetly from the GitHub Package
179+
Repository: ${{ github.repositoryUrl }}/packages/. See
180+
https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry#using-a-published-package
181+
for instructions on using packages from this repository. To include
182+
the validation layers only in your debug APK (recommended), use
183+
`debugImplementation` rather than `implementation` as the docs say.
96184
draft: false
97185
prerelease: false
98186
- name: Get release URL
@@ -107,7 +195,7 @@ jobs:
107195
publish:
108196
runs-on: ubuntu-22.04
109197
permissions: write-all
110-
needs: release
198+
needs: [release, sdk-version]
111199
strategy:
112200
fail-fast: false
113201
matrix:
@@ -123,20 +211,15 @@ jobs:
123211
suffix: "zip"
124212
type: "application/zip"
125213
steps:
126-
- name: Get sdk version string
127-
id: get_sdk_version
128-
run: |
129-
sdk_version=`echo "${{ github.ref }}" | cut -d "-" -f 3`
130-
echo "sdk_version=$sdk_version" >> $GITHUB_OUTPUT
131214
- name: Download artifacts
132215
uses: actions/download-artifact@v4
133216
with:
134-
path: ./android-binaries-${{ steps.get_sdk_version.outputs.sdk_version }}
217+
path: ./android-binaries-${{ needs.sdk-version.outputs.sdk_version }}
135218
merge-multiple: true
136219
pattern: ${{ matrix.config.artifact }}-*
137220
- name: Make release artifacts
138221
run: |
139-
${{ matrix.config.command }} android-binaries-${{ steps.get_sdk_version.outputs.sdk_version }}.${{ matrix.config.suffix }} android-binaries-${{ steps.get_sdk_version.outputs.sdk_version }}
222+
${{ matrix.config.command }} android-binaries-${{ needs.sdk-version.outputs.sdk_version }}.${{ matrix.config.suffix }} android-binaries-${{ needs.sdk-version.outputs.sdk_version }}
140223
- name: Download release URL
141224
uses: actions/download-artifact@v4
142225
with:
@@ -153,6 +236,6 @@ jobs:
153236
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
154237
with:
155238
upload_url: ${{ steps.set_upload_url.outputs.upload_url }}
156-
asset_name: android-binaries-${{ steps.get_sdk_version.outputs.sdk_version }}.${{ matrix.config.suffix }}
157-
asset_path: ./android-binaries-${{ steps.get_sdk_version.outputs.sdk_version }}.${{ matrix.config.suffix }}
239+
asset_name: android-binaries-${{ needs.sdk-version.outputs.sdk_version }}.${{ matrix.config.suffix }}
240+
asset_path: ./android-binaries-${{ needs.sdk-version.outputs.sdk_version }}.${{ matrix.config.suffix }}
158241
asset_content_type: ${{ matrix.config.type }}

jitpack.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file enables jitpack.io to build this repository into an AAR (Android
2+
# Archive) for easier consumption by app developers. Instead of needing to
3+
# download the VVL release artifacts from GitHub and check those libraries into
4+
# their repository, they can instead depend on
5+
# com.github.khronos:vulkan-validationlayers:$TAG. Jitpack will build the
6+
# repository into an AAR and serve that artifact to developers.
7+
#
8+
# One caveat: if the VVL build is not completely deterministic (unlikely), the
9+
# artifacts served from jitpack will not exactly match those hosted on the
10+
# GitHub Release page, since jitpack will build the artifacts rather than serve
11+
# the ones from the release.
12+
#
13+
# https://jitpack.io/docs/BUILDING/
14+
# https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/8167
15+
# https://github.com/KhronosGroup/Vulkan-ValidationLayers/pull/8303
16+
install:
17+
- python scripts/jitpack.py

scripts/android.py

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import argparse
2424
import os
25+
from pathlib import Path
2526
import sys
2627
import shutil
2728
import common_ci
@@ -77,23 +78,14 @@ def generate_apk(SDK_ROOT : str, CMAKE_INSTALL_DIR : str) -> str:
7778
# https://en.wikipedia.org/wiki/Apk_(file_format)#Package_contents
7879
#
7980
# As a result CMake will need to be run multiple times to create a complete test APK that can be run on any Android device.
80-
def main():
81-
configs = ['Release', 'Debug', 'MinSizeRel']
82-
83-
parser = argparse.ArgumentParser()
84-
parser.add_argument('--config', type=str, choices=configs, default=configs[0])
85-
parser.add_argument('--app-abi', dest='android_abi', type=str, default="arm64-v8a")
86-
parser.add_argument('--app-stl', dest='android_stl', type=str, choices=["c++_static", "c++_shared"], default="c++_static")
87-
parser.add_argument('--apk', action='store_true', help='Generate an APK as a post build step.')
88-
parser.add_argument('--clean', action='store_true', help='Cleans CMake build artifacts')
89-
args = parser.parse_args()
90-
91-
cmake_config = args.config
92-
android_abis = args.android_abi.split(" ")
93-
android_stl = args.android_stl
94-
create_apk = args.apk
95-
clean = args.clean
96-
81+
def build(
82+
cmake_config: str,
83+
abis: list[str],
84+
min_sdk_version: int,
85+
stl: str,
86+
create_apk: bool = False,
87+
clean: bool = False,
88+
) -> Path:
9789
if "ANDROID_NDK_HOME" not in os.environ:
9890
print("Cannot find ANDROID_NDK_HOME!")
9991
sys.exit(1)
@@ -115,7 +107,7 @@ def main():
115107
required_cli_tools += ['aapt', 'zipalign', 'keytool', 'apksigner']
116108

117109
print(f"ANDROID_NDK_HOME = {android_ndk_home}")
118-
print(f"Build configured for {cmake_config} | {android_stl} | {android_abis} | APK {create_apk}")
110+
print(f"Build configured for {cmake_config} | {stl} | {abis} | APK {create_apk}")
119111

120112
if not os.path.isfile(android_toolchain):
121113
print(f'Unable to find android.toolchain.cmake at {android_toolchain}')
@@ -136,7 +128,7 @@ def main():
136128
print("Cleaning CMake install")
137129
shutil.rmtree(cmake_install_dir)
138130

139-
for abi in android_abis:
131+
for abi in abis:
140132
build_dir = common_ci.RepoRelative(f'build-android/cmake/{abi}')
141133
lib_dir = f'lib/{abi}'
142134

@@ -157,9 +149,9 @@ def main():
157149
cmake_cmd += f' -D CMAKE_ANDROID_ARCH_ABI={abi}'
158150
cmake_cmd += f' -D CMAKE_INSTALL_LIBDIR={lib_dir}'
159151
cmake_cmd += f' -D BUILD_TESTS={create_apk}'
160-
cmake_cmd += f' -D CMAKE_ANDROID_STL_TYPE={android_stl}'
152+
cmake_cmd += f' -D CMAKE_ANDROID_STL_TYPE={stl}'
161153

162-
cmake_cmd += ' -D ANDROID_PLATFORM=26'
154+
cmake_cmd += f' -D ANDROID_PLATFORM={min_sdk_version}'
163155
cmake_cmd += ' -D ANDROID_USE_LEGACY_TOOLCHAIN_FILE=NO'
164156

165157
common_ci.RunShellCmd(cmake_cmd)
@@ -175,5 +167,30 @@ def main():
175167
if create_apk:
176168
generate_apk(SDK_ROOT = android_sdk_root, CMAKE_INSTALL_DIR = cmake_install_dir)
177169

170+
return Path(cmake_install_dir)
171+
172+
173+
def main() -> None:
174+
175+
configs = ['Release', 'Debug', 'MinSizeRel']
176+
177+
parser = argparse.ArgumentParser()
178+
parser.add_argument('--config', type=str, choices=configs, default=configs[0])
179+
parser.add_argument('--app-abi', dest='android_abi', type=str, default="arm64-v8a")
180+
parser.add_argument('--min-sdk-version', type=int, default=26, help='The minSdkVersion of the built artifacts')
181+
parser.add_argument('--app-stl', dest='android_stl', type=str, choices=["c++_static", "c++_shared"], default="c++_static")
182+
parser.add_argument('--apk', action='store_true', help='Generate an APK as a post build step.')
183+
parser.add_argument('--clean', action='store_true', help='Cleans CMake build artifacts')
184+
args = parser.parse_args()
185+
186+
build(
187+
args.config,
188+
args.android_abi.split(" "),
189+
args.min_sdk_version,
190+
args.android_sdk,
191+
args.apk,
192+
args.clean,
193+
)
194+
178195
if __name__ == '__main__':
179196
main()

0 commit comments

Comments
 (0)