π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Regenerate Ensu Swift bindings during iOS builds
Prateek Sunalf0c63343ecb4
diff --git a/.gitignore b/.gitignoreindex a1ec2b4a2d..518d386d14 100644--- a/.gitignore+++ b/.gitignore@@ -21,6 +21,7 @@ node_modules/mobile/native/android/packages/rust/build/mobile/native/darwin/Packages/Rust/build/mobile/native/darwin/Apps/ensu/build/+mobile/native/darwin/Apps/ensu/build-native-check/target/# Generated native bindings / binaries (regenerate locally)diff --git a/mobile/native/darwin/Apps/ensu/README.md b/mobile/native/darwin/Apps/ensu/README.mdindex e810d60bfc..6e0a15888d 100644--- a/mobile/native/darwin/Apps/ensu/README.md+++ b/mobile/native/darwin/Apps/ensu/README.md@@ -32,8 +32,7 @@ Run `./build.sh --help` or `./run.sh --help` for full options.- `../Packages/Rust/InferenceRSFFI.xcframework`The Xcode build script (`scripts/build-rust.sh`) builds Rust static libs, but it does-not regenerate the Swift bindings. If bindings are missing, build the corresponding-`rust/uniffi/core` or `rust/uniffi/ensu/*` crate and run `uniffi-bindgen generate` to output into the paths above.+regenerate the `core`, `db`, and `sync` Swift bindings into `ensu/Generated/` as part of the build.`../Packages/Rust/tool/generate_bindings.sh` and `../Packages/Rust/tool/build_xcframework.sh`handle the InferenceRS bindings and xcframework.@@ -123,4 +122,3 @@ ENTE_API_ENDPOINT="https://your-endpoint.example" \-destination 'platform=iOS Simulator,name=iPhone 15' \-derivedDataPath build```-diff --git a/mobile/native/darwin/Apps/ensu/ensu.xcodeproj/project.pbxproj b/mobile/native/darwin/Apps/ensu/ensu.xcodeproj/project.pbxprojindex a4feaaae0c..7b77612f51 100644--- a/mobile/native/darwin/Apps/ensu/ensu.xcodeproj/project.pbxproj+++ b/mobile/native/darwin/Apps/ensu/ensu.xcodeproj/project.pbxproj@@ -329,6 +329,15 @@"$(TARGET_TEMP_DIR)/ensu_rust/libcore.a","$(TARGET_TEMP_DIR)/ensu_rust/libdb.a","$(TARGET_TEMP_DIR)/ensu_rust/libsync.a",+ "$(SRCROOT)/ensu/Generated/core.swift",+ "$(SRCROOT)/ensu/Generated/coreFFI.h",+ "$(SRCROOT)/ensu/Generated/coreFFI.modulemap",+ "$(SRCROOT)/ensu/Generated/db.swift",+ "$(SRCROOT)/ensu/Generated/dbFFI.h",+ "$(SRCROOT)/ensu/Generated/dbFFI.modulemap",+ "$(SRCROOT)/ensu/Generated/sync.swift",+ "$(SRCROOT)/ensu/Generated/syncFFI.h",+ "$(SRCROOT)/ensu/Generated/syncFFI.modulemap",);runOnlyForDeploymentPostprocessing = 0;shellPath = /bin/sh;@@ -346,6 +355,15 @@"$(TARGET_TEMP_DIR)/ensu_rust/libcore.a","$(TARGET_TEMP_DIR)/ensu_rust/libdb.a","$(TARGET_TEMP_DIR)/ensu_rust/libsync.a",+ "$(SRCROOT)/ensu/Generated/core.swift",+ "$(SRCROOT)/ensu/Generated/coreFFI.h",+ "$(SRCROOT)/ensu/Generated/coreFFI.modulemap",+ "$(SRCROOT)/ensu/Generated/db.swift",+ "$(SRCROOT)/ensu/Generated/dbFFI.h",+ "$(SRCROOT)/ensu/Generated/dbFFI.modulemap",+ "$(SRCROOT)/ensu/Generated/sync.swift",+ "$(SRCROOT)/ensu/Generated/syncFFI.h",+ "$(SRCROOT)/ensu/Generated/syncFFI.modulemap",);runOnlyForDeploymentPostprocessing = 0;shellPath = /bin/sh;diff --git a/mobile/native/darwin/Apps/ensu/scripts/build-rust.sh b/mobile/native/darwin/Apps/ensu/scripts/build-rust.shindex 47d4eaf404..79358c6722 100755--- a/mobile/native/darwin/Apps/ensu/scripts/build-rust.sh+++ b/mobile/native/darwin/Apps/ensu/scripts/build-rust.sh@@ -15,8 +15,10 @@ fiREPO_ROOT="$(cd "${SRCROOT}/../../../../.." && pwd)"OUT_DIR="${TARGET_TEMP_DIR}/ensu_rust"+GENERATED_DIR="${SRCROOT}/ensu/Generated"mkdir -p "${OUT_DIR}"+mkdir -p "${GENERATED_DIR}"# Use debug profile for Debug builds to speed iteration.CARGO_FLAGS="--locked"@@ -33,7 +35,7 @@ write_endpoint_config() {endpoint_value="${endpoint_value%%$'\n'*}"endpoint_value="$(echo "${endpoint_value}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"- generated_file="${SRCROOT}/ensu/Generated/EndpointConfig.swift"+ generated_file="${GENERATED_DIR}/EndpointConfig.swift"mkdir -p "$(dirname "${generated_file}")"if [ -n "${endpoint_value}" ]; then@@ -56,6 +58,47 @@ EOFwrite_endpoint_config+if [ "$(uname -s)" = "Darwin" ]; then+ HOST_LIB_EXT="dylib"+elif [ "$(uname -s)" = "Linux" ]; then+ HOST_LIB_EXT="so"+else+ HOST_LIB_EXT="dll"+fi++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}")+}+# Map Xcode platform+arch to Rust target triple.# Note: For iOS simulator on arm64, Rust uses aarch64-apple-ios-sim.rust_target_for() {@@ -125,6 +168,11 @@ HOST_SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"# Ensure host builds (build scripts) use the macOS SDK.export SDKROOT="${HOST_SDKROOT}"+ensure_uniffi_bindgen+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"+build_crate_universal() {crate_name="$1" # e.g. corecrate_dir="$2" # absolute pathdiff --git a/rust/uniffi/ensu/db/Cargo.lock b/rust/uniffi/ensu/db/Cargo.lockindex 30aa7ce90a..d6e4e236ab 100644--- a/rust/uniffi/ensu/db/Cargo.lock+++ b/rust/uniffi/ensu/db/Cargo.lock@@ -117,6 +117,26 @@ dependencies = ["serde",]+[[package]]+name = "bip39"+version = "2.2.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "90dbd31c98227229239363921e60fcf5e558e43ec69094d46fc4996f08d1d5bc"+dependencies = [+ "bitcoin_hashes",+ "serde",+ "unicode-normalization",+]++[[package]]+name = "bitcoin_hashes"+version = "0.14.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "26ec84b80c482df901772e931a9a681e26a1b9ee2302edeff23cb30328745c8b"+dependencies = [+ "hex-conservative",+]+[[package]]name = "bitflags"version = "2.10.0"@@ -402,6 +422,7 @@ version = "0.0.1"dependencies = ["argon2","base64",+ "bip39","blake2b_simd","crypto_secretstream","getrandom 0.2.17",@@ -638,6 +659,15 @@ version = "0.4.3"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"+[[package]]+name = "hex-conservative"+version = "0.2.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "fda06d18ac606267c40c04e41b9947729bf8b9efe74bd4e82b61a5f26a510b9f"+dependencies = [+ "arrayvec",+]+[[package]]name = "http"version = "1.4.0"@@ -1842,6 +1872,15 @@ version = "1.0.22"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"+[[package]]+name = "unicode-normalization"+version = "0.1.25"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8"+dependencies = [+ "tinyvec",+]+[[package]]name = "uniffi"version = "0.31.0"diff --git a/rust/uniffi/ensu/sync/Cargo.lock b/rust/uniffi/ensu/sync/Cargo.lockindex 7dad93e1d2..2b50df259d 100644--- a/rust/uniffi/ensu/sync/Cargo.lock+++ b/rust/uniffi/ensu/sync/Cargo.lock@@ -117,6 +117,26 @@ dependencies = ["serde",]+[[package]]+name = "bip39"+version = "2.2.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "90dbd31c98227229239363921e60fcf5e558e43ec69094d46fc4996f08d1d5bc"+dependencies = [+ "bitcoin_hashes",+ "serde",+ "unicode-normalization",+]++[[package]]+name = "bitcoin_hashes"+version = "0.14.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "26ec84b80c482df901772e931a9a681e26a1b9ee2302edeff23cb30328745c8b"+dependencies = [+ "hex-conservative",+]+[[package]]name = "bitflags"version = "2.10.0"@@ -407,6 +427,7 @@ version = "0.0.1"dependencies = ["argon2","base64",+ "bip39","blake2b_simd","crypto_secretstream","getrandom 0.2.17",@@ -653,6 +674,15 @@ version = "0.4.3"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"+[[package]]+name = "hex-conservative"+version = "0.2.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "fda06d18ac606267c40c04e41b9947729bf8b9efe74bd4e82b61a5f26a510b9f"+dependencies = [+ "arrayvec",+]+[[package]]name = "hkdf"version = "0.12.4"@@ -1898,6 +1928,15 @@ version = "1.0.22"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"+[[package]]+name = "unicode-normalization"+version = "0.1.25"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8"+dependencies = [+ "tinyvec",+]+[[package]]name = "uniffi"version = "0.31.0"