Skip to content

armgit / ente

Public Imported from GitHub
0

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

[ensu] Supply packaged ORT for native codegen

laurenspriem57f84086af26
diff --git a/.github/scripts/ensu-codegen.mjs b/.github/scripts/ensu-codegen.mjs
new file mode 100644
index 0000000000..65e96bebe5
--- /dev/null
+++ b/.github/scripts/ensu-codegen.mjs
@@ -0,0 +1,38 @@
+#!/usr/bin/env node
+
+import { execFileSync } from "node:child_process";
+import path from "node:path";
+import { fileURLToPath } from "node:url";
+
+const root = path.resolve(
+ path.dirname(fileURLToPath(import.meta.url)),
+ "../..",
+);
+execFileSync(process.execPath, [path.join(root, "desktop/scripts/ort.js")], {
+ cwd: root,
+ stdio: "inherit",
+});
+
+const runtime = path.join(
+ root,
+ "desktop/node_modules/.cache/ente-onnxruntime",
+ process.arch,
+);
+const loaderPath =
+ process.platform === "darwin"
+ ? "DYLD_LIBRARY_PATH"
+ : process.platform === "win32"
+ ? "PATH"
+ : "LD_LIBRARY_PATH";
+execFileSync("cargo", ["codegen", "native", "ensu"], {
+ cwd: path.join(root, "rust"),
+ stdio: "inherit",
+ env: {
+ ...process.env,
+ ORT_LIB_PATH: runtime,
+ ORT_PREFER_DYNAMIC_LINK: "1",
+ [loaderPath]: [runtime, process.env[loaderPath]]
+ .filter(Boolean)
+ .join(path.delimiter),
+ },
+});
diff --git a/.github/workflows/ensu-build.yml b/.github/workflows/ensu-build.yml
index fe18a1f17e..74ee64f08c 100644
--- a/.github/workflows/ensu-build.yml
+++ b/.github/workflows/ensu-build.yml
@@ -334,8 +334,14 @@ jobs:
sudo apt-get update
sudo apt-get install -y libvulkan-dev glslc spirv-headers
- - run: cargo codegen native
- working-directory: rust
+ - name: Setup Node.js
+ uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1
+ with:
+ node-version: 24
+
+ - name: Generate native bindings
+ run: node .github/scripts/ensu-codegen.mjs
+ working-directory: .
- name: Setup signing keys
env:
@@ -429,8 +435,14 @@ jobs:
with:
ref: ${{ needs.build-metadata.outputs.commit_sha }}
- - run: cargo codegen native
- working-directory: rust
+ - name: Setup Node.js
+ uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1
+ with:
+ node-version: 24
+
+ - name: Generate native bindings
+ run: node .github/scripts/ensu-codegen.mjs
+ working-directory: .
- name: Import Apple Distribution certificate
uses: Apple-Actions/import-codesign-certs@77ba2a2a8f5cfc8c405ebf3159f767c323e238f9 # v7.1.0
diff --git a/android/apps/ensu/README.md b/android/apps/ensu/README.md
index a15130b1c8..2fb461d220 100644
--- a/android/apps/ensu/README.md
+++ b/android/apps/ensu/README.md
@@ -6,27 +6,28 @@ To know more about Ente, see [our main README](../../../README.md) or visit [ent
## Building from source
-1. Install [Android Studio](https://developer.android.com/studio), [Rust](https://www.rust-lang.org/tools/install), and CMake (e.g. `brew install cmake`).
+1. Install [Android Studio](https://developer.android.com/studio), [Rust](https://www.rust-lang.org/tools/install), [Node.js 24](https://nodejs.org/), and CMake (e.g. `brew install cmake`).
2. Generate the Kotlin bindings:
- ```sh
- cd rust
- cargo codegen native
- ```
+ ```sh
+ node .github/scripts/ensu-codegen.mjs
+ ```
+
+ Run this from the repository root. The helper uses Photos' checksum-pinned Ente ONNX Runtime installer to supply the host library needed by the binding generator. Gradle uses the packaged Android AAR when cross-compiling the app.
3. Open `android/` in Android Studio and run Ensu's `app` module. If the Android NDK is missing, Android Studio will prompt to install it.
-That's it. Apart from the `cargo codegen`, this is a normal Android project. Gradle cross-compiles the Rust libraries to JNI `.so` files automatically when building the app.
+That's it. Apart from generating the bindings, this is a normal Android project. Gradle cross-compiles the Rust libraries to JNI `.so` files automatically when building the app.
> [!NOTE]
>
-> Re-run `cargo codegen native` whenever the UniFFI-exported surface under `rust/bindings/uniffi/` changes. Internal Rust changes (function bodies, private helpers) are picked up by the normal Gradle build.
+> Re-run the helper whenever the UniFFI-exported surface under `rust/bindings/uniffi/` changes. Internal Rust changes (function bodies, private helpers) are picked up by the normal Gradle build.
>
> From anywhere in the repo:
>
> ```sh
-> (cd "$(git rev-parse --show-toplevel)/rust" && cargo codegen native)
+> (cd "$(git rev-parse --show-toplevel)" && node .github/scripts/ensu-codegen.mjs)
> ```
## Terminal builds
diff --git a/apple/apps/ensu/README.md b/apple/apps/ensu/README.md
index 7b066e5617..208768715f 100644
--- a/apple/apps/ensu/README.md
+++ b/apple/apps/ensu/README.md
@@ -4,27 +4,28 @@ Source code for the Ensu iOS app.
## Building from source
-1. Install [Xcode](https://developer.apple.com/xcode/), [Rust](https://www.rust-lang.org/tools/install), and CMake (e.g. `brew install cmake`).
+1. Install [Xcode](https://developer.apple.com/xcode/), [Rust](https://www.rust-lang.org/tools/install), [Node.js 24](https://nodejs.org/), and CMake (e.g. `brew install cmake`).
2. Generate the Swift bindings:
- ```sh
- cd rust
- cargo codegen native
- ```
+ ```sh
+ node .github/scripts/ensu-codegen.mjs
+ ```
+
+ Run this from the repository root. The helper uses Photos' checksum-pinned Ente ONNX Runtime installer to supply the host library needed by the binding generator. Xcode links the packaged iOS XCFramework when building the app.
3. Open `Ensu.xcodeproj` in Xcode and run the `Ensu` scheme.
-That's it. Apart from the `cargo codegen`, this is a normal iOS project. Xcode compiles and statically links the Rust libraries automatically when building the app.
+That's it. Apart from generating the bindings, this is a normal iOS project. Xcode compiles and statically links the Rust libraries automatically when building the app.
> [!NOTE]
>
-> Re-run `cargo codegen native` whenever the UniFFI-exported surface under `rust/bindings/uniffi/` changes. Internal Rust changes (function bodies, private helpers) are picked up by the normal Xcode build.
+> Re-run the helper whenever the UniFFI-exported surface under `rust/bindings/uniffi/` changes. Internal Rust changes (function bodies, private helpers) are picked up by the normal Xcode build.
>
> From anywhere in the repo:
>
> ```sh
-> (cd "$(git rev-parse --show-toplevel)/rust" && cargo codegen native)
+> (cd "$(git rev-parse --show-toplevel)" && node .github/scripts/ensu-codegen.mjs)
> ```
## Terminal builds