π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add Ensu iOS codegen entrypoint
Manav Rathi808511ed2d42
diff --git a/mobile/native/darwin/Apps/Ensu/README.md b/mobile/native/darwin/Apps/Ensu/README.mdindex 2ab3580e31..ddb166b918 100644--- a/mobile/native/darwin/Apps/Ensu/README.md+++ b/mobile/native/darwin/Apps/Ensu/README.md@@ -31,13 +31,20 @@ cmake is a prerequisite (e.g. `brew install cmake`).## Generated bindings & dependencies+- On a fresh checkout, from the repo root run the repo-local codegen step before any Xcode build:++```bash+cd rust+cargo codegen ensu-ios+```+- SwiftMath is fetched via SwiftPM (`https://github.com/mgriebling/SwiftMath.git`).- UniFFI Swift bindings are generated locally and gitignored:- `Ensu/Generated/core*`, `Ensu/Generated/db*`, `Ensu/Generated/sync*`, `Ensu/Generated/inference*`The Xcode build script (`scripts/build-rust.sh`) builds the Rust static libs directly into-`$(TARGET_TEMP_DIR)/ensu_rust` and regenerates the `core`, `db`, `sync`, and `inference`-Swift bindings into `Ensu/Generated/` as part of the build.+`$(TARGET_TEMP_DIR)/ensu_rust` and consumes the generated `core`, `db`, `sync`, and `inference`+Swift bindings from `Ensu/Generated/`. It does not generate bindings or install tools.### Debug Build (Simulator)```bashdiff --git a/mobile/native/darwin/Apps/Ensu/scripts/build-rust.sh b/mobile/native/darwin/Apps/Ensu/scripts/build-rust.shindex 602b332e89..20187fa900 100755--- a/mobile/native/darwin/Apps/Ensu/scripts/build-rust.sh+++ b/mobile/native/darwin/Apps/Ensu/scripts/build-rust.sh@@ -18,6 +18,20 @@ REPO_ROOT="$(cd "${SRCROOT}/../../../../.." && pwd)"OUT_DIR="${TARGET_TEMP_DIR}/ensu_rust"GENERATED_DIR="${SRCROOT}/Ensu/Generated"+CARGO_BIN_DIR="${CARGO_HOME:-${HOME}/.cargo}/bin"+if [ -d "${CARGO_BIN_DIR}" ]; then+ export PATH="${CARGO_BIN_DIR}:${PATH}"+fi++CARGO_BIN="$(command -v cargo || true)"+RUSTUP_BIN="$(command -v rustup || true)"++if [ -z "${CARGO_BIN}" ] || [ -z "${RUSTUP_BIN}" ]; then+ echo "Rust tools not found in PATH for Xcode." >&2+ echo "Expected to find cargo and rustup, usually under ${CARGO_BIN_DIR}." >&2+ exit 1+fi+mkdir -p "${OUT_DIR}"mkdir -p "${GENERATED_DIR}"@@ -79,82 +93,15 @@ bindings_missing() {return 1}-generate_swift_binding() {- crate_dir="$1"- dylib_name="$2"-- (- cd "${crate_dir}"- cargo build --locked --release- uniffi-bindgen generate "target/release/${dylib_name}" --language swift --out-dir "${GENERATED_DIR}"- )-}--sanitize_generated_swift_bindings() {- swift_file="$1"-- if [ ! -f "${swift_file}" ]; then- return- fi-- perl -0pi -e 's@try! rustCall \{ (uniffi_(?:db|sync)_fn_free_[^(]+\([^)]*\)) \}@// Avoid aborting the host app if Rust-side teardown fails during process shutdown.\n try? rustCall { $1 }@g' "${swift_file}"-}-ensure_generated_bindings() {if ! bindings_missing; thenreturnfi- if ! command -v uniffi-bindgen >/dev/null 2>&1; then- echo "Missing generated UniFFI Swift bindings in ${GENERATED_DIR}." >&2- echo "Install uniffi-bindgen and retry the build." >&2- exit 1- fi-- echo "Generating missing UniFFI Swift bindings..."- mkdir -p "${GENERATED_DIR}"- generate_swift_binding "${REPO_ROOT}/rust/uniffi/core" "libcore.dylib"- generate_swift_binding "${REPO_ROOT}/rust/uniffi/ensu/db" "libdb.dylib"- generate_swift_binding "${REPO_ROOT}/rust/uniffi/ensu/sync" "libsync.dylib"- generate_swift_binding "${REPO_ROOT}/rust/uniffi/ensu/inference" "libinference.dylib"- sanitize_generated_swift_bindings "${GENERATED_DIR}/db.swift"- sanitize_generated_swift_bindings "${GENERATED_DIR}/sync.swift"-}--HOST_LIB_EXT="dylib"--ensure_uniffi_bindgen() {- if command -v uniffi-bindgen >/dev/null 2>&1; then- version="$(uniffi-bindgen --version 2>/dev/null || true)"- if printf "%s" "${version}" | grep -q "0.31."; then- return- fi- echo "Found incompatible ${version}, installing uniffi-bindgen 0.31.x"- fi-- cargo install --locked --version 0.31.0 uniffi --features cli --bin uniffi-bindgen-}--generate_swift_bindings() {- crate_name="$1" # e.g. core- crate_dir="$2" # absolute path- lib_stem="$3" # e.g. core-- echo "π§© Generating Swift bindings for ${crate_name}"- rm -f "${GENERATED_DIR}/${crate_name}.swift" \- "${GENERATED_DIR}/${crate_name}FFI.h" \- "${GENERATED_DIR}/${crate_name}FFI.modulemap"-- (cd "${crate_dir}" && cargo build ${CARGO_FLAGS})-- host_lib_path="${crate_dir}/target/${PROFILE}/lib${lib_stem}.${HOST_LIB_EXT}"- if [ ! -f "${host_lib_path}" ]; then- echo "Expected host library not found: ${host_lib_path}" >&2- exit 1- fi-- (cd "${crate_dir}" && uniffi-bindgen generate "${host_lib_path}" --language swift --out-dir "${GENERATED_DIR}" --crate "${crate_name}")- sanitize_generated_swift_bindings "${GENERATED_DIR}/${crate_name}.swift"+ echo "Missing generated UniFFI Swift bindings in ${GENERATED_DIR}." >&2+ echo "Run the repo-local codegen step first:" >&2+ echo " cd \"${REPO_ROOT}/rust\" && cargo codegen ensu-ios" >&2+ exit 1}# Map Xcode platform+arch to Rust target triple.@@ -214,13 +161,8 @@ HOST_SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"# Ensure host builds (build scripts) use the macOS SDK.export SDKROOT="${HOST_SDKROOT}"-ensure_uniffi_bindgenensure_generated_bindingswrite_endpoint_config-generate_swift_bindings "core" "${REPO_ROOT}/rust/uniffi/core" "core"-generate_swift_bindings "db" "${REPO_ROOT}/rust/uniffi/ensu/db" "db"-generate_swift_bindings "sync" "${REPO_ROOT}/rust/uniffi/ensu/sync" "sync"-generate_swift_bindings "inference" "${REPO_ROOT}/rust/uniffi/ensu/inference" "inference"build_crate_universal() {crate_name="$1" # e.g. core@@ -238,9 +180,9 @@ build_crate_universal() {continuefi- if ! rustup target list --installed | grep -q "^${target}$"; then+ if ! "${RUSTUP_BIN}" target list --installed | grep -q "^${target}$"; thenecho "Installing Rust target ${target}..."- rustup target add "${target}"+ "${RUSTUP_BIN}" target add "${target}"fitarget_env="$(echo "${target}" | tr '[:lower:]-' '[:upper:]_')"@@ -261,7 +203,7 @@ build_crate_universal() {fiecho "Building ${crate_name} for ${PLATFORM_NAME} ${arch} (${target}) [${PROFILE}]"- (cd "${crate_dir}" && RUSTFLAGS="${RUSTFLAGS_TARGET}" cargo build ${CARGO_FLAGS} --target "${target}")+ (cd "${crate_dir}" && RUSTFLAGS="${RUSTFLAGS_TARGET}" "${CARGO_BIN}" build ${CARGO_FLAGS} --target "${target}")lib_path="${crate_dir}/target/${target}/${PROFILE}/${lib_name}"if [ ! -f "${lib_path}" ]; thendiff --git a/mobile/native/darwin/Apps/Ensu/setup-mac.sh b/mobile/native/darwin/Apps/Ensu/setup-mac.shindex 8633147a4e..d4cb704d4c 100755--- a/mobile/native/darwin/Apps/Ensu/setup-mac.sh+++ b/mobile/native/darwin/Apps/Ensu/setup-mac.sh@@ -7,7 +7,7 @@ set -euo pipefail# It covers the setup steps we had to take locally to make `archive` work:# 1. Ensure required local developer tools are installed.# 2. Ensure the required Rust Apple targets are installed.-# 3. Ensure the expected uniffi-bindgen version is available.+# 3. Ensure the generated UniFFI Swift bindings already exist.# 4. Resolve Swift package dependencies for the Xcode project.# 5. Print the archive command to run next.#@@ -76,21 +76,30 @@ require_rust_target() {exit 1}-require_uniffi_bindgen() {- 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+require_generated_bindings() {+ local generated_dir="$ROOT/Ensu/Generated"++ for binding in \+ "$generated_dir/core.swift" \+ "$generated_dir/coreFFI.h" \+ "$generated_dir/coreFFI.modulemap" \+ "$generated_dir/db.swift" \+ "$generated_dir/dbFFI.h" \+ "$generated_dir/dbFFI.modulemap" \+ "$generated_dir/sync.swift" \+ "$generated_dir/syncFFI.h" \+ "$generated_dir/syncFFI.modulemap" \+ "$generated_dir/inference.swift" \+ "$generated_dir/inferenceFFI.h" \+ "$generated_dir/inferenceFFI.modulemap"; do+ if [[ ! -f "$binding" ]]; then+ echo "Missing generated UniFFI Swift bindings under $generated_dir" >&2+ echo "Run the repo-local codegen step first:" >&2+ echo " cd \"$ROOT/../../../../../rust\"" >&2+ echo " cargo codegen ensu-ios" >&2+ exit 1fi- 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+ done}print_step "Checking required local tools"@@ -99,12 +108,13 @@ require_command cargo "Install Rust and ensure cargo is on PATH."require_command rustup "Install rustup and ensure it is on PATH."require_command cmake "Install CMake, for example with 'brew install cmake'."require_command lipo "Install Xcode command line tools and ensure lipo is on PATH."-require_uniffi_bindgenprint_step "Checking required Rust Apple targets"require_rust_target aarch64-apple-iosrequire_rust_target aarch64-apple-ios-simrequire_rust_target x86_64-apple-ios+print_step "Checking generated UniFFI Swift bindings"+require_generated_bindingsprint_step "Resolving Swift package dependencies"(cd "$ROOT"@@ -128,6 +138,9 @@ Archive command:archiveNotes:+ - If the generated Swift bindings are missing, run:+ cd "$ROOT/../../../../../rust"+ cargo codegen ensu-ios- Provisioning/TestFlight export is intentionally not handled here.- If Xcode still shows missing package products, run:File > Packages > Resolve Package Versionsdiff --git a/rust/.cargo/config.toml b/rust/.cargo/config.tomlindex 3ffe01aae3..8ae058feb8 100644--- a/rust/.cargo/config.toml+++ b/rust/.cargo/config.toml@@ -1,3 +1,6 @@+[alias]+codegen = ["run", "-p", "codegen", "--"]+[target.'cfg(target_arch = "aarch64")']rustflags = ["--cfg", "chacha20_force_neon"]diff --git a/rust/Cargo.lock b/rust/Cargo.locknew file mode 100644index 0000000000..e9fa382764--- /dev/null+++ b/rust/Cargo.lock@@ -0,0 +1,806 @@+# This file is automatically @generated by Cargo.+# It is not intended for manual editing.+version = 4++[[package]]+name = "anyhow"+version = "1.0.102"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"++[[package]]+name = "askama"+version = "0.14.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f75363874b771be265f4ffe307ca705ef6f3baa19011c149da8674a87f1b75c4"+dependencies = [+ "askama_derive",+ "itoa",+ "percent-encoding",+ "serde",+ "serde_json",+]++[[package]]+name = "askama_derive"+version = "0.14.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "129397200fe83088e8a68407a8e2b1f826cf0086b21ccdb866a722c8bcd3a94f"+dependencies = [+ "askama_parser",+ "basic-toml",+ "memchr",+ "proc-macro2",+ "quote",+ "rustc-hash",+ "serde",+ "serde_derive",+ "syn",+]++[[package]]+name = "askama_parser"+version = "0.14.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d6ab5630b3d5eaf232620167977f95eb51f3432fc76852328774afbd242d4358"+dependencies = [+ "memchr",+ "serde",+ "serde_derive",+ "winnow 0.7.15",+]++[[package]]+name = "autocfg"+version = "1.5.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"++[[package]]+name = "basic-toml"+version = "0.1.10"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ba62675e8242a4c4e806d12f11d136e626e6c8361d6b829310732241652a178a"+dependencies = [+ "serde",+]++[[package]]+name = "bitflags"+version = "2.11.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"++[[package]]+name = "camino"+version = "1.2.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e629a66d692cb9ff1a1c664e41771b3dcaf961985a9774c0eb0bd1b51cf60a48"+dependencies = [+ "serde_core",+]++[[package]]+name = "cargo-platform"+version = "0.1.9"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea"+dependencies = [+ "serde",+]++[[package]]+name = "cargo_metadata"+version = "0.19.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "dd5eb614ed4c27c5d706420e4320fbe3216ab31fa1c33cd8246ac36dae4479ba"+dependencies = [+ "camino",+ "cargo-platform",+ "semver",+ "serde",+ "serde_json",+ "thiserror",+]++[[package]]+name = "cfg-if"+version = "1.0.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"++[[package]]+name = "codegen"+version = "0.1.0"+dependencies = [+ "camino",+ "uniffi_bindgen",+]++[[package]]+name = "equivalent"+version = "1.0.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"++[[package]]+name = "errno"+version = "0.3.14"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"+dependencies = [+ "libc",+ "windows-sys",+]++[[package]]+name = "fastrand"+version = "2.4.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6"++[[package]]+name = "foldhash"+version = "0.1.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"++[[package]]+name = "fs-err"+version = "2.11.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "88a41f105fe1d5b6b34b2055e3dc59bb79b46b48b2040b9e6c7b4b5de097aa41"+dependencies = [+ "autocfg",+]++[[package]]+name = "getrandom"+version = "0.4.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555"+dependencies = [+ "cfg-if",+ "libc",+ "r-efi",+ "wasip2",+ "wasip3",+]++[[package]]+name = "glob"+version = "0.3.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"++[[package]]+name = "goblin"+version = "0.8.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1b363a30c165f666402fe6a3024d3bec7ebc898f96a4a23bd1c99f8dbf3f4f47"+dependencies = [+ "log",+ "plain",+ "scroll",+]++[[package]]+name = "hashbrown"+version = "0.15.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"+dependencies = [+ "foldhash",+]++[[package]]+name = "hashbrown"+version = "0.17.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51"++[[package]]+name = "heck"+version = "0.5.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"++[[package]]+name = "id-arena"+version = "2.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"++[[package]]+name = "indexmap"+version = "2.14.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"+dependencies = [+ "equivalent",+ "hashbrown 0.17.0",+ "serde",+ "serde_core",+]++[[package]]+name = "itoa"+version = "1.0.18"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"++[[package]]+name = "leb128fmt"+version = "0.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"++[[package]]+name = "libc"+version = "0.2.184"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "48f5d2a454e16a5ea0f4ced81bd44e4cfc7bd3a507b61887c99fd3538b28e4af"++[[package]]+name = "linux-raw-sys"+version = "0.12.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"++[[package]]+name = "log"+version = "0.4.29"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"++[[package]]+name = "memchr"+version = "2.8.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"++[[package]]+name = "minimal-lexical"+version = "0.2.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"++[[package]]+name = "nom"+version = "7.1.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"+dependencies = [+ "memchr",+ "minimal-lexical",+]++[[package]]+name = "once_cell"+version = "1.21.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"++[[package]]+name = "percent-encoding"+version = "2.3.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"++[[package]]+name = "plain"+version = "0.2.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"++[[package]]+name = "prettyplease"+version = "0.2.37"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"+dependencies = [+ "proc-macro2",+ "syn",+]++[[package]]+name = "proc-macro2"+version = "1.0.106"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"+dependencies = [+ "unicode-ident",+]++[[package]]+name = "quote"+version = "1.0.45"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"+dependencies = [+ "proc-macro2",+]++[[package]]+name = "r-efi"+version = "6.0.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"++[[package]]+name = "rustc-hash"+version = "2.1.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe"++[[package]]+name = "rustix"+version = "1.1.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190"+dependencies = [+ "bitflags",+ "errno",+ "libc",+ "linux-raw-sys",+ "windows-sys",+]++[[package]]+name = "scroll"+version = "0.12.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6ab8598aa408498679922eff7fa985c25d58a90771bd6be794434c5277eab1a6"+dependencies = [+ "scroll_derive",+]++[[package]]+name = "scroll_derive"+version = "0.12.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1783eabc414609e28a5ba76aee5ddd52199f7107a0b24c2e9746a1ecc34a683d"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "semver"+version = "1.0.28"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"+dependencies = [+ "serde",+ "serde_core",+]++[[package]]+name = "serde"+version = "1.0.228"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"+dependencies = [+ "serde_core",+ "serde_derive",+]++[[package]]+name = "serde_core"+version = "1.0.228"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"+dependencies = [+ "serde_derive",+]++[[package]]+name = "serde_derive"+version = "1.0.228"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "serde_json"+version = "1.0.149"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"+dependencies = [+ "itoa",+ "memchr",+ "serde",+ "serde_core",+ "zmij",+]++[[package]]+name = "serde_spanned"+version = "1.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26"+dependencies = [+ "serde_core",+]++[[package]]+name = "siphasher"+version = "1.0.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e"++[[package]]+name = "smawk"+version = "0.3.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c"++[[package]]+name = "syn"+version = "2.0.117"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"+dependencies = [+ "proc-macro2",+ "quote",+ "unicode-ident",+]++[[package]]+name = "tempfile"+version = "3.27.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"+dependencies = [+ "fastrand",+ "getrandom",+ "once_cell",+ "rustix",+ "windows-sys",+]++[[package]]+name = "textwrap"+version = "0.16.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c13547615a44dc9c452a8a534638acdf07120d4b6847c8178705da06306a3057"+dependencies = [+ "smawk",+]++[[package]]+name = "thiserror"+version = "2.0.18"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"+dependencies = [+ "thiserror-impl",+]++[[package]]+name = "thiserror-impl"+version = "2.0.18"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "toml"+version = "0.9.12+spec-1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "cf92845e79fc2e2def6a5d828f0801e29a2f8acc037becc5ab08595c7d5e9863"+dependencies = [+ "indexmap",+ "serde_core",+ "serde_spanned",+ "toml_datetime",+ "toml_parser",+ "toml_writer",+ "winnow 0.7.15",+]++[[package]]+name = "toml_datetime"+version = "0.7.5+spec-1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347"+dependencies = [+ "serde_core",+]++[[package]]+name = "toml_parser"+version = "1.1.2+spec-1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526"+dependencies = [+ "winnow 1.0.1",+]++[[package]]+name = "toml_writer"+version = "1.1.1+spec-1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "756daf9b1013ebe47a8776667b466417e2d4c5679d441c26230efd9ef78692db"++[[package]]+name = "unicode-ident"+version = "1.0.24"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"++[[package]]+name = "unicode-xid"+version = "0.2.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"++[[package]]+name = "uniffi_bindgen"+version = "0.31.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4ed0150801958d4825da56a41c71f000a457ac3a4613fa9647df78ac4b6b6881"+dependencies = [+ "anyhow",+ "askama",+ "camino",+ "cargo_metadata",+ "fs-err",+ "glob",+ "goblin",+ "heck",+ "indexmap",+ "once_cell",+ "serde",+ "tempfile",+ "textwrap",+ "toml",+ "uniffi_internal_macros",+ "uniffi_meta",+ "uniffi_pipeline",+ "uniffi_udl",+]++[[package]]+name = "uniffi_internal_macros"+version = "0.31.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "98f51ebca0d9a4b2aa6c644d5ede45c56f73906b96403c08a1985e75ccb64a01"+dependencies = [+ "anyhow",+ "indexmap",+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "uniffi_meta"+version = "0.31.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9df6d413db2827c68588f8149d30d49b71d540d46539e435b23a7f7dbd4d4f86"+dependencies = [+ "anyhow",+ "siphasher",+ "uniffi_internal_macros",+ "uniffi_pipeline",+]++[[package]]+name = "uniffi_pipeline"+version = "0.31.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a806dddc8208f22efd7e95a5cdf88ed43d0f3271e8f63b47e757a8bbdb43b63a"+dependencies = [+ "anyhow",+ "heck",+ "indexmap",+ "tempfile",+ "uniffi_internal_macros",+]++[[package]]+name = "uniffi_udl"+version = "0.31.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0d1a7339539bf6f6fa3e9b534dece13f778bda2d54b1a6d4e40b4d6090ac26e7"+dependencies = [+ "anyhow",+ "textwrap",+ "uniffi_meta",+ "weedle2",+]++[[package]]+name = "wasip2"+version = "1.0.2+wasi-0.2.9"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5"+dependencies = [+ "wit-bindgen",+]++[[package]]+name = "wasip3"+version = "0.4.0+wasi-0.3.0-rc-2026-01-06"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5"+dependencies = [+ "wit-bindgen",+]++[[package]]+name = "wasm-encoder"+version = "0.244.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319"+dependencies = [+ "leb128fmt",+ "wasmparser",+]++[[package]]+name = "wasm-metadata"+version = "0.244.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909"+dependencies = [+ "anyhow",+ "indexmap",+ "wasm-encoder",+ "wasmparser",+]++[[package]]+name = "wasmparser"+version = "0.244.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe"+dependencies = [+ "bitflags",+ "hashbrown 0.15.5",+ "indexmap",+ "semver",+]++[[package]]+name = "weedle2"+version = "5.0.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "998d2c24ec099a87daf9467808859f9d82b61f1d9c9701251aea037f514eae0e"+dependencies = [+ "nom",+]++[[package]]+name = "windows-link"+version = "0.2.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"++[[package]]+name = "windows-sys"+version = "0.61.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"+dependencies = [+ "windows-link",+]++[[package]]+name = "winnow"+version = "0.7.15"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945"+dependencies = [+ "memchr",+]++[[package]]+name = "winnow"+version = "1.0.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "09dac053f1cd375980747450bfc7250c264eaae0583872e845c0c7cd578872b5"++[[package]]+name = "wit-bindgen"+version = "0.51.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"+dependencies = [+ "wit-bindgen-rust-macro",+]++[[package]]+name = "wit-bindgen-core"+version = "0.51.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc"+dependencies = [+ "anyhow",+ "heck",+ "wit-parser",+]++[[package]]+name = "wit-bindgen-rust"+version = "0.51.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21"+dependencies = [+ "anyhow",+ "heck",+ "indexmap",+ "prettyplease",+ "syn",+ "wasm-metadata",+ "wit-bindgen-core",+ "wit-component",+]++[[package]]+name = "wit-bindgen-rust-macro"+version = "0.51.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a"+dependencies = [+ "anyhow",+ "prettyplease",+ "proc-macro2",+ "quote",+ "syn",+ "wit-bindgen-core",+ "wit-bindgen-rust",+]++[[package]]+name = "wit-component"+version = "0.244.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2"+dependencies = [+ "anyhow",+ "bitflags",+ "indexmap",+ "log",+ "serde",+ "serde_derive",+ "serde_json",+ "wasm-encoder",+ "wasm-metadata",+ "wasmparser",+ "wit-parser",+]++[[package]]+name = "wit-parser"+version = "0.244.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736"+dependencies = [+ "anyhow",+ "id-arena",+ "indexmap",+ "log",+ "semver",+ "serde",+ "serde_derive",+ "serde_json",+ "unicode-xid",+ "wasmparser",+]++[[package]]+name = "zmij"+version = "1.0.21"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"diff --git a/rust/Cargo.toml b/rust/Cargo.tomlnew file mode 100644index 0000000000..c700e63f4c--- /dev/null+++ b/rust/Cargo.toml@@ -0,0 +1,18 @@+[workspace]+resolver = "2"+members = ["apps/codegen"]+exclude = [+ "apps/ensu/src-tauri",+ "cli",+ "contacts",+ "core",+ "e2e",+ "ensu/db",+ "ensu/inference",+ "ensu/sync",+ "photos",+ "uniffi/core",+ "uniffi/ensu/db",+ "uniffi/ensu/inference",+ "uniffi/ensu/sync",+]diff --git a/rust/apps/codegen/Cargo.toml b/rust/apps/codegen/Cargo.tomlnew file mode 100644index 0000000000..c0dc5d2d0a--- /dev/null+++ b/rust/apps/codegen/Cargo.toml@@ -0,0 +1,8 @@+[package]+name = "codegen"+version = "0.1.0"+edition = "2024"++[dependencies]+camino = "=1.2.2"+uniffi_bindgen = { version = "=0.31.0", default-features = false, features = ["cargo-metadata"] }diff --git a/rust/apps/codegen/src/main.rs b/rust/apps/codegen/src/main.rsnew file mode 100644index 0000000000..30b3424426--- /dev/null+++ b/rust/apps/codegen/src/main.rs@@ -0,0 +1,228 @@+use std::env;+use std::error::Error;+use std::ffi::OsStr;+use std::fs;+use std::path::{Path, PathBuf};+use std::process::Command;++use camino::Utf8PathBuf;+use uniffi_bindgen::bindings::{self, GenerateOptions, TargetLanguage};++type DynError = Box<dyn Error>;++struct UniffiCrate<'a> {+ crate_name: &'a str,+ crate_dir: PathBuf,+ dylib_name: &'a str,+}++fn main() {+ if let Err(error) = run() {+ eprintln!("{error}");+ std::process::exit(1);+ }+}++fn run() -> Result<(), DynError> {+ let mut args = env::args().skip(1);+ match (args.next().as_deref(), args.next()) {+ (Some("ensu-ios"), None) => generate_ensu_ios(),+ _ => Err("usage: cargo codegen ensu-ios".into()),+ }+}++fn generate_ensu_ios() -> Result<(), DynError> {+ let rust_root = rust_root()?;+ let repo_root = rust_root+ .parent()+ .ok_or("failed to resolve repo root from rust/apps/codegen")?;+ let generated_dir = repo_root.join("mobile/native/darwin/Apps/Ensu/Ensu/Generated");++ fs::create_dir_all(&generated_dir)?;++ let crates = [+ UniffiCrate {+ crate_name: "core",+ crate_dir: rust_root.join("uniffi/core"),+ dylib_name: "libcore.dylib",+ },+ UniffiCrate {+ crate_name: "db",+ crate_dir: rust_root.join("uniffi/ensu/db"),+ dylib_name: "libdb.dylib",+ },+ UniffiCrate {+ crate_name: "sync",+ crate_dir: rust_root.join("uniffi/ensu/sync"),+ dylib_name: "libsync.dylib",+ },+ UniffiCrate {+ crate_name: "inference",+ crate_dir: rust_root.join("uniffi/ensu/inference"),+ dylib_name: "libinference.dylib",+ },+ ];++ for uniffi_crate in crates {+ build_host_dylib(&uniffi_crate.crate_dir)?;+ remove_generated_bindings(&generated_dir, uniffi_crate.crate_name)?;+ generate_swift_bindings(&generated_dir, &uniffi_crate)?;+ }++ sanitize_generated_swift_bindings(&generated_dir.join("db.swift"), "db")?;+ sanitize_generated_swift_bindings(&generated_dir.join("sync.swift"), "sync")?;++ Ok(())+}++fn rust_root() -> Result<PathBuf, DynError> {+ let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));+ manifest_dir+ .parent()+ .and_then(Path::parent)+ .map(Path::to_path_buf)+ .ok_or_else(|| "failed to resolve rust workspace root".into())+}++fn build_host_dylib(crate_dir: &Path) -> Result<(), DynError> {+ run_command(+ Command::new("cargo")+ .arg("build")+ .arg("--locked")+ .arg("--release")+ .current_dir(crate_dir),+ format!("failed to build {}", crate_dir.display()),+ )+}++fn remove_generated_bindings(generated_dir: &Path, crate_name: &str) -> Result<(), DynError> {+ for suffix in [".swift", "FFI.h", "FFI.modulemap"] {+ let path = generated_dir.join(format!("{crate_name}{suffix}"));+ match fs::remove_file(&path) {+ Ok(()) => {}+ Err(error) if error.kind() == std::io::ErrorKind::NotFound => {}+ Err(error) => {+ return Err(format!("failed to remove {}: {error}", path.display()).into());+ }+ }+ }++ Ok(())+}++fn generate_swift_bindings(+ generated_dir: &Path,+ uniffi_crate: &UniffiCrate<'_>,+) -> Result<(), DynError> {+ let source = uniffi_crate+ .crate_dir+ .join("target/release")+ .join(uniffi_crate.dylib_name);+ let source = utf8_path(&source)?;+ let out_dir = utf8_path(generated_dir)?;+ let previous_dir = env::current_dir().map_err(|error| {+ format!(+ "failed to capture current directory before generating {} bindings: {error}",+ uniffi_crate.crate_name+ )+ })?;++ env::set_current_dir(&uniffi_crate.crate_dir).map_err(|error| {+ format!(+ "failed to enter {} before generating bindings: {error}",+ uniffi_crate.crate_dir.display()+ )+ })?;++ let result = bindings::generate(GenerateOptions {+ languages: vec![TargetLanguage::Swift],+ source,+ out_dir,+ config_override: None,+ format: false,+ crate_filter: Some(uniffi_crate.crate_name.to_owned()),+ metadata_no_deps: false,+ });++ env::set_current_dir(&previous_dir).map_err(|error| {+ format!(+ "failed to restore current directory to {}: {error}",+ previous_dir.display()+ )+ })?;++ result?;++ Ok(())+}++fn sanitize_generated_swift_bindings(swift_file: &Path, crate_name: &str) -> Result<(), DynError> {+ let original = fs::read_to_string(swift_file)+ .map_err(|error| format!("failed to read {}: {error}", swift_file.display()))?;+ let free_call_prefix = format!("try! rustCall {{ uniffi_{crate_name}_fn_free_");++ let mut rewritten = String::with_capacity(original.len());+ let mut replaced = false;++ for segment in original.split_inclusive('\n') {+ let line = segment.strip_suffix('\n').unwrap_or(segment);+ let trimmed = line.trim_start();++ if trimmed.starts_with(&free_call_prefix) && trimmed.ends_with("(handle, $0) }") {+ let indent = &line[..line.len() - trimmed.len()];+ rewritten.push_str(indent);+ rewritten.push_str("// Avoid aborting the host app if Rust-side teardown fails during process shutdown.\n");+ rewritten.push_str(indent);+ rewritten.push_str(&line.replacen("try!", "try?", 1));+ if segment.ends_with('\n') {+ rewritten.push('\n');+ }+ replaced = true;+ } else {+ rewritten.push_str(segment);+ }+ }++ if replaced {+ fs::write(swift_file, rewritten)+ .map_err(|error| format!("failed to write {}: {error}", swift_file.display()))?;+ }++ Ok(())+}++fn utf8_path(path: &Path) -> Result<Utf8PathBuf, DynError> {+ Utf8PathBuf::from_path_buf(path.to_path_buf())+ .map_err(|path| format!("path is not valid UTF-8: {}", path.display()).into())+}++fn run_command(command: &mut Command, error_context: String) -> Result<(), DynError> {+ let program = command.get_program().to_os_string();+ let args = command+ .get_args()+ .map(OsStr::to_os_string)+ .collect::<Vec<_>>();+ let status = command.status().map_err(|error| {+ format!(+ "{error_context}: failed to start {}: {error}",+ render_command(&program, &args)+ )+ })?;++ if status.success() {+ return Ok(());+ }++ Err(format!(+ "{error_context}: {} exited with status {status}",+ render_command(&program, &args)+ )+ .into())+}++fn render_command(program: &OsStr, args: &[std::ffi::OsString]) -> String {+ let mut parts = Vec::with_capacity(args.len() + 1);+ parts.push(program.to_string_lossy().into_owned());+ parts.extend(args.iter().map(|arg| arg.to_string_lossy().into_owned()));+ parts.join(" ")+}diff --git a/rust/apps/ensu/src-tauri/Cargo.lock b/rust/apps/ensu/src-tauri/Cargo.lockindex 8ebec98814..2e76547626 100644--- a/rust/apps/ensu/src-tauri/Cargo.lock+++ b/rust/apps/ensu/src-tauri/Cargo.lock@@ -2278,7 +2278,6 @@ name = "inference_rs"version = "0.1.0"dependencies = ["llama-cpp-2",- "llama-cpp-sys-2","parking_lot","self_cell","serde",