-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
178 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,22 @@ | ||
# Rust | ||
/target | ||
/Cargo.lock | ||
|
||
# IDE | ||
/.vscode | ||
/.idea | ||
.DS_Store | ||
|
||
# Swift | ||
.build/ | ||
.swiftpm/ | ||
/Packages/ | ||
*.xcodeproj/ | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
*.xcframework/ | ||
*.xcframework.zip | ||
Info.plist | ||
Sources | ||
lib*.a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
[workspace] | ||
members = ["lib","cli"] | ||
resolver = "2" | ||
members = ["lib", "cli"] | ||
|
||
[profile.release-smaller] | ||
inherits = "release" | ||
opt-level = 'z' | ||
lto = true | ||
codegen-units = 1 | ||
panic = "abort" | ||
strip = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/configuration/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// swift-tools-version:5.5 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "cktap-swift", | ||
platforms: [ | ||
.macOS(.v12), | ||
.iOS(.v15) | ||
], | ||
products: [ | ||
.library( | ||
name: "CKTap", | ||
targets: ["cktapFFI", "CKTap"]), | ||
], | ||
dependencies: [], | ||
targets: [ | ||
.binaryTarget( | ||
name: "cktapFFI", | ||
path: "./cktapFFI.xcframework"), | ||
.target( | ||
name: "CKTap", | ||
dependencies: ["cktapFFI"] | ||
), | ||
.testTarget( | ||
name: "CKTapTests", | ||
dependencies: ["CKTap"] | ||
) | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import XCTest | ||
import CKTap | ||
|
||
final class CKTapTests: XCTestCase { | ||
func testHelloRandom() throws { | ||
print("Hello!") | ||
let nonce = randNonce() | ||
print("Random: \(nonce)") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/bash | ||
|
||
# This script builds local cktap Swift language bindings and corresponding cktapFFI.xcframework. | ||
|
||
TARGETDIR="../target" | ||
OUTDIR="." | ||
RELDIR="release-smaller" | ||
NAME="cktapFFI" | ||
STATIC_LIB_NAME="lib${NAME}.a" | ||
NEW_HEADER_DIR="../target/include" | ||
|
||
# set required rust version and install component and targets | ||
rustup default 1.77.1 | ||
rustup component add rust-src | ||
rustup target add aarch64-apple-ios # iOS arm64 | ||
rustup target add x86_64-apple-ios # iOS x86_64 | ||
rustup target add aarch64-apple-ios-sim # simulator mac M1 | ||
rustup target add aarch64-apple-darwin # mac M1 | ||
rustup target add x86_64-apple-darwin # mac x86_64 | ||
|
||
# Create all required directories first | ||
mkdir -p Sources/CKTap | ||
mkdir -p ../target/include | ||
mkdir -p ../target/lipo-macos/release-smaller | ||
mkdir -p ../target/lipo-ios-sim/release-smaller | ||
|
||
cd ../ || exit | ||
|
||
# build cktap-ffi rust lib for apple targets | ||
cargo build --package rust-cktap --profile release-smaller --target x86_64-apple-darwin | ||
cargo build --package rust-cktap --profile release-smaller --target aarch64-apple-darwin | ||
cargo build --package rust-cktap --profile release-smaller --target x86_64-apple-ios | ||
cargo build --package rust-cktap --profile release-smaller --target aarch64-apple-ios | ||
cargo build --package rust-cktap --profile release-smaller --target aarch64-apple-ios-sim | ||
|
||
# Then run uniffi-bindgen | ||
cargo run --bin uniffi-bindgen generate \ | ||
--library target/aarch64-apple-ios/release-smaller/librust_cktap.dylib \ | ||
--language swift \ | ||
--out-dir cktap-swift/Sources/CKTap \ | ||
--no-format | ||
|
||
# combine cktap-ffi static libs for aarch64 and x86_64 targets via lipo tool | ||
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/libcktapFFI.a | ||
|
||
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/libcktapFFI.a | ||
|
||
cd cktap-swift || exit | ||
|
||
# move cktap-ffi static lib header files to temporary directory | ||
mv "Sources/CKTap/rust_cktapFFI.h" "${NEW_HEADER_DIR}" | ||
mv "Sources/CKTap/rust_cktapFFI.modulemap" "${NEW_HEADER_DIR}/module.modulemap" | ||
|
||
# remove old xcframework directory | ||
rm -rf "${OUTDIR}/${NAME}.xcframework" | ||
|
||
# create new xcframework directory from cktap-ffi static libs and headers | ||
xcodebuild -create-xcframework \ | ||
-library "${TARGETDIR}/lipo-macos/${RELDIR}/librust_cktap.a" \ | ||
-headers "${NEW_HEADER_DIR}" \ | ||
-library "${TARGETDIR}/aarch64-apple-ios/${RELDIR}/librust_cktap.a" \ | ||
-headers "${NEW_HEADER_DIR}" \ | ||
-library "${TARGETDIR}/lipo-ios-sim/${RELDIR}/librust_cktap.a" \ | ||
-headers "${NEW_HEADER_DIR}" \ | ||
-output "${OUTDIR}/${NAME}.xcframework" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
default: | ||
just --list | ||
|
||
build: | ||
bash ./build-xcframework.sh | ||
|
||
clean: | ||
rm -rf ../rust-cktap-ffi/target/ | ||
|
||
test: | ||
swift test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
uniffi::generate_scaffolding("src/rust-cktap.udl").expect("Failed to generate FFI scaffolding"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
uniffi::include_scaffolding!("rust-cktap"); | ||
|
||
extern crate core; | ||
pub extern crate secp256k1; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace rust_cktap { | ||
sequence<u8> rand_nonce(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
uniffi::uniffi_bindgen_main() | ||
} |