Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
dependencies ▾

Modern-Apps.git / apple / XCFramework / BUILD_NOTES.md

BUILD_NOTES.md4.2 KiBRenderedCodeRaw
1# XCFramework build — `EverysyncCore.xcframework` (Phase 3, Mac only)
2
3Builds the shared KMP core (`library/everysync-core`) as an XCFramework with
4the `iosArm64 + iosSimulatorArm64` slices, linked against the Rust `e2ee_pqc`
5static lib for the 10 PQC cinterop functions. Swift never calls Rust directly
6— only via this XCFramework.
7
8> Requires macOS + Xcode. This directory holds the script + interface docs;
9> nothing here runs on the Windows box. Verified by inspection only.
10
11## Prerequisites (Mac)
12
13- Xcode 15+ with iOS 17 SDK (`xcode-select -p` points at it).
14- Rust targets: `rustup target add aarch64-apple-ios aarch64-apple-ios-sim`
15 (simulator slice is ARM64-only — no Intel slice; Rosetta fallback is out
16 of scope for Phase 3).
17- `cbindgen` (`cargo install cbindgen`) — generates `e2ee_pqc.h` from
18 `library/e2ee-p2p/src/main/rust/src/c_bridge.rs`.
19- KMP iOS plugin version == Kotlin version (see
20 `gradle/libs.versions.toml`); `iosArm64 + iosSimulatorArm64` targets in
21 `library/everysync-core/build.gradle.kts`.
22
23## Steps
24
251. Build the Rust static lib per slice (from repo root):
26 ```sh
27 cargo build --target aarch64-apple-ios --release \
28 --manifest-path library/e2ee-p2p/src/main/rust/Cargo.toml
29 cargo build --target aarch64-apple-ios-sim --release \
30 --manifest-path library/e2ee-p2p/src/main/rust/Cargo.toml
31 ```
32 NOTE: `IOS_PQC_NOTES.md` says `x86_64-apple-ios` for the simulator slice;
33 that target is Intel-only and wrong for Apple-Silicon simulators. This doc
34 uses `aarch64-apple-ios-sim` — the drift is recorded in
35 `../IPC_CONTRACT.md` appendix review notes (contract semantics unaffected;
36 only the build target triple changed).
372. Generate the C header (consumed by `e2eePqc.def`):
38 ```sh
39 cbindgen --crate e2ee-p2p --output e2ee_pqc.h \
40 --config library/e2ee-p2p/src/main/rust/cbindgen.toml
41 ```
42 (If no `cbindgen.toml` exists, create one pinning `language = "C"`,
43 `usize_is_size_t = true`, and the `pqc_` export prefix. The reference
44 header `e2ee_pqc.reference.h` in this directory shows the expected 10-fn
45 surface.)
463. Place `e2ee_pqc.h` in `src/nativeInterop/cinterop/e2eePqc/` next to
47 `e2eePqc.def` (see `IOS_PQC_NOTES.md` for the canonical `.def` text —
48 copied verbatim into `e2eePqc.def` here).
494. Build the XCFramework:
50 ```sh
51 ./gradlew :library:everysync-core:assembleEverysyncCoreXCFramework
52 ```
53 (Task name must match the KMP `XCFramework` block the Mac adds to the
54 module build file in Phase 3 — confirm on the Mac.)
55 Equivalent manual slice assembly (if the Gradle task is unavailable):
56 ```sh
57 ./gradlew :library:everysync-core:compileKotlinIosArm64 \
58 :library:everysync-core:compileKotlinIosSimulatorArm64
59 xcodebuild -create-xcframework \
60 -library <iosArm64 .a> -headers <generated headers> \
61 -library <simArm64 .a> -headers <generated headers> \
62 -output EverysyncCore.xcframework
63 ```
64 Or run `./build_xcframework.sh` in this directory (wraps steps 1–4).
655. Link the XCFramework into the three app targets + the Credential Provider
66 extension + the Share extension (all five link the SAME XCFramework —
67 merge/match/TOTP stay single-sourced).
686. Re-run relay conformance from the iOS simulator against Android + desktop
69 (see `../E2E_CHECKLIST.md`): register/getkey/append/pull, channel-name
70 assertions, `B64(AES_GCM)` record shape, double-wrapped
71 roster/epoch/transfer envelopes, PQC-sealed invite to `inbox:<device>`,
72 `everysync://join` parse, plus the three invariants (null-on-failed-pull
73 abort, tombstone-only delete, keys-never-visible).
74
75## Memory discipline (matches JNA)
76
77Every `*mut u8 + len` out-param buffer from the 10 PQC fns is `Box::into_raw`
78— the Kotlin cinterop actual copies to a `ByteArray`, then calls `pqc_free`;
79priv/SS bytes are zeroed via `pqc_secure_zero`. The two CryptoKit bridge fns
80(`everysync_aes_gcm_encrypt/decrypt` in `../Shared/EverysyncCoreCrypto.swift`)
81follow the same discipline via `everysync_crypto_free`.
82
83## What Swift must NOT do
84
85Re-implement merge pairing, TOTP framing/math, canonical JSON/hash, envelope
86Base64/AES, role checks, or link parsing. If logic exists in Swift that also
87exists in `everysync-core`, delete the Swift copy.