Skip to content

armgit / ente

Public Imported from GitHub
0

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

Get iOS simulator to build

laurenspriem5cca06b17410
diff --git a/mobile/apps/photos/rust/Cargo.toml b/mobile/apps/photos/rust/Cargo.toml
index 2e8c110c0e..03690c2f8d 100644
--- a/mobile/apps/photos/rust/Cargo.toml
+++ b/mobile/apps/photos/rust/Cargo.toml
@@ -17,9 +17,14 @@ kamadak-exif = "0.6.1"
nalgebra = "0.33.2"
ndarray = "0.16.1"
once_cell = "1.20.2"
-ort = { version = "2.0.0-rc.9", default-features = false, features = ["ndarray", "load-dynamic", "copy-dylibs", "coreml", "nnapi"] }
thiserror = "2.0.11"
+[target.'cfg(target_os = "ios")'.dependencies]
+ort = { version = "2.0.0-rc.9", default-features = false, features = ["std", "ndarray", "coreml"] }
+
+[target.'cfg(not(target_os = "ios"))'.dependencies]
+ort = { version = "2.0.0-rc.9", default-features = false, features = ["ndarray", "load-dynamic", "copy-dylibs", "coreml", "nnapi"] }
+
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(frb_expand)'] }
diff --git a/mobile/apps/photos/rust_builder/cargokit/build_pod.sh b/mobile/apps/photos/rust_builder/cargokit/build_pod.sh
index ed0e0d987d..2350e72a54 100755
--- a/mobile/apps/photos/rust_builder/cargokit/build_pod.sh
+++ b/mobile/apps/photos/rust_builder/cargokit/build_pod.sh
@@ -37,6 +37,32 @@ export CARGOKIT_TOOL_TEMP_DIR=$TARGET_TEMP_DIR/build_tool
# Directory inside root project. Not necessarily the top level directory of root project.
export CARGOKIT_ROOT_PROJECT_DIR=$SRCROOT
+# Configure ort-sys to link against the ONNX Runtime iOS xcframework instead of
+# relying on runtime dylib loading.
+if [[ -n "$PODS_ROOT" ]] && [[ -d "$PODS_ROOT/onnxruntime-c/onnxruntime.xcframework" ]]; then
+ ORT_XCFWK_LOCATION="$PODS_ROOT/onnxruntime-c/onnxruntime.xcframework"
+ export ORT_IOS_XCFWK_LOCATION="$ORT_XCFWK_LOCATION"
+
+ # ort-sys currently does not handle x86_64 iOS simulator triples for
+ # ORT_IOS_XCFWK_LOCATION, so provide ORT_LIB_LOCATION with a thin archive.
+ if [[ "$CARGOKIT_DARWIN_PLATFORM_NAME" == "iphonesimulator" ]] && [[ "$CARGOKIT_DARWIN_ARCHS" == "x86_64" ]]; then
+ ORT_SIM_LIB="$ORT_XCFWK_LOCATION/ios-arm64_x86_64-simulator/onnxruntime.framework/onnxruntime"
+ if [[ -f "$ORT_SIM_LIB" ]]; then
+ ORT_LIB_TEMP_DIR="$TARGET_TEMP_DIR/ort_sys_sim_x86_64"
+ mkdir -p "$ORT_LIB_TEMP_DIR"
+ lipo -thin x86_64 "$ORT_SIM_LIB" -output "$ORT_LIB_TEMP_DIR/libonnxruntime.a"
+ export ORT_LIB_LOCATION="$ORT_LIB_TEMP_DIR"
+
+ # Link the simulator clang runtime; ort-sys links the device variant for
+ # x86_64-apple-ios, which misses simulator-only symbols.
+ CLANG_RESOURCE_DIR="$(xcrun clang --print-resource-dir 2>/dev/null || true)"
+ if [[ -n "$CLANG_RESOURCE_DIR" ]] && [[ -d "$CLANG_RESOURCE_DIR/lib/darwin" ]]; then
+ export RUSTFLAGS="${RUSTFLAGS} -L native=${CLANG_RESOURCE_DIR}/lib/darwin -l clang_rt.iossim"
+ fi
+ fi
+ fi
+fi
+
FLUTTER_EXPORT_BUILD_ENVIRONMENT=(
"$PODS_ROOT/../Flutter/ephemeral/flutter_export_environment.sh" # macOS
"$PODS_ROOT/../Flutter/flutter_export_environment.sh" # iOS