Skip to content

Commit f23819a

Browse files
committed
chore: project restructure
1 parent 75bcfb0 commit f23819a

8 files changed

Lines changed: 83 additions & 39 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
22
resolver = "2"
3-
members = ["lib", "cli"]
3+
members = ["lib", "cli", "cktap-ffi"]
44

55
[profile.release-smaller]
66
inherits = "release"

cktap-ffi/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "cktap-ffi"
3+
version = "0.1.0"
4+
edition = "2021"
5+
license = "MIT"
6+
7+
[lib]
8+
name = "cktap_ffi"
9+
crate-type = ["staticlib", "cdylib"]
10+
11+
[dependencies]
12+
rust-cktap = { path = "../lib" }
13+
uniffi = { version = "0.29", features = ["cli"], optional = true }
14+
15+
[build-dependencies]
16+
uniffi = { version = "0.29", features = ["build"], optional = true }
17+
18+
[features]
19+
default = []
20+
uniffi = ["dep:uniffi"]

cktap-ffi/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#[cfg(feature = "uniffi")]
2+
uniffi::setup_scaffolding!();
3+
4+
pub use rust_cktap::{
5+
rand_chaincode, rand_nonce as core_rand_nonce, CkTapCard, Error, SatsCard, TapSigner,
6+
};
7+
8+
#[cfg(feature = "uniffi")]
9+
#[derive(uniffi::Object)]
10+
pub struct TestStruct {
11+
pub value: u32,
12+
}
13+
14+
#[cfg(feature = "uniffi")]
15+
#[uniffi::export]
16+
pub fn rand_nonce() -> Vec<u8> {
17+
core_rand_nonce().to_vec()
18+
}

cktap-swift/build-xcframework.sh

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@
55
TARGETDIR="../target"
66
OUTDIR="."
77
RELDIR="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+
818
NAME="cktapFFI"
9-
STATIC_LIB_NAME="lib${NAME}.a"
19+
STATIC_LIB_FILENAME="lib${FFI_LIB_NAME}.a"
1020
NEW_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

5568
cd 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
6286
rm -rf "${OUTDIR}/${NAME}.xcframework"
6387

6488
# create new xcframework directory from cktap-ffi static libs and headers
6589
xcodebuild -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+

lib/Cargo.toml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77
[lib]
8-
crate-type = ["lib", "staticlib", "cdylib"]
8+
crate-type = ["lib"]
99
name = "rust_cktap"
1010

1111

@@ -26,23 +26,13 @@ bitcoin = { version = "0.32", features = ["rand-std"] }
2626
# logging
2727
log = "0.4"
2828

29-
# uniffi
30-
uniffi = { version = "0.29", features = ["cli"], optional = true }
31-
29+
# pcsc as optional
3230
pcsc = { version = "2", optional = true }
3331

34-
[build-dependencies]
35-
uniffi = { version = "0.29.1", features = ["build"] }
36-
3732
[features]
38-
uniffi = ["dep:uniffi"]
3933
default = []
4034
emulator = []
4135

4236
[[example]]
4337
name = "pcsc"
4438
required-features = ["pcsc"]
45-
46-
[[bin]]
47-
name = "uniffi-bindgen"
48-
path = "src/uniffi-bindgen.rs"

lib/src/ffi.rs

Lines changed: 0 additions & 4 deletions
This file was deleted.

lib/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#[cfg(feature = "uniffi")]
2-
uniffi::setup_scaffolding!();
3-
41
extern crate core;
52

63
use bitcoin::key::rand::Rng as _;
@@ -15,9 +12,6 @@ pub use bitcoin::secp256k1::{self, rand};
1512
#[cfg(feature = "emulator")]
1613
pub mod emulator;
1714

18-
#[cfg(feature = "uniffi")]
19-
mod ffi;
20-
2115
#[cfg(feature = "pcsc")]
2216
pub mod pcsc;
2317
pub mod sats_card;

0 commit comments

Comments
 (0)