Skip to content

Commit e8ed640

Browse files
feat(ios): simulator (#2833)
1 parent da61305 commit e8ed640

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

.github/workflows/mobile_ios.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,62 @@ jobs:
8585
8686
file "$out/lib/liblibp2p.dylib"
8787
file "$out/bin/libp2p_ffi_ios_check"
88+
89+
- name: Run FFI check on iOS simulator
90+
if: matrix.target == 'simulator-arm64'
91+
run: |
92+
out="$PWD/result-${{ matrix.target }}"
93+
run_dir="$RUNNER_TEMP/nim-libp2p-ios-sim"
94+
rm -rf "$run_dir"
95+
mkdir -p "$run_dir/bin" "$run_dir/lib"
96+
cp "$out/bin/libp2p_ffi_ios_check" "$run_dir/bin/"
97+
cp "$out/lib/liblibp2p.dylib" "$run_dir/lib/"
98+
chmod -R u+w "$run_dir"
99+
100+
install_name="$(otool -L "$run_dir/bin/libp2p_ffi_ios_check" | awk '/liblibp2p\.dylib/{print $1; exit}')"
101+
test -n "$install_name"
102+
install_name_tool -change "$install_name" "@executable_path/../lib/liblibp2p.dylib" "$run_dir/bin/libp2p_ffi_ios_check"
103+
install_name_tool -id "@rpath/liblibp2p.dylib" "$run_dir/lib/liblibp2p.dylib"
104+
codesign --force --sign - "$run_dir/lib/liblibp2p.dylib" "$run_dir/bin/libp2p_ffi_ios_check"
105+
106+
device_udid="$(
107+
xcrun simctl list devices --json | /usr/bin/python3 -c '
108+
import json
109+
import re
110+
import sys
111+
112+
def runtime_version(runtime):
113+
match = re.search(r"iOS-(\d+(?:[-.]\d+)*)", runtime)
114+
if not match:
115+
return ()
116+
return tuple(int(part) for part in re.split(r"[-.]", match.group(1)))
117+
118+
candidates = []
119+
for runtime, devices in json.load(sys.stdin)["devices"].items():
120+
if ".iOS-" not in runtime:
121+
continue
122+
for device in devices:
123+
availability = device.get("availability", "")
124+
if device.get("isAvailable") is False or "unavailable" in availability.lower():
125+
continue
126+
if not device.get("name", "").startswith("iPhone"):
127+
continue
128+
candidates.append((
129+
runtime_version(runtime),
130+
device.get("state") == "Shutdown",
131+
device.get("name", ""),
132+
device["udid"],
133+
))
134+
if not candidates:
135+
raise SystemExit("no available iPhone simulator device")
136+
print(max(candidates)[3])
137+
'
138+
)"
139+
cleanup() {
140+
xcrun simctl shutdown "$device_udid" || true
141+
}
142+
trap cleanup EXIT
143+
144+
xcrun simctl boot "$device_udid" || true
145+
xcrun simctl bootstatus "$device_udid" -b
146+
xcrun simctl spawn "$device_udid" "$run_dir/bin/libp2p_ffi_ios_check"

0 commit comments

Comments
 (0)