|
| 1 | +# iOS Mobile Builds For libp2p_ffi |
| 2 | + |
| 3 | +`cbind/libp2p_ffi.nim` is the supported C ABI target for iOS builds. The legacy |
| 4 | +`cbind/libp2p.nim` target is not extended for iOS. |
| 5 | + |
| 6 | +## Supported Targets |
| 7 | + |
| 8 | +The iOS build targets iOS 13.0 or newer by default and uses SDKs from an |
| 9 | +installed Xcode bundle: |
| 10 | + |
| 11 | +| Target | Nim CPU | SDK | Clang target | |
| 12 | +| --- | --- | --- | --- | |
| 13 | +| iOS device `arm64` | `arm64` | `iphoneos` | `arm64-apple-ios13.0` | |
| 14 | +| iOS simulator `arm64` | `arm64` | `iphonesimulator` | `arm64-apple-ios13.0-simulator` | |
| 15 | + |
| 16 | +These targets must be built on macOS with Xcode installed. They are not exposed |
| 17 | +on Linux Nix hosts because the iPhoneOS and iPhoneSimulator SDKs are provided by |
| 18 | +Xcode, not by nixpkgs. |
| 19 | + |
| 20 | +## Build Commands |
| 21 | + |
| 22 | +Build a single target on macOS: |
| 23 | + |
| 24 | +```sh |
| 25 | +nix build .#cbind-ffi-ios-arm64 |
| 26 | +nix build .#cbind-ffi-ios-simulator-arm64 |
| 27 | +``` |
| 28 | + |
| 29 | +Build both iOS layouts in one output: |
| 30 | + |
| 31 | +```sh |
| 32 | +nix build .#cbind-ffi-ios |
| 33 | +``` |
| 34 | + |
| 35 | +If your Nix installation uses sandboxing on macOS, disable it for this build so |
| 36 | +the derivation can access the host Xcode bundle and SDKs: |
| 37 | + |
| 38 | +```sh |
| 39 | +nix --extra-experimental-features "nix-command flakes" \ |
| 40 | + --option sandbox false \ |
| 41 | + build .#cbind-ffi-ios-arm64 |
| 42 | +``` |
| 43 | + |
| 44 | +## Artifact Layout |
| 45 | + |
| 46 | +Single-target outputs are flat: |
| 47 | + |
| 48 | +```text |
| 49 | +result/ |
| 50 | + bin/libp2p_ffi_ios_check |
| 51 | + include/libp2p.h |
| 52 | + include/nim_ffi_cbor.h |
| 53 | + include/nim_ffi_prelude.h |
| 54 | + include/tinycbor/... |
| 55 | + include/cddl_bindings/libp2p.cddl |
| 56 | + lib/liblibp2p.dylib |
| 57 | + lib/liblibp2p.a |
| 58 | + nix-support/ios-target |
| 59 | +``` |
| 60 | + |
| 61 | +The aggregate output nests the same layout by target: |
| 62 | + |
| 63 | +```text |
| 64 | +result/ios/arm64/... |
| 65 | +result/ios/simulator-arm64/... |
| 66 | +``` |
| 67 | + |
| 68 | +`liblibp2p.dylib` and `liblibp2p.a` intentionally keep the same naming as the |
| 69 | +host `cbind-ffi` package. |
| 70 | + |
| 71 | +## Downstream Linking Notes |
| 72 | + |
| 73 | +Use the generated high-level C helpers in `include/libp2p.h`: |
| 74 | + |
| 75 | +- `libp2p_ctx_create` |
| 76 | +- `libp2p_ctx_start` |
| 77 | +- `libp2p_ctx_stop` |
| 78 | +- `libp2p_ctx_destroy` |
| 79 | + |
| 80 | +The generated header uses TinyCBOR for request and response encoding. The Nix |
| 81 | +output installs the required TinyCBOR headers and C sources under |
| 82 | +`include/tinycbor`. Downstream C, C++, Objective-C, or Swift wrapper code that |
| 83 | +calls the generated helper functions should compile those TinyCBOR `.c` files |
| 84 | +into the app or a support library. |
| 85 | + |
| 86 | +For shared-library linking, package the matching target's `lib/liblibp2p.dylib` |
| 87 | +with the iOS application using the normal Xcode embedding/signing flow. For |
| 88 | +static linking, link `lib/liblibp2p.a` together with the C++ runtime selected by |
| 89 | +the application. |
| 90 | + |
| 91 | +## iOS Check Harness |
| 92 | + |
| 93 | +The Nix iOS derivation compiles `cbind/examples/libp2p_ffi_mobile_check.c` for |
| 94 | +each target. The harness includes the generated nim-ffi C header, creates a |
| 95 | +default TCP/Yamux node, starts it, stops it, destroys the context, and fails on |
| 96 | +callback errors or timeouts. |
| 97 | + |
| 98 | +The derivation only compiles and links the harness. It does not run the harness |
| 99 | +on a simulator or physical device. |
| 100 | + |
| 101 | +## CI Coverage |
| 102 | + |
| 103 | +`.github/workflows/mobile_ios.yml` runs on macOS and builds both iOS packages. |
| 104 | +The workflow checks that each output contains: |
| 105 | + |
| 106 | +- shared and static `liblibp2p` libraries |
| 107 | +- generated C headers and CDDL |
| 108 | +- TinyCBOR headers used by the generated C helper layer |
| 109 | +- the linked iOS check executable |
| 110 | +- Mach-O platform metadata matching the selected SDK |
| 111 | +- `arm64` architecture metadata for the dynamic library, static library, |
| 112 | + and check executable |
0 commit comments