Wire local TDLib into iOS FFI build

This commit is contained in:
Mikhail Kilin
2026-05-21 15:27:59 +03:00
parent aec3678bd6
commit 217328505c
34 changed files with 24460 additions and 28 deletions

View File

@@ -7,7 +7,7 @@ Local toolchain status:
- `scripts/check-ios-prereqs.sh` passes.
- `scripts/run-ios-simulator-app.sh` launches the fake-backed SwiftUI shell in iOS Simulator.
Current real TDLib blocker:
Previous real TDLib blocker:
```bash
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer cargo build -p tele-ios-ffi --target aarch64-apple-ios-sim --release
@@ -25,10 +25,83 @@ Interpretation:
- Rust, Swift, Xcode, and the iOS simulator runtime are working.
- The fake-backed iOS app shell can be built, installed, launched, and rendered.
- Real TDLib iOS linking is blocked because `tdlib-rs` 1.2.0 does not publish the iOS static library artifact requested by its `download-tdlib` build script.
- `download-tdlib` cannot be used for iOS because `tdlib-rs` 1.2.0 does not publish the iOS artifact requested by its build script.
Next viable paths:
Current real TDLib status:
1. Build TDLib for `iphoneos` and `iphonesimulator` locally and switch the Rust dependency path to `local-tdlib` or `pkg-config`.
2. Add a fake-only `tele-ios-ffi` build feature that avoids linking TDLib for simulator UI work, while keeping real TDLib behind a separate feature.
3. Replace the `tdlib-rs` packaging path for iOS with a lower-level C ABI/XCFramework if UniFFI plus `tdlib-rs` cannot link cleanly on device.
- `scripts/build-tdlib-ios.sh` builds TDLib `1.8.29` locally for iOS device and simulator.
- `.build/tdlib-ios/iphoneos/lib/libtdjson.1.8.29.dylib` is `arm64`.
- `.build/tdlib-ios/iphonesimulator/lib/libtdjson.1.8.29.dylib` is a universal `x86_64` + `arm64` simulator dylib.
- `scripts/check-ios-tdlib-linking.sh` builds `tele-ios-ffi` for `aarch64-apple-ios-sim` with local TDLib.
- `IOS_RUST_TARGET=aarch64-apple-ios scripts/build-ios-ffi-with-local-tdlib.sh` builds `tele-ios-ffi` for device with local TDLib.
- `scripts/build-ios-real-ffi-xcframework.sh` packages simulator Rust slices into `tele_ios_ffi.xcframework`, packages local `libtdjson` into `tdjson.xcframework`, and writes generated Swift bindings into the Swift package's local `Generated` path.
- `TELE_IOS_USE_LOCAL_FFI=1 scripts/build-ios-simulator-app.sh` builds and packages the SwiftUI simulator app against the real Rust/TDLib FFI path, including `Frameworks/libtdjson.dylib` in the `.app` bundle.
- The repo patches `tdlib-rs` through `crates/vendor/tdlib-rs` because upstream `src/build.rs` does not handle `target_os = "ios"` for `local-tdlib`.
Selected path:
1. Keep `download-tdlib` for the terminal/macOS build path.
2. Build TDLib locally for iOS and iOS Simulator from the TDLib source commit matching TDLib `1.8.29`.
3. Build `tele-ios-ffi` with `tele-core/tdlib-local` and `LOCAL_TDLIB_PATH`.
4. Package the resulting Rust FFI library and TDLib dylib into the iOS app/XCFramework path.
The TDLib source commit used for `1.8.29` is:
```text
af69dd4397b6dc1bf23ba0fd0bf429fcba6454f6
```
This can be checked with:
```bash
npm info prebuilt-tdlib@td-1.8.29 tdlib --json
```
Build local TDLib artifacts:
```bash
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer scripts/build-tdlib-ios.sh
```
This writes local, untracked outputs to:
```text
.build/tdlib-ios/iphoneos/
.build/tdlib-ios/iphonesimulator/
```
Build the real iOS FFI path against local TDLib:
```bash
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer scripts/build-ios-ffi-with-local-tdlib.sh
```
or for a device target:
```bash
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer IOS_RUST_TARGET=aarch64-apple-ios scripts/build-ios-ffi-with-local-tdlib.sh
```
Package the real FFI path for the Swift app and build the simulator `.app`:
```bash
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer scripts/build-ios-real-ffi-xcframework.sh
TELE_IOS_USE_LOCAL_FFI=1 DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer scripts/build-ios-simulator-app.sh
```
Known local prerequisites:
- Xcode with the iOS SDK installed.
- Homebrew build tools: `brew install cmake gperf coreutils`.
- Rust iOS targets: `rustup target add aarch64-apple-ios-sim aarch64-apple-ios`.
- `scripts/build-tdlib-ios.sh` builds only the required OpenSSL platforms through TDLib's vendored `Python-Apple-support` flow, with a local patch for the simulator target triple under Xcode 26.
- TDLib CMake uses `TDLIB_IOS_DEPLOYMENT_TARGET=17.0` by default to match the Swift package minimum iOS version.
- TDLib's `prepare_cross_compiling` target is run as a host-side generation step before cross-compiling, so generated TL/MIME sources exist for the iOS build.
Example local blocker if these tools are missing:
```text
Required tool not found: cmake
```
CMake 4.x compatibility is handled by passing `-DCMAKE_POLICY_VERSION_MINIMUM=3.5` to TDLib's configure step.