Skip to content

armgit / ente

Public Imported from GitHub
0

💚 End-to-end encrypted cloud for everything.

Remove legacy Apple inference package

Manav Rathi668fb2f91d24
diff --git a/mobile/native/darwin/Packages/Rust/.gitignore b/mobile/native/darwin/Packages/Rust/.gitignore
deleted file mode 100644
index 40f5319175..0000000000
--- a/mobile/native/darwin/Packages/Rust/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-build/
-InferenceRSFFI.xcframework/
-Sources/InferenceRS/inference*
diff --git a/mobile/native/darwin/Packages/Rust/Package.swift b/mobile/native/darwin/Packages/Rust/Package.swift
deleted file mode 100644
index 6a845d59ad..0000000000
--- a/mobile/native/darwin/Packages/Rust/Package.swift
+++ /dev/null
@@ -1,34 +0,0 @@
-// swift-tools-version: 5.9
-import PackageDescription
-
-let package = Package(
- name: "InferenceRS",
- platforms: [
- .iOS(.v13),
- .macOS(.v10_15),
- ],
- products: [
- .library(name: "InferenceRS", targets: ["InferenceRS"]),
- ],
- targets: [
- .binaryTarget(
- name: "InferenceRSFFI",
- path: "InferenceRSFFI.xcframework"
- ),
- .target(
- name: "InferenceRS",
- dependencies: ["InferenceRSFFI"],
- path: "Sources/InferenceRS",
- linkerSettings: [
- .linkedFramework("Accelerate"),
- .linkedFramework("Metal"),
- .linkedFramework("MetalKit")
- ]
- ),
- .testTarget(
- name: "InferenceRSTests",
- dependencies: ["InferenceRS"],
- path: "Tests/InferenceRSTests"
- ),
- ]
-)
diff --git a/mobile/native/darwin/Packages/Rust/README.md b/mobile/native/darwin/Packages/Rust/README.md
deleted file mode 100644
index 65dbe92722..0000000000
--- a/mobile/native/darwin/Packages/Rust/README.md
+++ /dev/null
@@ -1,116 +0,0 @@
-# InferenceRS (Swift)
-
-Swift bindings generated via UniFFI from the shared Rust binding crate in
-`rust/uniffi/ensu/inference`, backed by `rust/ensu/inference`.
-
-## Generate bindings
-
-From the repo root:
-
-```bash
-cd mobile/native/darwin/Packages/Rust
-./tool/generate_bindings.sh
-```
-
-This writes the Swift sources plus the UniFFI header/modulemap into
-`Sources/InferenceRS`. These generated files are gitignored—re-run the script
-whenever you need to regenerate bindings.
-
-Note: The script applies the llama.cpp mtmd patch (requires `python3`). Set
-`APPLY_LLAMA_MTMD_PATCH=0` to skip it.
-
-## Build the xcframework
-
-Prerequisites on macOS:
-
-- `cargo`
-- `xcodebuild`
-- `lipo`
-- `cmake`
-- `uniffi-bindgen`
-
-From the repo root:
-
-```bash
-cd mobile/native/darwin/Packages/Rust
-./tool/build_xcframework.sh
-```
-
-This produces `InferenceRSFFI.xcframework`, which the Swift package references
-as a binary target. The xcframework is gitignored and should be generated
-locally as needed.
-
-Note: The build applies the llama.cpp mtmd patch (requires `python3`). Set
-`APPLY_LLAMA_MTMD_PATCH=0` to skip it.
-
-## Use in an app (SwiftPM)
-
-Add the package to your app and import `InferenceRS`:
-
-```swift
-import InferenceRS
-
-try initBackend()
-let model = try loadModel(
- params: ModelLoadParams(modelPath: "/path/to/model.gguf", nGpuLayers: nil, useMmap: nil, useMlock: nil)
-)
-let context = try createContext(
- model: model,
- params: ContextParams(contextSize: 4096, nThreads: 4, nBatch: 128)
-)
-
-let request = GenerateChatRequest(
- messages: [
- ChatMessage(role: "system", content: "You are a helpful assistant."),
- ChatMessage(role: "user", content: "Say hello")
- ],
- templateOverride: nil,
- addAssistant: true,
- imagePaths: nil,
- mmprojPath: nil,
- mediaMarker: nil,
- maxTokens: 64,
- temperature: 0.7,
- topP: 0.9,
- topK: nil,
- repeatPenalty: nil,
- frequencyPenalty: nil,
- presencePenalty: nil,
- seed: nil,
- stopSequences: nil,
- grammar: nil
-)
-
-final class StreamHandler: GenerateEventCallback {
- func onEvent(event: GenerateEvent) {
- switch event {
- case let .text(_, text, _):
- print(text)
- case let .done(summary):
- print("Done: \(summary.generatedTokens ?? 0) tokens")
- case let .error(_, message):
- print("Error: \(message)")
- }
- }
-}
-
-let summary = try generateChatStream(
- context: context,
- request: request,
- callback: StreamHandler()
-)
-print("Summary job id: \(summary.jobId)")
-```
-
-Notes:
-- Generation runs synchronously; invoke on a background queue if needed.
-- Callback interfaces are class-only (`AnyObject`) in Swift.
-
-## Run tests
-
-Build the xcframework first, then set a model path to enable the integration test:
-
-```bash
-./tool/build_xcframework.sh
-INFERENCE_RS_TEST_MODEL=/path/to/model.gguf swift test
-```
diff --git a/mobile/native/darwin/Packages/Rust/Tests/InferenceRSTests/InferenceRSTests.swift b/mobile/native/darwin/Packages/Rust/Tests/InferenceRSTests/InferenceRSTests.swift
deleted file mode 100644
index 7c9ffd61d9..0000000000
--- a/mobile/native/darwin/Packages/Rust/Tests/InferenceRSTests/InferenceRSTests.swift
+++ /dev/null
@@ -1,149 +0,0 @@
-import XCTest
-import InferenceRS
-
-final class GenerateEventCollector: GenerateEventCallback {
- private(set) var events: [GenerateEvent] = []
-
- func onEvent(event: GenerateEvent) {
- events.append(event)
- }
-
- var hasDone: Bool {
- events.contains { event in
- if case .done = event { return true }
- return false
- }
- }
-
- var lastError: String? {
- events.compactMap { event in
- if case let .error(_, message) = event { return message }
- return nil
- }.last
- }
-
- var textOutput: String {
- events.compactMap { event in
- if case let .text(_, text, _) = event { return text }
- return nil
- }.joined()
- }
-}
-
-final class InferenceRSTests: XCTestCase {
- func testInitBackend() throws {
- try initBackend()
- }
-
- func testGenerateChatStreamWhenModelProvided() throws {
- let env = ProcessInfo.processInfo.environment
- guard let modelPath = env["INFERENCE_RS_TEST_MODEL"] ?? env["INFERENCE_RS_TEST_MODEL_PATH"] else {
- throw XCTSkip("Set INFERENCE_RS_TEST_MODEL to run the integration test.")
- }
-
- try initBackend()
-
- let model = try loadModel(
- params: ModelLoadParams(
- modelPath: modelPath,
- nGpuLayers: nil,
- useMmap: nil,
- useMlock: nil
- )
- )
-
- let context = try createContext(
- model: model,
- params: ContextParams(contextSize: 2048, nThreads: nil, nBatch: nil)
- )
-
- let request = GenerateChatRequest(
- messages: [
- ChatMessage(role: "system", content: "You are a helpful assistant."),
- ChatMessage(role: "user", content: "Say hello in one short sentence.")
- ],
- templateOverride: nil,
- addAssistant: true,
- imagePaths: nil,
- mmprojPath: nil,
- mediaMarker: nil,
- maxTokens: 24,
- temperature: 0.7,
- topP: 0.9,
- topK: nil,
- repeatPenalty: nil,
- frequencyPenalty: nil,
- presencePenalty: nil,
- seed: 42,
- stopSequences: nil,
- grammar: nil
- )
-
- let collector = GenerateEventCollector()
- let summary = try generateChatStream(context: context, request: request, callback: collector)
-
- XCTAssertGreaterThan(summary.jobId, 0)
- XCTAssertTrue(collector.hasDone)
- XCTAssertNil(collector.lastError)
- print("Swift text output: \(collector.textOutput)")
- }
-
- func testGenerateChatStreamWithImageWhenProvided() throws {
- let env = ProcessInfo.processInfo.environment
- guard let modelPath = env["INFERENCE_RS_TEST_MODEL"] ?? env["INFERENCE_RS_TEST_MODEL_PATH"] else {
- throw XCTSkip("Set INFERENCE_RS_TEST_MODEL to run the integration test.")
- }
- guard let mmprojPath = env["INFERENCE_RS_TEST_MMPROJ"] ?? env["INFERENCE_RS_TEST_MMPROJ_PATH"] else {
- throw XCTSkip("Set INFERENCE_RS_TEST_MMPROJ to run the vision test.")
- }
- guard let imagePath = env["INFERENCE_RS_TEST_IMAGE"] ?? env["INFERENCE_RS_TEST_IMAGE_PATH"] else {
- throw XCTSkip("Set INFERENCE_RS_TEST_IMAGE to run the vision test.")
- }
-
- try initBackend()
-
- let model = try loadModel(
- params: ModelLoadParams(
- modelPath: modelPath,
- nGpuLayers: nil,
- useMmap: nil,
- useMlock: nil
- )
- )
-
- let context = try createContext(
- model: model,
- params: ContextParams(contextSize: 2048, nThreads: nil, nBatch: nil)
- )
-
- let request = GenerateChatRequest(
- messages: [
- ChatMessage(role: "system", content: "You are a helpful assistant."),
- ChatMessage(role: "user", content: "What color is the car? Answer in one word.")
- ],
- templateOverride: nil,
- addAssistant: true,
- imagePaths: [imagePath],
- mmprojPath: mmprojPath,
- mediaMarker: nil,
- maxTokens: 24,
- temperature: 0.2,
- topP: 0.9,
- topK: nil,
- repeatPenalty: nil,
- frequencyPenalty: nil,
- presencePenalty: nil,
- seed: 42,
- stopSequences: nil,
- grammar: nil
- )
-
- let collector = GenerateEventCollector()
- let summary = try generateChatStream(context: context, request: request, callback: collector)
-
- XCTAssertGreaterThan(summary.jobId, 0)
- XCTAssertTrue(collector.hasDone)
- XCTAssertNil(collector.lastError)
- print("Swift image output: \(collector.textOutput)")
- }
-}
diff --git a/mobile/native/darwin/Packages/Rust/tool/build_xcframework.sh b/mobile/native/darwin/Packages/Rust/tool/build_xcframework.sh
deleted file mode 100755
index d7e2b6271d..0000000000
--- a/mobile/native/darwin/Packages/Rust/tool/build_xcframework.sh
+++ /dev/null
@@ -1,109 +0,0 @@
-#!/usr/bin/env bash
-set -euo pipefail
-
-ROOT="$(cd "$(dirname "$0")/.." && pwd)"
-REPO_ROOT="$(cd "$ROOT/../../../../.." && pwd)"
-RUST_DIR="$REPO_ROOT/rust/uniffi/ensu/inference"
-CORE_ROOT="$REPO_ROOT/rust/ensu/inference"
-PATCH_SCRIPT="$CORE_ROOT/tool/patch_llama_mtmd.sh"
-APPLY_LLAMA_MTMD_PATCH="${APPLY_LLAMA_MTMD_PATCH:-1}"
-LIB_NAME="libinference.a"
-
-require_command() {
- local name="$1"
- local hint="${2:-}"
- if command -v "$name" >/dev/null 2>&1; then
- return
- fi
-
- echo "Missing required command: $name" >&2
- if [[ -n "$hint" ]]; then
- echo "$hint" >&2
- fi
- exit 1
-}
-
-require_command cargo "Install Rust and ensure cargo is on PATH."
-require_command rustup "Install rustup and ensure it is on PATH."
-require_command xcodebuild "Install Xcode command line tools and ensure xcodebuild is on PATH."
-require_command lipo "Install Xcode command line tools and ensure lipo is on PATH."
-require_command cmake "Install CMake, for example with 'brew install cmake'."
-require_command uniffi-bindgen "Install a compatible version with 'cargo install --locked --version 0.31.0 uniffi --features cli --bin uniffi-bindgen'."
-
-require_rust_target() {
- local target="$1"
- if rustup target list --installed | grep -qx "$target"; then
- return
- fi
-
- echo "Missing required Rust target: $target" >&2
- echo "Install Apple targets with:" >&2
- echo " rustup target add aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-ios aarch64-apple-darwin x86_64-apple-darwin" >&2
- exit 1
-}
-
-require_rust_target aarch64-apple-ios
-require_rust_target aarch64-apple-ios-sim
-require_rust_target x86_64-apple-ios
-require_rust_target aarch64-apple-darwin
-require_rust_target x86_64-apple-darwin
-
-if [[ "$APPLY_LLAMA_MTMD_PATCH" != "0" && -f "$PATCH_SCRIPT" ]]; then
- if ! command -v python3 >/dev/null 2>&1; then
- echo "python3 is required to apply the llama mtmd patch." >&2
- exit 1
- fi
- echo "Applying llama mtmd patch..."
- bash "$PATCH_SCRIPT"
-fi
-
-"$ROOT/tool/generate_bindings.sh"
-
-HEADER_DIR="$ROOT/build/headers"
-HEADER_SRC="$ROOT/Sources/InferenceRS/inferenceFFI.h"
-MODULEMAP_SRC="$ROOT/Sources/InferenceRS/inferenceFFI.modulemap"
-
-rm -rf "$HEADER_DIR"
-mkdir -p "$ROOT/build/ios" "$ROOT/build/macos" "$HEADER_DIR"
-
-if [[ ! -f "$HEADER_SRC" ]] || [[ ! -f "$MODULEMAP_SRC" ]]; then
- echo "Expected UniFFI headers in $ROOT/Sources/InferenceRS" >&2
- exit 1
-fi
-
-cp "$HEADER_SRC" "$HEADER_DIR/"
-cp "$MODULEMAP_SRC" "$HEADER_DIR/module.modulemap"
-
-export IPHONEOS_DEPLOYMENT_TARGET=13.0
-export CMAKE_OSX_DEPLOYMENT_TARGET=13.0
-
-cargo rustc --manifest-path "$RUST_DIR/Cargo.toml" --release --target aarch64-apple-ios --lib --crate-type staticlib
-cargo rustc --manifest-path "$RUST_DIR/Cargo.toml" --release --target aarch64-apple-ios-sim --lib --crate-type staticlib
-cargo rustc --manifest-path "$RUST_DIR/Cargo.toml" --release --target x86_64-apple-ios --lib --crate-type staticlib
-
-cp "$RUST_DIR/target/aarch64-apple-ios/release/$LIB_NAME" "$ROOT/build/ios/$LIB_NAME"
-
-lipo -create \
- "$RUST_DIR/target/aarch64-apple-ios-sim/release/$LIB_NAME" \
- "$RUST_DIR/target/x86_64-apple-ios/release/$LIB_NAME" \
- -output "$ROOT/build/ios/${LIB_NAME%.a}-sim.a"
-
-unset IPHONEOS_DEPLOYMENT_TARGET
-export MACOSX_DEPLOYMENT_TARGET=10.15
-export CMAKE_OSX_DEPLOYMENT_TARGET=10.15
-
-cargo rustc --manifest-path "$RUST_DIR/Cargo.toml" --release --target aarch64-apple-darwin --lib --crate-type staticlib
-cargo rustc --manifest-path "$RUST_DIR/Cargo.toml" --release --target x86_64-apple-darwin --lib --crate-type staticlib
-
-lipo -create \
- "$RUST_DIR/target/aarch64-apple-darwin/release/$LIB_NAME" \
- "$RUST_DIR/target/x86_64-apple-darwin/release/$LIB_NAME" \
- -output "$ROOT/build/macos/$LIB_NAME"
-
-rm -rf "$ROOT/InferenceRSFFI.xcframework"
-
-xcodebuild -create-xcframework \
- -library "$ROOT/build/ios/$LIB_NAME" -headers "$HEADER_DIR" \
- -library "$ROOT/build/ios/${LIB_NAME%.a}-sim.a" -headers "$HEADER_DIR" \
- -library "$ROOT/build/macos/$LIB_NAME" -headers "$HEADER_DIR" \
- -output "$ROOT/InferenceRSFFI.xcframework"
diff --git a/mobile/native/darwin/Packages/Rust/tool/generate_bindings.sh b/mobile/native/darwin/Packages/Rust/tool/generate_bindings.sh
deleted file mode 100755
index 332a186a93..0000000000
--- a/mobile/native/darwin/Packages/Rust/tool/generate_bindings.sh
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/usr/bin/env bash
-set -euo pipefail
-
-ROOT="$(cd "$(dirname "$0")/.." && pwd)"
-REPO_ROOT="$(cd "$ROOT/../../../../.." && pwd)"
-RUST_DIR="$REPO_ROOT/rust/uniffi/ensu/inference"
-CORE_ROOT="$REPO_ROOT/rust/ensu/inference"
-PATCH_SCRIPT="$CORE_ROOT/tool/patch_llama_mtmd.sh"
-APPLY_LLAMA_MTMD_PATCH="${APPLY_LLAMA_MTMD_PATCH:-1}"
-OUT_DIR="$ROOT/Sources/InferenceRS"
-
-require_command() {
- local name="$1"
- local hint="${2:-}"
- if command -v "$name" >/dev/null 2>&1; then
- return
- fi
-
- echo "Missing required command: $name" >&2
- if [[ -n "$hint" ]]; then
- echo "$hint" >&2
- fi
- exit 1
-}
-
-require_compatible_uniffi_bindgen() {
- require_command cargo "Install Rust and ensure cargo is on PATH."
-
- if command -v uniffi-bindgen >/dev/null 2>&1; then
- local version
- version="$(uniffi-bindgen --version 2>/dev/null || true)"
- if printf "%s" "$version" | grep -q "0.31."; then
- return
- fi
- echo "Found incompatible ${version:-uniffi-bindgen version}." >&2
- else
- echo "Missing required command: uniffi-bindgen" >&2
- fi
-
- echo "Install a compatible version with:" >&2
- echo " cargo install --locked --version 0.31.0 uniffi --features cli --bin uniffi-bindgen" >&2
- exit 1
-}
-
-require_command cargo "Install Rust and ensure cargo is on PATH."
-require_compatible_uniffi_bindgen
-
-if [[ "$APPLY_LLAMA_MTMD_PATCH" != "0" && -f "$PATCH_SCRIPT" ]]; then
- if ! command -v python3 >/dev/null 2>&1; then
- echo "python3 is required to apply the llama mtmd patch." >&2
- exit 1
- fi
- echo "Applying llama mtmd patch..."
- bash "$PATCH_SCRIPT"
-fi
-
-cargo build --manifest-path "$RUST_DIR/Cargo.toml" --release
-
-if [[ "$(uname -s)" == "Darwin" ]]; then
- LIB_EXT="dylib"
-elif [[ "$(uname -s)" == "Linux" ]]; then
- LIB_EXT="so"
-else
- LIB_EXT="dll"
-fi
-
-LIB_PATH="$RUST_DIR/target/release/libinference.$LIB_EXT"
-
-if [[ ! -f "$LIB_PATH" ]]; then
- echo "Expected $LIB_PATH to exist" >&2
- exit 1
-fi
-
-mkdir -p "$OUT_DIR"
-rm -f "$OUT_DIR"/inference* "$OUT_DIR"/inference_rs_uniffi*
-
-pushd "$RUST_DIR" >/dev/null
-uniffi-bindgen generate "$LIB_PATH" --language swift --out-dir "$OUT_DIR" --crate inference
-popd >/dev/null
diff --git a/rust/ensu/packaging.md b/rust/ensu/packaging.md
index ec7f281a5b..c862798974 100644
--- a/rust/ensu/packaging.md
+++ b/rust/ensu/packaging.md
@@ -29,5 +29,4 @@ Android and Apple native apps use UniFFI + adapters.
## Native packaging layers
- Android: `mobile/native/android/packages/rust`
-- Apple (`core`, `db`, `sync`): `mobile/native/darwin/Apps/ensu`
-- Apple (`inference`): `mobile/native/darwin/Packages/Rust`
+- Apple: `mobile/native/darwin/Apps/ensu`