Skip to content

armgit / ente

Public Imported from GitHub
0

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

Merge remote-tracking branch 'upstream/main' into ensu-fix

Prateek Sunal81bb4b3f309b
diff --cc mobile/native/darwin/Apps/ensu/scripts/build-rust.sh
index 5c81a04116,79358c6722..2607ea2c81
--- a/mobile/native/darwin/Apps/ensu/scripts/build-rust.sh
+++ b/mobile/native/darwin/Apps/ensu/scripts/build-rust.sh
@@@ -55,57 -56,49 +56,98 @@@ enum BuildEndpointConfig
EOF
}
+bindings_missing() {
+ 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"; do
+ if [ ! -f "${binding}" ]; then
+ return 0
+ fi
+ done
+
+ 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}"
+ )
+}
+
+ensure_generated_bindings() {
+ if ! bindings_missing; then
+ return
+ fi
+
+ 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"
+}
+
+ensure_generated_bindings
write_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() {