diff --git a/.github/build.sh b/.github/build.sh index 575b6f8..8aa2d32 100644 --- a/.github/build.sh +++ b/.github/build.sh @@ -1,83 +1,55 @@ #!/bin/bash -set -euo pipefail -# Enable debug output -set -x +set -e -# Define paths -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd -P)" -PROJECT_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")" -PROJECT_BUILD_DIR="${PROJECT_ROOT}/build" -SCHEME="RunveyKit" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd -P)" +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" -echo "Current directory: $(pwd)" -echo "Swift version:" -swift --version +PROJECT_BUILD_DIR="${PROJECT_BUILD_DIR:-"${PROJECT_ROOT}/build"}" +XCODEBUILD_BUILD_DIR="$PROJECT_BUILD_DIR/xcodebuild" +XCODEBUILD_DERIVED_DATA_PATH="$XCODEBUILD_BUILD_DIR/DerivedData" -# Function to build framework build_framework() { local sdk="$1" local destination="$2" - local archive_path="${PROJECT_BUILD_DIR}/${SCHEME}-${sdk}.xcarchive" - - echo "Building for ${sdk}..." - mkdir -p "${PROJECT_BUILD_DIR}" - - # Clean previous archive if exists - rm -rf "${archive_path}" - - echo "Running xcodebuild..." + local scheme="$3" + + local XCODEBUILD_ARCHIVE_PATH="./$scheme-$sdk.xcarchive" + + rm -rf "$XCODEBUILD_ARCHIVE_PATH" + xcodebuild archive \ - -scheme "${SCHEME}" \ - -archivePath "${archive_path}" \ - -sdk "${sdk}" \ - -destination "${destination}" \ + -scheme $scheme \ + -archivePath $XCODEBUILD_ARCHIVE_PATH \ + -derivedDataPath "$XCODEBUILD_DERIVED_DATA_PATH" \ + -sdk "$sdk" \ + -destination "$destination" \ BUILD_LIBRARY_FOR_DISTRIBUTION=YES \ - SKIP_INSTALL=NO \ - BUILD_DIR="${PROJECT_BUILD_DIR}/build" \ - OBJROOT="${PROJECT_BUILD_DIR}/build" \ - SYMROOT="${PROJECT_BUILD_DIR}/build" \ - | tee "${PROJECT_BUILD_DIR}/xcodebuild-${sdk}.log" | xcpretty || { - echo "xcodebuild failed. Full log:" - cat "${PROJECT_BUILD_DIR}/xcodebuild-${sdk}.log" - exit 1 - } - - # Verify archive was created - if [ ! -d "${archive_path}" ]; then - echo "Error: Archive not created at ${archive_path}" - exit 1 - fi - - # Verify framework exists in archive - if [ ! -d "${archive_path}/Products/Library/Frameworks/${SCHEME}.framework" ]; then - echo "Error: Framework not found in archive" - ls -la "${archive_path}/Products/Library/Frameworks" || true - exit 1 - fi -} + INSTALL_PATH='Library/Frameworks' \ + OTHER_SWIFT_FLAGS=-no-verify-emitted-module-interface \ + LD_GENERATE_MAP_FILE=YES -main() { - # Build for different architectures - build_framework "iphoneos" "generic/platform=iOS" - build_framework "iphonesimulator" "generic/platform=iOS Simulator" - - # Create XCFramework - echo "Creating XCFramework..." - rm -rf "${SCHEME}.xcframework" - - xcodebuild -create-xcframework \ - -framework "${PROJECT_BUILD_DIR}/${SCHEME}-iphonesimulator.xcarchive/Products/Library/Frameworks/${SCHEME}.framework" \ - -framework "${PROJECT_BUILD_DIR}/${SCHEME}-iphoneos.xcarchive/Products/Library/Frameworks/${SCHEME}.framework" \ - -output "${SCHEME}.xcframework" - - # Verify XCFramework was created - if [ ! -d "${SCHEME}.xcframework" ]; then - echo "Error: XCFramework not created" - exit 1 - fi - - echo "Build completed successfully." + FRAMEWORK_MODULES_PATH="$XCODEBUILD_ARCHIVE_PATH/Products/Library/Frameworks/$scheme.framework/Modules" + mkdir -p "$FRAMEWORK_MODULES_PATH" + cp -r \ + "$XCODEBUILD_DERIVED_DATA_PATH/Build/Intermediates.noindex/ArchiveIntermediates/$scheme/BuildProductsPath/Release-$sdk/$scheme.swiftmodule" \ + "$FRAMEWORK_MODULES_PATH/$scheme.swiftmodule" + # Delete private swiftinterface + rm -f "$FRAMEWORK_MODULES_PATH/$scheme.swiftmodule/*.private.swiftinterface" + mkdir -p "$scheme-$sdk.xcarchive/LinkMaps" + find "$XCODEBUILD_DERIVED_DATA_PATH" -name "$scheme-LinkMap-*.txt" -exec cp {} "./$scheme-$sdk.xcarchive/LinkMaps/" \; } -main "$@" +# Update the Package.swift to build the library as dynamic instead of static +sed -i '' '/Replace this/ s/.*/type: .dynamic,/' Package.swift + +build_framework "iphonesimulator" "generic/platform=iOS Simulator" "RunveyKit" +build_framework "iphoneos" "generic/platform=iOS" "RunveyKit" + +echo "Builds completed successfully." + +rm -rf "RunveyKit.xcframework" +xcodebuild -create-xcframework -framework RunveyKit-iphonesimulator.xcarchive/Products/Library/Frameworks/RunveyKit.framework -framework RunveyKit-iphoneos.xcarchive/Products/Library/Frameworks/RunveyKit.framework -output RunveyKit.xcframework + +cp -r RunveyKit-iphonesimulator.xcarchive/dSYMs RunveyKit.xcframework/ios-arm64_x86_64-simulator +cp -r RunveyKit-iphoneos.xcarchive/dSYMs RunveyKit.xcframework/ios-arm64 \ No newline at end of file diff --git a/Package.swift b/Package.swift index 9246141..aaedcb5 100644 --- a/Package.swift +++ b/Package.swift @@ -15,6 +15,7 @@ let package = Package( products: [ .library( name: "RunveyKit", + type: .static, targets: ["RunveyKit"]) ], dependencies: [