Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Define the custom ONNX Runtime release once in version.properties

laurenspriem6a74a6aba680
diff --git a/mobile/apps/photos/android/app/build.gradle b/mobile/apps/photos/android/app/build.gradle
index 97f2870075..d544b4c245 100644
--- a/mobile/apps/photos/android/app/build.gradle
+++ b/mobile/apps/photos/android/app/build.gradle
@@ -29,14 +29,20 @@ if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
+// The pinned custom ONNX Runtime release is defined once in
+// mobile/native/onnxruntime/version.properties.
+def onnxRuntimeVersionFile = file('../../../../native/onnxruntime/version.properties')
+def onnxRuntimeVersions = new Properties()
+onnxRuntimeVersionFile.withInputStream { onnxRuntimeVersions.load(it) }
def onnxRuntimeAar = new File(
gradle.gradleUserHomeDir,
- 'caches/io.ente/onnxruntime/ort-1.27.0-webgpu-pilot.5/' +
- 'onnxruntime-webgpu-android-1.27.0-pilot.5.aar',
+ "caches/io.ente/onnxruntime/${onnxRuntimeVersions.getProperty('ortRelease')}/" +
+ onnxRuntimeVersions.getProperty('ortAndroidAsset'),
)
def prepareOnnxRuntimeAndroid = tasks.register('prepareOnnxRuntimeAndroid', Exec) {
def prepareScript = file('../../../../native/onnxruntime/prepare-android.sh')
inputs.file(prepareScript)
+ inputs.file(onnxRuntimeVersionFile)
outputs.file(onnxRuntimeAar)
outputs.upToDateWhen { false }
commandLine 'sh', prepareScript, onnxRuntimeAar
diff --git a/mobile/native/android/apps/ensu/rust/build.gradle.kts b/mobile/native/android/apps/ensu/rust/build.gradle.kts
index 5dedcd44a6..49dde44449 100644
--- a/mobile/native/android/apps/ensu/rust/build.gradle.kts
+++ b/mobile/native/android/apps/ensu/rust/build.gradle.kts
@@ -1,4 +1,5 @@
import java.io.ByteArrayOutputStream
+import java.util.Properties
plugins {
id("com.android.library")
@@ -9,13 +10,20 @@ val knownAbis = listOf("arm64-v8a", "armeabi-v7a", "x86_64")
val debugJniLibsDir = layout.buildDirectory.dir("generated/jniLibs/debug")
val releaseJniLibsDir = layout.buildDirectory.dir("generated/jniLibs/release")
+// The pinned custom ONNX Runtime release is defined once in
+// mobile/native/onnxruntime/version.properties.
+val onnxRuntimeVersionFile = file("../../../../onnxruntime/version.properties")
+val onnxRuntimeVersions = Properties().apply {
+ onnxRuntimeVersionFile.inputStream().use { load(it) }
+}
val onnxRuntimeAar = gradle.gradleUserHomeDir.resolve(
- "caches/io.ente/onnxruntime/ort-1.27.0-webgpu-pilot.5/" +
- "onnxruntime-webgpu-android-1.27.0-pilot.5.aar",
+ "caches/io.ente/onnxruntime/${onnxRuntimeVersions.getProperty("ortRelease")}/" +
+ onnxRuntimeVersions.getProperty("ortAndroidAsset"),
)
val prepareOnnxRuntimeAndroid = tasks.register<Exec>("prepareOnnxRuntimeAndroid") {
val prepareScript = file("../../../../onnxruntime/prepare-android.sh")
inputs.file(prepareScript)
+ inputs.file(onnxRuntimeVersionFile)
outputs.file(onnxRuntimeAar)
outputs.upToDateWhen { false }
commandLine("sh", prepareScript, onnxRuntimeAar)
diff --git a/mobile/native/onnxruntime/README.md b/mobile/native/onnxruntime/README.md
index bac5381e23..51f4d955bb 100644
--- a/mobile/native/onnxruntime/README.md
+++ b/mobile/native/onnxruntime/README.md
@@ -2,13 +2,40 @@
The mobile apps use Ente's pinned custom ONNX Runtime 1.27.0 packaging build:
-- Release: `ort-1.27.0-webgpu-pilot.5`
- Android: WebGPU, XNNPACK, and CPU; ARM64, ARMv7, and x86_64
- iOS: CoreML and CPU; iOS 15.1+ device and ARM64 Simulator
+The release tag, asset names, and SHA-256 digests are defined once in
+`version.properties`; the prepare scripts and the Android Gradle builds all
+read from it. To bump the release, update only that file.
+
Android's AAR is downloaded by `prepare-android.sh` into the Gradle user cache.
iOS's XCFramework ZIP is downloaded by `prepare-ios.sh`; the selected static
-archive slice is then bundled by the Rust build. Both downloads are pinned to
-the SHA-256 digests published with the release.
+archive slice is then bundled by the Rust build. Both downloads are verified
+against the SHA-256 digests published with the release.
Desktop ONNX Runtime packaging is intentionally unchanged.
+
+## WebGPU rollout status
+
+On Android, the WebGPU execution provider is opt-in at runtime
+(`set_ml_execution_config` in the Rust ML bindings; the photos app currently
+enables it for internal users only) and is additionally restricted to
+Android 12+ (SDK 31). All other devices use the XNNPACK/CPU chain.
+
+## Building the Rust photos crate for iOS outside Xcode
+
+The iOS `ort` dependency no longer downloads prebuilt binaries; the Cargokit
+build exports `ORT_LIB_PATH` pointing at the custom static archive. For direct
+`cargo` invocations against an iOS target (for example `cargo check`), export
+it manually:
+
+```sh
+ORT_LIB_PATH="$(sh mobile/native/onnxruntime/prepare-ios.sh \
+ "$HOME/Library/Caches/io.ente/onnxruntime" iphoneos)" \
+IPHONEOS_DEPLOYMENT_TARGET=15.1 \
+cargo check -p ente-photos --target aarch64-apple-ios
+```
+
+Use `iphonesimulator` and `--target aarch64-apple-ios-sim` for the Simulator.
+The deployment target must be at least 15.1 to match the archive.
diff --git a/mobile/native/onnxruntime/prepare-android.sh b/mobile/native/onnxruntime/prepare-android.sh
index da60c77962..de8daef4e9 100755
--- a/mobile/native/onnxruntime/prepare-android.sh
+++ b/mobile/native/onnxruntime/prepare-android.sh
@@ -1,9 +1,22 @@
#!/bin/sh
set -eu
-asset_name="onnxruntime-webgpu-android-1.27.0-pilot.5.aar"
-asset_url="https://github.com/laurens-pilot/ort-packaging/releases/download/ort-1.27.0-webgpu-pilot.5/$asset_name"
-expected_sha256="f40ef31bb6ff8399c556872bcad272bddb650b0845f3026c56a065de9b1ec579"
+script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
+properties_file="$script_dir/version.properties"
+
+read_property() {
+ sed -n "s/^$1=//p" "$properties_file" | head -n 1
+}
+
+base_url=$(read_property ortReleaseBaseUrl)
+release=$(read_property ortRelease)
+asset_name=$(read_property ortAndroidAsset)
+expected_sha256=$(read_property ortAndroidSha256)
+if [ -z "$base_url" ] || [ -z "$release" ] || [ -z "$asset_name" ] || [ -z "$expected_sha256" ]; then
+ echo "Failed to read the ONNX Runtime release from $properties_file" >&2
+ exit 1
+fi
+asset_url="$base_url/$release/$asset_name"
destination=${1:?"usage: prepare-android.sh <destination.aar>"}
diff --git a/mobile/native/onnxruntime/prepare-ios.sh b/mobile/native/onnxruntime/prepare-ios.sh
index 1fa84bf78e..c51674b411 100755
--- a/mobile/native/onnxruntime/prepare-ios.sh
+++ b/mobile/native/onnxruntime/prepare-ios.sh
@@ -1,9 +1,22 @@
#!/bin/sh
set -eu
-asset_name="onnxruntime-coreml-ios-1.27.0-pilot.5.zip"
-asset_url="https://github.com/laurens-pilot/ort-packaging/releases/download/ort-1.27.0-webgpu-pilot.5/$asset_name"
-expected_sha256="fc820547f8e328ed501112be06b23d26329676d4e6a78978fc64971f8f05555d"
+script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
+properties_file="$script_dir/version.properties"
+
+read_property() {
+ sed -n "s/^$1=//p" "$properties_file" | head -n 1
+}
+
+base_url=$(read_property ortReleaseBaseUrl)
+release=$(read_property ortRelease)
+asset_name=$(read_property ortIosAsset)
+expected_sha256=$(read_property ortIosSha256)
+if [ -z "$base_url" ] || [ -z "$release" ] || [ -z "$asset_name" ] || [ -z "$expected_sha256" ]; then
+ echo "Failed to read the ONNX Runtime release from $properties_file" >&2
+ exit 1
+fi
+asset_url="$base_url/$release/$asset_name"
cache_root=${1:?"usage: prepare-ios.sh <cache-root> <iphoneos|iphonesimulator>"}
platform=${2:?"usage: prepare-ios.sh <cache-root> <iphoneos|iphonesimulator>"}
@@ -32,7 +45,7 @@ sha256_file() {
fi
}
-asset_cache="$cache_root/ort-1.27.0-webgpu-pilot.5"
+asset_cache="$cache_root/$release"
archive="$asset_cache/$asset_name"
extract_root="$asset_cache/$expected_sha256"
verified_marker="$extract_root/.verified"
diff --git a/mobile/native/onnxruntime/version.properties b/mobile/native/onnxruntime/version.properties
new file mode 100644
index 0000000000..3265337daf
--- /dev/null
+++ b/mobile/native/onnxruntime/version.properties
@@ -0,0 +1,12 @@
+# Single source of truth for Ente's pinned custom ONNX Runtime packaging
+# release. Read by prepare-android.sh and prepare-ios.sh, and by the Android
+# Gradle builds that locate the downloaded AAR in the Gradle user cache.
+#
+# When bumping the release, update every value below; the prepare scripts
+# verify the SHA-256 digests published with the release.
+ortReleaseBaseUrl=https://github.com/laurens-pilot/ort-packaging/releases/download
+ortRelease=ort-1.27.0-webgpu-pilot.5
+ortAndroidAsset=onnxruntime-webgpu-android-1.27.0-pilot.5.aar
+ortAndroidSha256=f40ef31bb6ff8399c556872bcad272bddb650b0845f3026c56a065de9b1ec579
+ortIosAsset=onnxruntime-coreml-ios-1.27.0-pilot.5.zip
+ortIosSha256=fc820547f8e328ed501112be06b23d26329676d4e6a78978fc64971f8f05555d