55TARGETDIR=" ../target"
66OUTDIR=" ."
77RELDIR=" release-smaller"
8+
9+ FFI_LIB_NAME=" cktap_ffi"
10+ FFI_PKG_NAME=" cktap-ffi"
11+
12+ DYLIB_FILENAME=" lib${FFI_LIB_NAME} .dylib"
13+ HEADER_BASENAME=" ${FFI_LIB_NAME} FFI"
14+ HEADER_FILENAME=" ${HEADER_BASENAME} .h"
15+ MODULEMAP_FILENAME=" module.modulemap"
16+ GENERATED_MODULEMAP=" ${FFI_LIB_NAME} FFI.modulemap"
17+
818NAME=" cktapFFI"
9- STATIC_LIB_NAME =" lib${NAME } .a"
19+ STATIC_LIB_FILENAME =" lib${FFI_LIB_NAME } .a"
1020NEW_HEADER_DIR=" ../target/include"
1121
1222# set required rust version and install component and targets
@@ -28,46 +38,62 @@ cd ../ || exit
2838
2939# Target architectures
3040# macOS Intel
31- cargo build --package rust-cktap --profile release-smaller --target x86_64-apple-darwin
41+ cargo build --package ${FFI_PKG_NAME} --features uniffi --profile ${RELDIR} --target x86_64-apple-darwin
3242# macOS Apple Silicon
33- cargo build --package rust-cktap --profile release-smaller --target aarch64-apple-darwin
43+ cargo build --package ${FFI_PKG_NAME} --features uniffi --profile ${RELDIR} --target aarch64-apple-darwin
3444# Simulator on Intel Macs
35- cargo build --package rust-cktap --profile release-smaller --target x86_64-apple-ios
45+ cargo build --package ${FFI_PKG_NAME} --features uniffi --profile ${RELDIR} --target x86_64-apple-ios
3646# Simulator on Apple Silicon Mac
37- cargo build --package rust-cktap --profile release-smaller --target aarch64-apple-ios-sim
47+ cargo build --package ${FFI_PKG_NAME} --features uniffi --profile ${RELDIR} --target aarch64-apple-ios-sim
3848# iPhone devices
39- cargo build --package rust-cktap --profile release-smaller --target aarch64-apple-ios
49+ cargo build --package ${FFI_PKG_NAME} --features uniffi --profile ${RELDIR} --target aarch64-apple-ios
4050
4151# Then run uniffi-bindgen
42- cargo run --bin uniffi-bindgen generate \
43- --features uniffi \
44- --library target/aarch64-apple-ios/release-smaller/librust_cktap.dylib \
52+ cargo run --package ${FFI_PKG_NAME} --bin uniffi-bindgen --features uniffi generate \
53+ --library target/aarch64-apple-ios/${RELDIR} /${DYLIB_FILENAME} \
4554 --language swift \
4655 --out-dir cktap-swift/Sources/CKTap \
4756 --no-format
4857
4958# Create universal library for simulator targets
50- lipo target/aarch64-apple-ios-sim/release-smaller/librust_cktap.a target/x86_64-apple-ios/release-smaller/librust_cktap.a -create -output target/lipo-ios-sim/release-smaller/librust_cktap.a
59+ lipo target/aarch64-apple-ios-sim/${RELDIR} /${STATIC_LIB_FILENAME} \
60+ target/x86_64-apple-ios/${RELDIR} /${STATIC_LIB_FILENAME} \
61+ -create -output target/lipo-ios-sim/${RELDIR} /${STATIC_LIB_FILENAME}
5162
5263# Create universal library for mac targets
53- lipo target/aarch64-apple-darwin/release-smaller/librust_cktap.a target/x86_64-apple-darwin/release-smaller/librust_cktap.a -create -output target/lipo-macos/release-smaller/librust_cktap.a
64+ lipo target/aarch64-apple-darwin/${RELDIR} /${STATIC_LIB_FILENAME} \
65+ target/x86_64-apple-darwin/${RELDIR} /${STATIC_LIB_FILENAME} \
66+ -create -output target/lipo-macos/${RELDIR} /${STATIC_LIB_FILENAME}
5467
5568cd cktap-swift || exit
5669
5770# move cktap-ffi static lib header files to temporary directory
58- mv " Sources/CKTap/rust_cktapFFI.h" " ${NEW_HEADER_DIR} "
59- mv " Sources/CKTap/rust_cktapFFI.modulemap" " ${NEW_HEADER_DIR} /module.modulemap"
71+ if [ -f " Sources/CKTap/${HEADER_FILENAME} " ]; then
72+ mv " Sources/CKTap/${HEADER_FILENAME} " " ${NEW_HEADER_DIR} /"
73+ else
74+ echo " Warning: Could not find header file Sources/CKTap/${HEADER_FILENAME} "
75+ fi
76+
77+ # Handle modulemap using the correct filename pattern
78+ if [ -f " Sources/CKTap/${GENERATED_MODULEMAP} " ]; then
79+ mv " Sources/CKTap/${GENERATED_MODULEMAP} " " ${NEW_HEADER_DIR} /${MODULEMAP_FILENAME} "
80+ else
81+ echo " Creating a standard module map."
82+ echo " framework module ${NAME} { umbrella header \" ${HEADER_FILENAME} \" export * }" > " ${NEW_HEADER_DIR} /${MODULEMAP_FILENAME} "
83+ fi
6084
6185# remove old xcframework directory
6286rm -rf " ${OUTDIR} /${NAME} .xcframework"
6387
6488# create new xcframework directory from cktap-ffi static libs and headers
6589xcodebuild -create-xcframework \
66- -library " ${TARGETDIR} /lipo-macos/${RELDIR} /librust_cktap.a " \
90+ -library " ${TARGETDIR} /lipo-macos/${RELDIR} /${STATIC_LIB_FILENAME} " \
6791 -headers " ${NEW_HEADER_DIR} " \
68- -library " ${TARGETDIR} /aarch64-apple-ios/${RELDIR} /librust_cktap.a " \
92+ -library " ${TARGETDIR} /aarch64-apple-ios/${RELDIR} /${STATIC_LIB_FILENAME} " \
6993 -headers " ${NEW_HEADER_DIR} " \
70- -library " ${TARGETDIR} /lipo-ios-sim/${RELDIR} /librust_cktap.a " \
94+ -library " ${TARGETDIR} /lipo-ios-sim/${RELDIR} /${STATIC_LIB_FILENAME} " \
7195 -headers " ${NEW_HEADER_DIR} " \
7296 -output " ${OUTDIR} /${NAME} .xcframework"
7397
98+ echo " Building Swift package completed."
99+
0 commit comments