-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
1 parent
bc60db5
commit d390d66
Showing
13 changed files
with
452 additions
and
171 deletions.
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,47 +1,65 @@ | ||
#!/bin/bash | ||
|
||
# Documentation: | ||
# This script builds a <TARGET> for all supported platforms. | ||
# This script builds a <TARGET> for all provided <PLATFORMS>. | ||
|
||
# Usage: | ||
# build.sh <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS] | ||
# e.g. `bash scripts/build.sh MyTarget iOS macOS` | ||
|
||
# Exit immediately if a command exits with a non-zero status | ||
set -e | ||
|
||
# Verify that all required arguments are provided | ||
if [ $# -eq 0 ]; then | ||
echo "Error: This script requires exactly one argument" | ||
echo "Usage: $0 <TARGET>" | ||
echo "Error: This script requires at least one argument" | ||
echo "Usage: $0 <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]" | ||
echo "For instance: $0 MyTarget iOS macOS" | ||
exit 1 | ||
fi | ||
|
||
# Create local argument variables. | ||
# Define argument variables | ||
TARGET=$1 | ||
|
||
# Use the script folder to refer to other scripts. | ||
FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
SCRIPT="$FOLDER/build_platform.sh" | ||
# Remove TARGET from arguments list | ||
shift | ||
|
||
# Make the script executable | ||
chmod +x $SCRIPT | ||
# Define platforms variable | ||
if [ $# -eq 0 ]; then | ||
set -- iOS macOS tvOS watchOS xrOS | ||
fi | ||
PLATFORMS=$@ | ||
|
||
# A function that builds a specific platform | ||
# A function that builds $TARGET for a specific platform | ||
build_platform() { | ||
local platform=$1 | ||
echo "Building for $platform..." | ||
if ! bash $SCRIPT $TARGET $platform; then | ||
echo "Failed to build $platform" | ||
|
||
# Define a local $PLATFORM variable | ||
local PLATFORM=$1 | ||
|
||
# Build $TARGET for the $PLATFORM | ||
echo "Building $TARGET for $PLATFORM..." | ||
if ! xcodebuild -scheme $TARGET -derivedDataPath .build -destination generic/platform=$PLATFORM; then | ||
echo "Failed to build $TARGET for $PLATFORM" | ||
return 1 | ||
fi | ||
echo "Successfully built $platform" | ||
|
||
# Complete successfully | ||
echo "Successfully built $TARGET for $PLATFORM" | ||
} | ||
|
||
# Array of platforms to build | ||
platforms=("iOS" "macOS" "tvOS" "watchOS" "xrOS") | ||
# Start script | ||
echo "" | ||
echo "Building $TARGET for [$PLATFORMS]..." | ||
echo "" | ||
|
||
# Loop through platforms and build | ||
for platform in "${platforms[@]}"; do | ||
if ! build_platform "$platform"; then | ||
# Loop through all platforms and call the build function | ||
for PLATFORM in $PLATFORMS; do | ||
if ! build_platform "$PLATFORM"; then | ||
exit 1 | ||
fi | ||
done | ||
|
||
echo "All platforms built successfully!" | ||
# Complete successfully | ||
echo "" | ||
echo "Building $TARGET completed successfully!" | ||
echo "" |
This file was deleted.
Oops, something went wrong.
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,26 +1,99 @@ | ||
#!/bin/bash | ||
|
||
# Documentation: | ||
# This script build DocC for a <TARGET>. | ||
# The documentation ends up in to .build/docs. | ||
# This script builds DocC for a <TARGET> for all provided <PLATFORMS>. | ||
# The documentation ends up in to .build/docs-<PLATFORM>. | ||
|
||
# Usage: | ||
# docc.sh <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS] | ||
# e.g. `bash scripts/docc.sh MyTarget iOS macOS` | ||
|
||
# Exit immediately if a command exits with a non-zero status | ||
set -e | ||
|
||
# Verify that all required arguments are provided | ||
if [ $# -eq 0 ]; then | ||
echo "Error: This script requires exactly one argument" | ||
echo "Usage: $0 <TARGET>" | ||
echo "Error: This script requires at least one argument" | ||
echo "Usage: $0 <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]" | ||
echo "For instance: $0 MyTarget iOS macOS" | ||
exit 1 | ||
fi | ||
|
||
# Define argument variables | ||
TARGET=$1 | ||
TARGET_LOWERCASED=$(echo "$1" | tr '[:upper:]' '[:lower:]') | ||
|
||
# Remove TARGET from arguments list | ||
shift | ||
|
||
# Define platforms variable | ||
if [ $# -eq 0 ]; then | ||
set -- iOS macOS tvOS watchOS xrOS | ||
fi | ||
PLATFORMS=$@ | ||
|
||
# Prepare the package for DocC | ||
swift package resolve; | ||
|
||
xcodebuild docbuild -scheme $1 -derivedDataPath /tmp/docbuild -destination 'generic/platform=iOS'; | ||
# A function that builds $TARGET for a specific platform | ||
build_platform() { | ||
|
||
# Define a local $PLATFORM variable | ||
local PLATFORM=$1 | ||
|
||
# Define the build folder name, based on the $PLATFORM | ||
case $PLATFORM in | ||
"iOS") | ||
DEBUG_PATH="Debug-iphoneos" | ||
;; | ||
"macOS") | ||
DEBUG_PATH="Debug" | ||
;; | ||
"tvOS") | ||
DEBUG_PATH="Debug-appletvos" | ||
;; | ||
"watchOS") | ||
DEBUG_PATH="Debug-watchos" | ||
;; | ||
"xrOS") | ||
DEBUG_PATH="Debug-xros" | ||
;; | ||
*) | ||
echo "Error: Unsupported platform '$PLATFORM'" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
# Build $TARGET docs for the $PLATFORM | ||
echo "Building $TARGET docs for $PLATFORM..." | ||
xcodebuild docbuild -scheme $TARGET -derivedDataPath .build/docbuild -destination 'generic/platform='$PLATFORM; | ||
|
||
# Transform docs for static hosting | ||
$(xcrun --find docc) process-archive \ | ||
transform-for-static-hosting .build/docbuild/Build/Products/$DEBUG_PATH/$TARGET.doccarchive \ | ||
--output-path .build/docs-$PLATFORM \ | ||
--hosting-base-path "$TARGET"; | ||
|
||
# Inject a root redirect script on the root page | ||
echo "<script>window.location.href += \"/documentation/$TARGET_LOWERCASED\"</script>" > .build/docs-$PLATFORM/index.html; | ||
|
||
# Complete successfully | ||
echo "Successfully built $TARGET docs for $PLATFORM" | ||
} | ||
|
||
# Start script | ||
echo "" | ||
echo "Building $TARGET docs for [$PLATFORMS]..." | ||
echo "" | ||
|
||
$(xcrun --find docc) process-archive \ | ||
transform-for-static-hosting /tmp/docbuild/Build/Products/Debug-iphoneos/$1.doccarchive \ | ||
--output-path .build/docs \ | ||
--hosting-base-path "$TARGET"; | ||
# Loop through all platforms and call the build function | ||
for PLATFORM in $PLATFORMS; do | ||
if ! build_platform "$PLATFORM"; then | ||
exit 1 | ||
fi | ||
done | ||
|
||
echo "<script>window.location.href += \"/documentation/$TARGET_LOWERCASED\"</script>" > .build/docs/index.html; | ||
# Complete successfully | ||
echo "" | ||
echo "Building $TARGET docs completed successfully!" | ||
echo "" |
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,114 @@ | ||
#!/bin/bash | ||
|
||
# Documentation: | ||
# This script generates an XCFramework for a certain <TARGET> for all provided <PLATFORMS>. | ||
|
||
# Important: | ||
# This script doesn't work on packages, only on .xcproj projects that generate a framework. | ||
|
||
# Usage: | ||
# framework.sh <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS] | ||
# e.g. `bash scripts/framework.sh MyTarget iOS macOS` | ||
|
||
# Exit immediately if a command exits with a non-zero status | ||
set -e | ||
|
||
# Verify that all required arguments are provided | ||
if [ $# -eq 0 ]; then | ||
echo "Error: This script requires exactly one argument" | ||
echo "Usage: $0 <TARGET>" | ||
exit 1 | ||
fi | ||
|
||
# Define argument variables | ||
TARGET=$1 | ||
|
||
# Remove TARGET from arguments list | ||
shift | ||
|
||
# Define platforms variable | ||
if [ $# -eq 0 ]; then | ||
set -- iOS macOS tvOS watchOS xrOS | ||
fi | ||
PLATFORMS=$@ | ||
|
||
# Define local variables | ||
BUILD_FOLDER=.build | ||
BUILD_FOLDER_ARCHIVES=.build/framework_archives | ||
BUILD_FILE=$BUILD_FOLDER/$TARGET.xcframework | ||
BUILD_ZIP=$BUILD_FOLDER/$TARGET.zip | ||
|
||
# Start script | ||
echo "" | ||
echo "Building $TARGET XCFramework for [$PLATFORMS]..." | ||
echo "" | ||
|
||
# Delete old builds | ||
echo "Cleaning old builds..." | ||
rm -rf $BUILD_ZIP | ||
rm -rf $BUILD_FILE | ||
rm -rf $BUILD_FOLDER_ARCHIVES | ||
|
||
|
||
# Generate XCArchive files for all platforms | ||
echo "Generating XCArchives..." | ||
|
||
# Initialize the xcframework command | ||
XCFRAMEWORK_CMD="xcodebuild -create-xcframework" | ||
|
||
# Build iOS archives and append to the xcframework command | ||
if [[ " ${PLATFORMS[@]} " =~ " iOS " ]]; then | ||
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=iOS" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-iOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES | ||
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=iOS Simulator" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-iOS-Sim SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES | ||
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-iOS.xcarchive/Products/Library/Frameworks/$TARGET.framework" | ||
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-iOS-Sim.xcarchive/Products/Library/Frameworks/$TARGET.framework" | ||
fi | ||
|
||
# Build iOS archive and append to the xcframework command | ||
if [[ " ${PLATFORMS[@]} " =~ " macOS " ]]; then | ||
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=macOS" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-macOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES | ||
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-macOS.xcarchive/Products/Library/Frameworks/$TARGET.framework" | ||
fi | ||
|
||
# Build tvOS archives and append to the xcframework command | ||
if [[ " ${PLATFORMS[@]} " =~ " tvOS " ]]; then | ||
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=tvOS" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-tvOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES | ||
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=tvOS Simulator" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-tvOS-Sim SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES | ||
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-tvOS.xcarchive/Products/Library/Frameworks/$TARGET.framework" | ||
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-tvOS-Sim.xcarchive/Products/Library/Frameworks/$TARGET.framework" | ||
fi | ||
|
||
# Build watchOS archives and append to the xcframework command | ||
if [[ " ${PLATFORMS[@]} " =~ " watchOS " ]]; then | ||
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=watchOS" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-watchOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES | ||
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=watchOS Simulator" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-watchOS-Sim SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES | ||
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-watchOS.xcarchive/Products/Library/Frameworks/$TARGET.framework" | ||
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-watchOS-Sim.xcarchive/Products/Library/Frameworks/$TARGET.framework" | ||
fi | ||
|
||
# Build xrOS archives and append to the xcframework command | ||
if [[ " ${PLATFORMS[@]} " =~ " xrOS " ]]; then | ||
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=xrOS" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-xrOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES | ||
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=xrOS Simulator" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-xrOS-Sim SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES | ||
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-xrOS.xcarchive/Products/Library/Frameworks/$TARGET.framework" | ||
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-xrOS-Sim.xcarchive/Products/Library/Frameworks/$TARGET.framework" | ||
fi | ||
|
||
# Genererate XCFramework | ||
echo "Generating XCFramework..." | ||
XCFRAMEWORK_CMD+=" -output $BUILD_FILE" | ||
eval "$XCFRAMEWORK_CMD" | ||
|
||
# Genererate iOS XCFramework zip | ||
echo "Generating XCFramework zip..." | ||
zip -r $BUILD_ZIP $BUILD_FILE | ||
echo "" | ||
echo "***** CHECKSUM *****" | ||
swift package compute-checksum $BUILD_ZIP | ||
echo "********************" | ||
echo "" | ||
|
||
# Complete successfully | ||
echo "" | ||
echo "$TARGET XCFramework created successfully!" | ||
echo "" |
Oops, something went wrong.