Skip to content

Commit

Permalink
feat(ios): use/support/build xcframeworks
Browse files Browse the repository at this point in the history
  • Loading branch information
sgtcoolguy committed Sep 10, 2020
1 parent e56e127 commit 133527e
Show file tree
Hide file tree
Showing 8 changed files with 315 additions and 196 deletions.
8 changes: 4 additions & 4 deletions build/lib/ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class IOS {
async copyLegacyHeaders(DEST_IOS) {
// Gather all the *.h files in TitaniumKit, create "redirecting" headers in iphone/include that point to the TitaniumKit ones
await fs.ensureDir(path.join(DEST_IOS, 'include'));
const subdirs = await fs.readdir(path.join(IOS_ROOT, 'TitaniumKit/build/Release-iphoneuniversal/TitaniumKit.framework/Headers'));
const subdirs = await fs.readdir(path.join(IOS_ROOT, 'TitaniumKit/build/TitaniumKit.xcframework/ios-arm64_armv7/TitaniumKit.framework/Headers'));
// create them all in parallel
await Promise.all(subdirs.map(file => {
// TODO: Inject a deprecation warning if used and remove in SDK 9.0.0?
Expand Down Expand Up @@ -138,13 +138,13 @@ class IOS {
copyFiles(IOS_ROOT, DEST_IOS, [ 'AppledocSettings.plist', 'Classes', 'cli', 'iphone', 'templates' ]),

// Copy TitaniumKit
copyFiles(path.join(IOS_ROOT, 'TitaniumKit/build/Release-iphoneuniversal'), path.join(DEST_IOS, 'Frameworks'), [ 'TitaniumKit.framework' ]),
fs.copySync(path.join(IOS_ROOT, 'TitaniumKit/build/TitaniumKit.xcframework'), path.join(DEST_IOS, 'Frameworks/TitaniumKit.xcframework')),

// Copy and inject values for special source files
this.injectSDKConstants(path.join(DEST_IOS, 'main.m')),

// Copy Ti.Verify
copyFiles(IOS_LIB, DEST_IOS, [ 'libtiverify.a' ]),
// Copy tiverify.xcframework
copyFiles(IOS_LIB, path.join(DEST_IOS, 'Frameworks'), [ 'tiverify.xcframework' ]),

// Copy iphone/package.json, but replace __VERSION__ with our version!
copyAndModifyFile(IOS_ROOT, DEST_IOS, 'package.json', { __VERSION__: this.sdkVersion }),
Expand Down
2 changes: 1 addition & 1 deletion build/lib/packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const TITANIUM_PREP_LOCATIONS = [
*/
async function zip(cwd, filename) {
const command = os.platform() === 'win32' ? path.join(ROOT_DIR, 'build/win32/zip') : 'zip';
await exec(`${command} -9 -q -r "${path.join('..', path.basename(filename))}" *`, { cwd });
await exec(`${command} -9 -q -r -y "${path.join('..', path.basename(filename))}" *`, { cwd });

const outputFolder = path.resolve(cwd, '..');
const outputFile = path.join(outputFolder, path.basename(filename));
Expand Down
15 changes: 12 additions & 3 deletions iphone/TitaniumKit/TitaniumKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,6 @@
TargetAttributes = {
DB258CCC1F09757E000D0D8D = {
CreatedOnToolsVersion = 8.3.3;
ProvisioningStyle = Automatic;
};
DB9635BE1F0AB4AC00C41B20 = {
CreatedOnToolsVersion = 8.3.3;
Expand Down Expand Up @@ -988,8 +987,11 @@
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = NO;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Manual;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand Down Expand Up @@ -1020,6 +1022,8 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.appcelerator.TitaniumKit;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SKIP_INSTALL = YES;
VALID_ARCHS = "$(ARCHS_STANDARD)";
};
Expand All @@ -1033,8 +1037,11 @@
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = NO;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Manual;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand Down Expand Up @@ -1063,6 +1070,8 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.appcelerator.TitaniumKit;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SKIP_INSTALL = YES;
VALID_ARCHS = "$(ARCHS_STANDARD)";
};
Expand Down
108 changes: 33 additions & 75 deletions iphone/TitaniumKit/TitaniumKit/Scripts/build-universal-framework.sh
Original file line number Diff line number Diff line change
@@ -1,79 +1,37 @@
# Based on https://medium.com/@syshen/create-an-ios-universal-framework-148eb130a46c, thank you!

######################
# Options
######################

REVEAL_ARCHIVE_IN_FINDER=false

FRAMEWORK_NAME="${PROJECT_NAME}"

SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework"

DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework"

UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal"

FRAMEWORK="${UNIVERSAL_LIBRARY_DIR}/${FRAMEWORK_NAME}.framework"

XCODE_VERSION=$(/usr/libexec/PlistBuddy -c "Print :DTXcode" "$(xcode-select -p)/../Info.plist")

######################
# Build Frameworks
######################

# Exclude arm64 architecture from simulator build in XCode 12+- TIMOB-28042

if [[ $XCODE_VERSION -ge 1200 ]]; then
xcodebuild -scheme ${PROJECT_NAME} -sdk iphonesimulator EXCLUDED_ARCHS=arm64 -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator 2>&1
else
xcodebuild -scheme ${PROJECT_NAME} -sdk iphonesimulator -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator 2>&1
fi

xcodebuild -scheme ${PROJECT_NAME} -sdk iphoneos -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos 2>&1

######################
# Create directory for universal
######################

rm -rf "${UNIVERSAL_LIBRARY_DIR}"

mkdir "${UNIVERSAL_LIBRARY_DIR}"

mkdir "${FRAMEWORK}"


######################
# Copy files Framework
######################

cp -r "${DEVICE_LIBRARY_PATH}/." "${FRAMEWORK}"

######################
# Make an universal binary
######################

lipo "${SIMULATOR_LIBRARY_PATH}/${FRAMEWORK_NAME}" "${DEVICE_LIBRARY_PATH}/${FRAMEWORK_NAME}" -create -output "${FRAMEWORK}/${FRAMEWORK_NAME}" | echo

# For Swift framework, Swiftmodule needs to be copied in the universal framework
if [ -d "${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
cp -f ${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
fi

if [ -d "${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
cp -f ${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
fi

######################
# On Release, copy the result to release directory
######################
OUTPUT_DIR="${PROJECT_DIR}/dist/${FRAMEWORK_NAME}-${CONFIGURATION}-iphoneuniversal/"

rm -rf "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"

cp -r "${FRAMEWORK}" "$OUTPUT_DIR"

if [ ${REVEAL_ARCHIVE_IN_FINDER} = true ]; then
open "${OUTPUT_DIR}/"
fi
FRAMEWORK_NAME="${PROJECT_NAME}" \
SCHEME="${PROJECT_NAME}" \
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}

#----- Make macCatalyst archive
xcodebuild archive \
-scheme $SCHEME \
-archivePath $UNIVERSAL_OUTPUTFOLDER/macCatalyst.xcarchive \
-sdk macosx \
SKIP_INSTALL=NO \
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES \
SUPPORTS_MACCATALYST=YES \

#----- Make iOS Simulator archive
xcodebuild archive \
-scheme $SCHEME \
-archivePath $UNIVERSAL_OUTPUTFOLDER/simulator.xcarchive \
-sdk iphonesimulator \
SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES

#----- Make iOS device archive
xcodebuild archive \
-scheme $SCHEME \
-archivePath $UNIVERSAL_OUTPUTFOLDER/iosdevice.xcarchive \
-sdk iphoneos \
SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES

#----- Make XCFramework
xcodebuild -create-xcframework \
-framework $UNIVERSAL_OUTPUTFOLDER/simulator.xcarchive/Products/Library/Frameworks/$SCHEME.framework \
-framework $UNIVERSAL_OUTPUTFOLDER/iosdevice.xcarchive/Products/Library/Frameworks/$SCHEME.framework \
-framework $UNIVERSAL_OUTPUTFOLDER/macCatalyst.xcarchive/Products/Library/Frameworks/$SCHEME.framework \
-output ${PROJECT_DIR}/dist/$SCHEME.xcframework
Loading

0 comments on commit 133527e

Please sign in to comment.