Skip to content

armgit / ente

Public Imported from GitHub
0

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

update

Manav Rathid2d1e5a2bc2c
diff --git a/rust/README.md b/rust/README.md
index af589b21c5..f5d744a423 100644
--- a/rust/README.md
+++ b/rust/README.md
@@ -14,18 +14,28 @@
β”‚ β”‚ β”‚
β–Ό β–Ό β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
-β”‚ mobile/apps/photos/rust/ β”‚ β”‚ web/packages/ente-wasm/ β”‚ β”‚ rust/cli/ β”‚
-β”‚ β”‚ β”‚ (ente-wasm crate) β”‚ β”‚ β”‚
-β”‚ Depends on ente-core β”‚ β”‚ β”‚ β”‚ (future: when CLI β”‚
-β”‚ #[frb] wrappers inline β”‚ β”‚ Rust crate + wasm-pack β”‚ β”‚ uses ente-core) β”‚
-β”‚ + app-specific (usearch) β”‚ β”‚ #[wasm_bindgen] wrappers β”‚ β”‚ β”‚
+β”‚ mobile/packages/rust/ β”‚ β”‚ web/packages/wasm/ β”‚ β”‚ rust/cli/ β”‚
+β”‚ (ente-rust crate) β”‚ β”‚ (ente-wasm crate) β”‚ β”‚ β”‚
+β”‚ β”‚ β”‚ β”‚ β”‚ (future: when CLI β”‚
+β”‚ Shared #[frb] wrappers β”‚ β”‚ #[wasm_bindgen] wrappers β”‚ β”‚ uses ente-core) β”‚
+β”‚ for all mobile apps β”‚ β”‚ for all web apps β”‚ β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
- β”‚ β”‚
- β–Ό β–Ό
-β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
-β”‚ Flutter Photos App β”‚ β”‚ Web Apps β”‚
-β”‚ β”‚ β”‚ (Photos, Auth, etc.) β”‚
-β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
+ β”‚ β”‚ β”‚
+ β”‚ └──────────────┐ β”‚
+ β–Ό β–Ό β–Ό
+β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
+β”‚ Photos App β”‚ β”‚ Other apps β”‚ β”‚ Web Apps β”‚
+β”‚ β”‚ β”‚ (Auth ...) β”‚ β”‚ (Photos, Auth, etc.) β”‚
+β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
+ β–²
+ β”‚
+β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
+β”‚ mobile/apps/photos/rust/ β”‚
+β”‚ (ente-photos-rust crate) β”‚
+β”‚ β”‚
+β”‚ App-specific #[frb]: β”‚
+β”‚ usearch, ML, etc. β”‚
+β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```
## Directory Structure
@@ -42,26 +52,35 @@ rust/
β”‚ └── urls.rs
└── Cargo.toml # crate name: ente-core
-web/packages/ente-wasm/ # WASM bindings (lives in web workspace)
+web/packages/wasm/ # WASM bindings (lives in web workspace)
β”œβ”€β”€ src/
β”‚ └── lib.rs # #[wasm_bindgen] wrappers around ente-core
β”œβ”€β”€ Cargo.toml # crate name: ente-wasm
β”œβ”€β”€ package.json # includes wasm-pack as devDependency
└── pkg/ # generated output (gitignored)
-mobile/apps/photos/rust/ # FRB bindings (lives in mobile app)
+mobile/packages/rust/ # Shared FRB bindings for all mobile apps
+β”œβ”€β”€ rust/
+β”‚ β”œβ”€β”€ src/
+β”‚ β”‚ └── api/ # #[frb] wrappers around ente-core
+β”‚ └── Cargo.toml # crate name: ente-rust
+β”œβ”€β”€ lib/ # Generated Dart bindings
+└── pubspec.yaml # Flutter plugin package
+
+mobile/apps/photos/rust/ # Photos app-specific FRB bindings
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ lib.rs
-β”‚ └── api/ # #[frb] wrappers around ente-core
+β”‚ └── api/ # #[frb] app-specific code (usearch, ML)
β”‚ └── *.rs
-└── Cargo.toml # crate name: rust_lib_photos
+└── Cargo.toml # crate name: ente-photos-rust
```
**Crates:**
- `ente-core` - shared business logic (pure Rust, no FFI)
- `ente-wasm` - wasm-bindgen wrappers for web
-- `rust_lib_photos` - FRB wrappers for mobile
+- `ente-rust` - shared FRB wrappers for mobile (Dart class: `EnteRust`)
+- `ente-photos-rust` - Photos app-specific FRB (Dart class: `EntePhotosRust`)
## Tooling
@@ -87,9 +106,12 @@ wasm-pack is installed via npm as a devDependency, so `yarn install` handles it.
### [Flutter Rust Bridge (FRB)](https://github.com/fzyzcjy/flutter_rust_bridge)
-Used for Flutter integration. FRB wrappers (annotated with `#[frb]`) live in `mobile/apps/photos/rust/` and depend on `ente-core`.
+Used for Flutter integration. FRB is used on two crates:
+
+- **`ente-rust`** (`mobile/packages/rust/`) - Shared wrappers around `ente-core`, used by multiple mobile apps (Photos, Auth, etc.)
+- **`ente-photos-rust`** (`mobile/apps/photos/rust/`) - Photos app-specific functionality (usearch, ML)
-Currently, App-specific functionality (usearch, ML) stays alongside in the same crate. In the future, if another one of Ente's Flutter apps needs the same wrappers, we can extract a shared crate.
+Both depend on `ente-core` and use `#[frb]` annotations to generate Dart bindings.
## Development
@@ -127,25 +149,21 @@ yarn build:wasm # builds the WASM package
> cargo watch -w ../rust/core -w packages/wasm/src -s "yarn build:wasm"
> ```
-**rust_lib_photos (mobile/apps/photos/rust/):**
-
-One time:
+**ente-rust (mobile/packages/rust/):**
```sh
cargo install flutter_rust_bridge_codegen
-```
-
-From `mobile/apps/photos`:
-
-```sh
-flutter pub get
flutter_rust_bridge_codegen generate
+flutter test
```
-Then `mobile/apps/photos/rust/`
+`flutter_rust_bridge_codegen generate` needs to be run either manually (or in watch mode, `flutter_rust_bridge_codegen generate --watch`) whenever the Rust source changes to get the bindings to update.
+
+**ente-photos-rust (mobile/apps/photos/rust/):**
```sh
-cargo build
+flutter_rust_bridge_codegen generate
+flutter test
```
## Future
@@ -188,6 +206,7 @@ wasm = ["getrandom/js"]
## Tests
- **ente-core:** Standard `cargo test` - comprehensive unit tests
-- **rust_lib_photos:** Minimal FRB smoke test in Dart to catch binding drift
+- **ente-rust:** Minimal FRB smoke test in Dart to catch binding drift
+- **ente-photos-rust:** Integration tests for app-specific functionality
- **ente-wasm:** Vitest tests in web package
- **Golden fixtures:** Share test vectors across native/FRB/WASM for crypto parity