Skip to content

Commit 4b14523

Browse files
committed
fix: add ios bindings
1 parent 644a42c commit 4b14523

File tree

9 files changed

+152
-6
lines changed

9 files changed

+152
-6
lines changed

Package.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// swift-tools-version:5.5
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let tag = "v0.3.1"
7+
let checksum = "f5d926feb8c48c0e1e61d6d9bd958d2c0989ec188f2887aa78cf34ae97a5b083"
8+
let url = "https://github.com/synonymdev/vss-rust-client-ffi/releases/download/\(tag)/VssRustClientFfi.xcframework.zip"
9+
10+
let package = Package(
11+
name: "vss-rust-client-ffi",
12+
platforms: [
13+
.iOS(.v13),
14+
.macOS(.v11),
15+
],
16+
products: [
17+
.library(
18+
name: "VssRustClientFfi",
19+
targets: ["VssRustClientFfi", "VssRustClientFfiFFI"]),
20+
],
21+
targets: [
22+
.target(
23+
name: "VssRustClientFfi",
24+
dependencies: ["VssRustClientFfiFFI"],
25+
path: "./bindings/ios",
26+
sources: ["vss_rust_client_ffi.swift"]
27+
),
28+
.binaryTarget(
29+
name: "VssRustClientFfiFFI",
30+
url: url,
31+
checksum: checksum
32+
)
33+
]
34+
)
30.1 MB
Binary file not shown.

bindings/ios/VssRustClientFfi.xcframework/Info.plist

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<key>HeadersPath</key>
1111
<string>Headers</string>
1212
<key>LibraryIdentifier</key>
13-
<string>ios-arm64</string>
13+
<string>ios-arm64-simulator</string>
1414
<key>LibraryPath</key>
1515
<string>libvss_rust_client_ffi.a</string>
1616
<key>SupportedArchitectures</key>
@@ -19,14 +19,16 @@
1919
</array>
2020
<key>SupportedPlatform</key>
2121
<string>ios</string>
22+
<key>SupportedPlatformVariant</key>
23+
<string>simulator</string>
2224
</dict>
2325
<dict>
2426
<key>BinaryPath</key>
2527
<string>libvss_rust_client_ffi.a</string>
2628
<key>HeadersPath</key>
2729
<string>Headers</string>
2830
<key>LibraryIdentifier</key>
29-
<string>ios-arm64-simulator</string>
31+
<string>ios-arm64</string>
3032
<key>LibraryPath</key>
3133
<string>libvss_rust_client_ffi.a</string>
3234
<key>SupportedArchitectures</key>
@@ -35,8 +37,6 @@
3537
</array>
3638
<key>SupportedPlatform</key>
3739
<string>ios</string>
38-
<key>SupportedPlatformVariant</key>
39-
<string>simulator</string>
4040
</dict>
4141
</array>
4242
<key>CFBundlePackageType</key>

bindings/ios/VssRustClientFfi.xcframework/ios-arm64-simulator/Headers/module.modulemap renamed to bindings/ios/VssRustClientFfi.xcframework/ios-arm64-simulator/Headers/VssRustClientFfiFFI/module.modulemap

File renamed without changes.

bindings/ios/VssRustClientFfi.xcframework/ios-arm64-simulator/Headers/vss_rust_client_ffiFFI.h renamed to bindings/ios/VssRustClientFfi.xcframework/ios-arm64-simulator/Headers/VssRustClientFfiFFI/vss_rust_client_ffiFFI.h

File renamed without changes.

bindings/ios/VssRustClientFfi.xcframework/ios-arm64/Headers/module.modulemap renamed to bindings/ios/VssRustClientFfi.xcframework/ios-arm64/Headers/VssRustClientFfiFFI/module.modulemap

File renamed without changes.

bindings/ios/VssRustClientFfi.xcframework/ios-arm64/Headers/vss_rust_client_ffiFFI.h renamed to bindings/ios/VssRustClientFfi.xcframework/ios-arm64/Headers/VssRustClientFfiFFI/vss_rust_client_ffiFFI.h

File renamed without changes.

build_ios.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ cp bindings/ios/module.modulemap "bindings/ios/ios-arm64-sim/Headers/$UNIQUE_HEA
8484
# Create XCFramework
8585
echo "Creating XCFramework..."
8686
xcodebuild -create-xcframework \
87-
-library ./target/aarch64-apple-ios-sim/release/libvss_rust_client_ffi.a -headers "bindings/ios/ios-arm64-sim/Headers/$UNIQUE_HEADER_FOLDER" \
88-
-library ./target/aarch64-apple-ios/release/libvss_rust_client_ffi.a -headers "bindings/ios/ios-arm64/Headers/$UNIQUE_HEADER_FOLDER" \
87+
-library ./target/aarch64-apple-ios-sim/release/libvss_rust_client_ffi.a -headers "bindings/ios/ios-arm64-sim/Headers" \
88+
-library ./target/aarch64-apple-ios/release/libvss_rust_client_ffi.a -headers "bindings/ios/ios-arm64/Headers" \
8989
-output "bindings/ios/VssRustClientFfi.xcframework" \
9090
|| { echo "Failed to create XCFramework"; exit 1; }
9191

