Skip to content

Commit

Permalink
Update build.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
rudrankriyam committed Oct 10, 2024
1 parent a2a6efe commit ac304ec
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 70 deletions.
112 changes: 42 additions & 70 deletions .github/build.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let package = Package(
products: [
.library(
name: "RunveyKit",
type: .static,
targets: ["RunveyKit"])
],
dependencies: [
Expand Down

0 comments on commit ac304ec

Please sign in to comment.