Skip to content

Commit 0fed411

Browse files
committed
build: wire android stl headers and persist bazel cache
1 parent 05fd8e5 commit 0fed411

2 files changed

Lines changed: 34 additions & 9 deletions

File tree

.github/workflows/build-android-arm64.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,29 @@ jobs:
3838
"ndk;${ANDROID_NDK_VERSION}"
3939
4040
- name: Restore Bazel Repository Cache
41-
uses: actions/cache@v4
41+
id: restore_bazel_repository_cache
42+
uses: actions/cache/restore@v4
4243
with:
4344
path: ${{ github.workspace }}/.bazel-cache/repository
44-
key: ${{ runner.os }}-bazel-${{ env.ANDROID_PLATFORM }}-${{ env.TFJAVA_COMMIT }}-${{ hashFiles('scripts/patch_tfjava.py', '.github/workflows/build-android-arm64.yml') }}
45+
key: ${{ runner.os }}-bazel-${{ env.ANDROID_PLATFORM }}-${{ env.TFJAVA_COMMIT }}-${{ hashFiles('scripts/patch_tfjava.py') }}
4546
restore-keys: |
4647
${{ runner.os }}-bazel-${{ env.ANDROID_PLATFORM }}-${{ env.TFJAVA_COMMIT }}-
4748
${{ runner.os }}-bazel-${{ env.ANDROID_PLATFORM }}-
4849
4950
- name: Restore Bazel Disk Cache
50-
uses: actions/cache@v4
51+
id: restore_bazel_disk_cache
52+
uses: actions/cache/restore@v4
5153
with:
5254
path: ${{ github.workspace }}/.bazel-cache/disk
53-
key: ${{ runner.os }}-bazel-disk-${{ env.ANDROID_PLATFORM }}-${{ env.TFJAVA_COMMIT }}-${{ hashFiles('scripts/patch_tfjava.py', '.github/workflows/build-android-arm64.yml') }}
55+
key: ${{ runner.os }}-bazel-disk-${{ env.ANDROID_PLATFORM }}-${{ env.TFJAVA_COMMIT }}-${{ hashFiles('scripts/patch_tfjava.py') }}
5456
restore-keys: |
5557
${{ runner.os }}-bazel-disk-${{ env.ANDROID_PLATFORM }}-${{ env.TFJAVA_COMMIT }}-
5658
${{ runner.os }}-bazel-disk-${{ env.ANDROID_PLATFORM }}-
5759
5860
- name: Clone TensorFlow Java
5961
shell: bash
6062
run: |
61-
git clone https://github.com/tensorflow/java.git tfjava
63+
git clone --filter=blob:none --no-checkout https://github.com/tensorflow/java.git tfjava
6264
cd tfjava
6365
git checkout "${TFJAVA_COMMIT}"
6466
@@ -251,6 +253,20 @@ jobs:
251253
(cd "${GITHUB_WORKSPACE}/artifacts/output" && find . -type f -print0 | sort -z | xargs -0 sha256sum) > "${GITHUB_WORKSPACE}/artifacts/sha256.txt" || true
252254
fi
253255
256+
- name: Save Bazel Repository Cache
257+
if: always() && steps.restore_bazel_repository_cache.outputs.cache-hit != 'true'
258+
uses: actions/cache/save@v4
259+
with:
260+
path: ${{ github.workspace }}/.bazel-cache/repository
261+
key: ${{ runner.os }}-bazel-${{ env.ANDROID_PLATFORM }}-${{ env.TFJAVA_COMMIT }}-${{ hashFiles('scripts/patch_tfjava.py') }}
262+
263+
- name: Save Bazel Disk Cache
264+
if: always() && steps.restore_bazel_disk_cache.outputs.cache-hit != 'true'
265+
uses: actions/cache/save@v4
266+
with:
267+
path: ${{ github.workspace }}/.bazel-cache/disk
268+
key: ${{ runner.os }}-bazel-disk-${{ env.ANDROID_PLATFORM }}-${{ env.TFJAVA_COMMIT }}-${{ hashFiles('scripts/patch_tfjava.py') }}
269+
254270
- name: Upload Artifacts
255271
if: always()
256272
uses: actions/upload-artifact@v4

scripts/patch_tfjava.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,19 @@ def replace_once(text: str, old: str, new: str, path: Path) -> str:
1414
def patch_module_pom(path: Path) -> None:
1515
text = path.read_text(encoding="utf-8")
1616
if "<PLATFORM>${javacpp.platform}</PLATFORM>" in text:
17-
return
18-
old = "<EXTENSION>${javacpp.platform.extension}</EXTENSION>"
19-
new = """<EXTENSION>${javacpp.platform.extension}</EXTENSION>\n <PLATFORM>${javacpp.platform}</PLATFORM>"""
20-
text = replace_once(text, old, new, path)
17+
pass
18+
else:
19+
old = "<EXTENSION>${javacpp.platform.extension}</EXTENSION>"
20+
new = """<EXTENSION>${javacpp.platform.extension}</EXTENSION>\n <PLATFORM>${javacpp.platform}</PLATFORM>"""
21+
text = replace_once(text, old, new, path)
22+
if "${env.ANDROID_NDK_HOME}/sources/cxx-stl/gnu-libstdc++/4.9/include" not in text:
23+
old = """ <includePaths>\n <includePath>${project.basedir}/</includePath>\n <includePath>${project.basedir}/bazel-${project.artifactId}/external/org_tensorflow/</includePath>\n </includePaths>\n"""
24+
new = """ <includePaths>\n <includePath>${project.basedir}/</includePath>\n <includePath>${project.basedir}/bazel-${project.artifactId}/external/org_tensorflow/</includePath>\n <includePath>${env.ANDROID_NDK_HOME}/sources/cxx-stl/gnu-libstdc++/4.9/include</includePath>\n <includePath>${env.ANDROID_NDK_HOME}/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/include</includePath>\n </includePaths>\n"""
25+
text = replace_once(text, old, new, path)
26+
if "${env.ANDROID_NDK_HOME}/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a" not in text:
27+
old = """ <linkPaths>\n <linkPath>${project.basedir}/bazel-bin/external/org_tensorflow/tensorflow/</linkPath>\n </linkPaths>\n"""
28+
new = """ <linkPaths>\n <linkPath>${project.basedir}/bazel-bin/external/org_tensorflow/tensorflow/</linkPath>\n <linkPath>${env.ANDROID_NDK_HOME}/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a</linkPath>\n </linkPaths>\n"""
29+
text = replace_once(text, old, new, path)
2130
path.write_text(text, encoding="utf-8")
2231

2332

0 commit comments

Comments
 (0)