@@ -94,4 +94,18 @@ echo "Cleaning up temporary directories..."
9494
rm -rf "bindings/ios/ios-arm64"
9595
rm -rf "bindings/ios/ios-arm64-sim"
9696

97+
# Create zip file for distribution and checksum calculation
98+
echo "Creating XCFramework zip file..."
99+
rm -f ./bindings/ios/VssRustClientFfi.xcframework.zip
100+
ditto -c -k --sequesterRsrc --keepParent ./bindings/ios/VssRustClientFfi.xcframework ./bindings/ios/VssRustClientFfi.xcframework.zip || { echo "Failed to create zip file"; exit 1; }
101+
102+
# Compute checksum
103+
echo "Computing checksum..."
104+
CHECKSUM=`swift package compute-checksum ./bindings/ios/VssRustClientFfi.xcframework.zip` || { echo "Failed to compute checksum"; exit 1; }
105+
echo "New checksum: $CHECKSUM"
106+
107+
# Update Package.swift with the new checksum using Python script
108+
echo "Updating Package.swift with new checksum..."
109+
python3 ./update_package.py --checksum "$CHECKSUM" || { echo "Failed to update Package.swift"; exit 1; }
110+
97111
echo "iOS build process completed successfully!"

update_package.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import json
5+
import os
6+
import re
7+
import sys
8+
9+
10+
def run(new_checksum: str = None, new_tag: str = None):
11+
if new_checksum is None and new_tag is None:
12+
print('At least one of --checksum or --tag arguments must be provided.', file=sys.stderr)
13+
sys.exit(1)
14+
15+
if new_checksum is not None:
16+
if not new_checksum.isalnum():
17+
print('Checksum must be alphanumeric.', file=sys.stderr)
18+
sys.exit(1)
19+
20+
if not new_checksum.islower():
21+
print('Checksum must be lowercase.', file=sys.stderr)
22+
sys.exit(1)
23+
24+
try:
25+
int(new_checksum, 16)
26+
except:
27+
print('Checksum must be hexadecimal.', file=sys.stderr)
28+
sys.exit(1)
29+
30+
if new_tag is not None:
31+
if new_tag.strip() != new_tag:
32+
print('Tag must not contain any whitespace.', file=sys.stderr)
33+
sys.exit(1)
34+
35+
# Support both v0.3.1 and 0.3.1 formats
36+
tag_regex = re.compile("^v?\d+[.]\d+[.]\d+$")
37+
tag_match = tag_regex.match(new_tag)
38+
if tag_match is None:
39+
print('Tag must adhere to x.x.x or vx.x.x major/minor/patch format.', file=sys.stderr)
40+
sys.exit(1)
41+
42+
settings = [
43+
{'variable_name': 'checksum', 'value': new_checksum},
44+
{'variable_name': 'tag', 'value': new_tag},
45+
]
46+
47+
# Get the Package.swift path relative to this script
48+
script_dir = os.path.dirname(os.path.realpath(__file__))
49+
package_file_path = os.path.join(script_dir, 'Package.swift')
50+
51+
print(f'Updating: {package_file_path}')
52+
53+
original_package_file = None
54+
try:
55+
with open(package_file_path, 'r') as package_file_handle:
56+
original_package_file = package_file_handle.read()
57+
except Exception as e:
58+
print(f'Failed to read Package.swift file: {e}', file=sys.stderr)
59+
sys.exit(1)
60+
61+
package_file = original_package_file
62+
for current_setting in settings:
63+
current_variable_name = current_setting['variable_name']
64+
new_value = current_setting['value']
65+
if new_value is None:
66+
continue
67+
68+
print(f'Setting {current_variable_name}: {new_value}')
69+
70+
# Create regex pattern to match the let declaration
71+
regex = re.compile(f'(let[\s]+{current_variable_name}[\s]*=[\s]*)"([^"]*)"')
72+
73+
# Find and replace the value
74+
match = regex.search(package_file)
75+
if match:
76+
old_value = match.group(2)
77+
package_file = regex.sub(f'\\1"{new_value}"', package_file)
78+
print(f' Changed from: {old_value}')
79+
print(f' Changed to: {new_value}')
80+
else:
81+
print(f' Warning: Could not find {current_variable_name} in Package.swift', file=sys.stderr)
82+
83+
# Write the updated file
84+
try:
85+
with open(package_file_path, "w") as f:
86+
f.write(package_file)
87+
print('Successfully updated Package.swift')
88+
except Exception as e:
89+
print(f'Failed to write Package.swift file: {e}', file=sys.stderr)
90+
sys.exit(1)
91+
92+
93+
if __name__ == '__main__':
94+
parser = argparse.ArgumentParser(description='Update Package.swift with new checksum and/or tag')
95+
parser.add_argument('--checksum', type=str, help='new checksum of VssRustClientFfi.xcframework.zip', required=False, default=None)
96+
parser.add_argument('--tag', type=str, help='new release tag (e.g., v0.3.1)', required=False, default=None)
97+
args = parser.parse_args()
98+
run(new_checksum=args.checksum, new_tag=args.tag)

0 commit comments

Comments
 (0)