Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions swift/Package.swift.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "WalletKit",
platforms: [
.iOS(.v13)
],
products: [
.library(
name: "WalletKit",
targets: ["WalletKit"]),
],
dependencies: [
.package(url: "https://github.com/attaswift/BigInt.git", .upToNextMajor(from: "5.7.0")),
],
targets: [
.target(
name: "WalletKit",
dependencies: [
"walletkit_coreFFI",
.product(name: "BigInt", package: "BigInt"),
],
path: "Sources/WalletKit"
),
<binary_target>
]
)
51 changes: 14 additions & 37 deletions swift/archive_swift.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -e
# Creates the dynamic Package.swift file for release.
# Usage: ./archive_swift.sh --asset-url <URL> --checksum <CHECKSUM> --release-version <VERSION>

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Initialize variables
ASSET_URL=""
CHECKSUM=""
Expand Down Expand Up @@ -56,44 +58,19 @@ echo " Checksum: $CHECKSUM"
echo " Release Version: $RELEASE_VERSION"
echo ""

cat > Package.swift << EOF
// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

// Release version: $RELEASE_VERSION

import PackageDescription
awk -v url="$ASSET_URL" -v checksum="$CHECKSUM" '
/<binary_target>/ {
print " .binaryTarget("
print " name: \"walletkit_coreFFI\","
print " url: \"" url "\","
print " checksum: \"" checksum "\""
print " )"
next
}
{ print }
' "$SCRIPT_DIR/Package.swift.template" > Package.swift

let package = Package(
name: "WalletKit",
platforms: [
.iOS(.v13)
],
products: [
.library(
name: "WalletKit",
targets: ["WalletKit"]),
],
dependencies: [
.package(url: "https://github.com/attaswift/BigInt.git", .upToNextMajor(from: "5.7.0")),
],
targets: [
.target(
name: "WalletKit",
dependencies: [
"walletkit_coreFFI",
.product(name: "BigInt", package: "BigInt"),
],
path: "Sources/WalletKit"
),
.binaryTarget(
name: "walletkit_coreFFI",
url: "$ASSET_URL",
checksum: "$CHECKSUM"
)
]
)
EOF
echo "// Release version: $RELEASE_VERSION" >> Package.swift

swiftlint lint --autocorrect Package.swift

Expand Down
48 changes: 11 additions & 37 deletions swift/local_swift.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -e

PROJECT_ROOT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BASE_PATH="$PROJECT_ROOT_PATH/swift" # The base path for the Swift build
LOCAL_BUILD_PATH="$BASE_PATH/local_build" # Local build artifacts directory
LOCAL_BUILD_PATH="$BASE_PATH/local_build/walletkit-swift" # Local build artifacts directory
FRAMEWORK="WalletKit.xcframework"

echo "Building $FRAMEWORK for local iOS development"
Expand All @@ -26,42 +26,16 @@ bash "$BASE_PATH/build_swift.sh" "$LOCAL_BUILD_PATH"

echo "Creating Package.swift for local development..."

# Create Package.swift for local development
cat > $LOCAL_BUILD_PATH/Package.swift << EOF
// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "WalletKit",
platforms: [
.iOS(.v13)
],
products: [
.library(
name: "WalletKit",
targets: ["WalletKit"]),
],
dependencies: [
.package(url: "https://github.com/attaswift/BigInt.git", from: "5.4.0"),
],
targets: [
.target(
name: "WalletKit",
dependencies: [
"walletkit_coreFFI",
.product(name: "BigInt", package: "BigInt"),
],
path: "Sources/WalletKit"
),
.binaryTarget(
name: "walletkit_coreFFI",
path: "WalletKit.xcframework"
)
]
)
EOF
awk -v path="$FRAMEWORK" '
/<binary_target>/ {
print " .binaryTarget("
print " name: \"walletkit_coreFFI\","
print " path: \"" path "\""
print " )"
next
}
{ print }
' "$BASE_PATH/Package.swift.template" > "$LOCAL_BUILD_PATH/Package.swift"

echo ""
echo "✅ Swift package built successfully!"
Expand Down
37 changes: 37 additions & 0 deletions swift/make_local_swift_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"

# Load local env overrides if present
[[ -f "$PROJECT_ROOT/.env" ]] && source "$PROJECT_ROOT/.env"

WORLD_APP_PATH="${1:-$WORLD_APP_PATH}"

if [ -z "$WORLD_APP_PATH" ]; then
echo "Error: Missing path to the WorldApp project. This is used to find and update the Package.swift that references walletkit-swift."
echo "Usage: $0 /Path/To/WorldApp"
echo "Or set WORLD_APP_PATH in .env"
exit 1
fi

LOCAL_BUILD_PATH="$SCRIPT_DIR/local_build/walletkit-swift"

echo "Building the WalletKit Swift package..."
bash "$SCRIPT_DIR/local_swift.sh"

echo "Finding Package.swift files that reference walletkit-swift..."
PACKAGE_FILES=$(grep -rl "worldcoin/walletkit-swift" "$WORLD_APP_PATH" --include="Package.swift" --exclude-dir=".build" --exclude-dir=".claude" || true)

if [ -z "$PACKAGE_FILES" ]; then
echo "Warning: No Package.swift found referencing worldcoin/walletkit-swift in $WORLD_APP_PATH"
exit 1
fi

while IFS= read -r pkg_file; do
echo "Patching $pkg_file..."
sed -i '' "s|\.package(url: \"https://github.com/worldcoin/walletkit-swift\", exact: \"[^\"]*\")|.package(path: \"$LOCAL_BUILD_PATH\")|" "$pkg_file"
done <<< "$PACKAGE_FILES"

echo "Done! In Xcode, make sure package resolution succeeds (via the Issue Navigator). You can get opaque build failures if the package isn't where the app expects it to be."