From 92c9964ec8c5689f5442574f513746eaa8e7b144 Mon Sep 17 00:00:00 2001 From: Vladimir Burdukov Date: Wed, 27 May 2026 11:52:07 +0300 Subject: [PATCH] feat(swift): add make_local_swift_package.sh to build and patch WorldApp for local development - add make_local_swift_package.sh to build bedrock-swift and patch WorldApp's Package.swift to use the local build - extract Package.swift into a template to support the refactored build scripts - update local build output path to local_build/bedrock-swift --- swift/Package.swift.template | 24 +++++++++++++++ swift/archive_swift.sh | 49 ++++++++++--------------------- swift/local_swift.sh | 44 ++++++++------------------- swift/make_local_swift_package.sh | 37 +++++++++++++++++++++++ 4 files changed, 89 insertions(+), 65 deletions(-) create mode 100644 swift/Package.swift.template create mode 100755 swift/make_local_swift_package.sh diff --git a/swift/Package.swift.template b/swift/Package.swift.template new file mode 100644 index 00000000..dc125e93 --- /dev/null +++ b/swift/Package.swift.template @@ -0,0 +1,24 @@ +// 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: "Bedrock", + platforms: [ + .iOS(.v13) + ], + products: [ + .library( + name: "Bedrock", + targets: ["Bedrock"]), + ], + targets: [ + .target( + name: "Bedrock", + dependencies: ["BedrockFFI"], + path: "Sources/Bedrock" + ), + + ] +) diff --git a/swift/archive_swift.sh b/swift/archive_swift.sh index db2e8b0b..9da76586 100755 --- a/swift/archive_swift.sh +++ b/swift/archive_swift.sh @@ -4,6 +4,8 @@ set -e # Creates the dynamic Package.swift file for release. # Usage: ./archive_swift.sh --asset-url --checksum --release-version +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + # Initialize variables ASSET_URL="" CHECKSUM="" @@ -56,40 +58,21 @@ 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" ' +// { + print " .binaryTarget(" + print " name: \"BedrockFFI\"," + print " url: \"" url "\"," + print " checksum: \"" checksum "\"" + print " )" + next +} +{ print } +' "$SCRIPT_DIR/Package.swift.template" > Package.swift -let package = Package( - name: "Bedrock", - platforms: [ - .iOS(.v13) - ], - products: [ - .library( - name: "Bedrock", - targets: ["Bedrock"]), - ], - targets: [ - .target( - name: "Bedrock", - dependencies: ["BedrockFFI"], - path: "Sources/Bedrock" - ), - .binaryTarget( - name: "BedrockFFI", - url: "$ASSET_URL", - checksum: "$CHECKSUM" - ) - ] -) -EOF +echo "// Release version: $RELEASE_VERSION" >> Package.swift -swiftlint lint --autocorrect Package.swift +swiftlint lint --autocorrect Package.swift echo "" -echo "✅ Package.swift built successfully for version $RELEASE_VERSION!" \ No newline at end of file +echo "✅ Package.swift built successfully for version $RELEASE_VERSION!" diff --git a/swift/local_swift.sh b/swift/local_swift.sh index a69a2b6c..6131babf 100755 --- a/swift/local_swift.sh +++ b/swift/local_swift.sh @@ -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/bedrock-swift" # Local build artifacts directory FRAMEWORK="Bedrock.xcframework" echo "Building $FRAMEWORK for local iOS development" @@ -26,36 +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: "Bedrock", - platforms: [ - .iOS(.v13) - ], - products: [ - .library( - name: "Bedrock", - targets: ["Bedrock"]), - ], - targets: [ - .target( - name: "Bedrock", - dependencies: ["BedrockFFI"], - path: "Sources/Bedrock" - ), - .binaryTarget( - name: "BedrockFFI", - path: "Bedrock.xcframework" - ) - ] -) -EOF +awk -v path="$FRAMEWORK" ' +// { + print " .binaryTarget(" + print " name: \"BedrockFFI\"," + print " path: \"" path "\"" + print " )" + next +} +{ print } +' "$BASE_PATH/Package.swift.template" > "$LOCAL_BUILD_PATH/Package.swift" echo "" echo "✅ Swift package built successfully!" @@ -68,4 +48,4 @@ echo "2. Click 'Add Local...' and select the local_build directory: $LOCAL_BUILD echo "3. Or add it to your Package.swift dependencies:" echo " .package(path: \"$LOCAL_BUILD_PATH\")" echo "" -echo "The package exports the 'Bedrock' library that you can import in your Swift code." \ No newline at end of file +echo "The package exports the 'Bedrock' library that you can import in your Swift code." diff --git a/swift/make_local_swift_package.sh b/swift/make_local_swift_package.sh new file mode 100755 index 00000000..c17a259f --- /dev/null +++ b/swift/make_local_swift_package.sh @@ -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 bedrock-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/bedrock-swift" + +echo "Building the Bedrock Swift package..." +bash "$SCRIPT_DIR/local_swift.sh" + +echo "Finding Package.swift files that reference bedrock-swift..." +PACKAGE_FILES=$(grep -rl "worldcoin/bedrock-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/bedrock-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/bedrock-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."