Skip to content

Commit

Permalink
Merge pull request #2 from iComics/dynamic-ios-library
Browse files Browse the repository at this point in the history
Added support for iOS XCFramework builds
  • Loading branch information
TimOliver authored May 6, 2021
2 parents c807d5f + 1b1d57c commit 103f0c6
Show file tree
Hide file tree
Showing 7 changed files with 443 additions and 27 deletions.
8 changes: 5 additions & 3 deletions XADArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
*/
#import <Foundation/Foundation.h>

#import "XADArchiveParser.h"
#import "XADUnarchiver.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#import "XADException.h"
#import "CSHandle.h"
#pragma clang diagnostic pop

typedef int XADAction;
//typedef off_t xadSize; // deprecated
Expand All @@ -37,8 +39,8 @@ extern NSString *XADResourceDataKey;
extern NSString *XADResourceForkData;
extern NSString *XADFinderFlags;


@class UniversalDetector;
@class XADArchiveParser, XADUnarchiver;

@interface XADArchive:NSObject
{
Expand Down
3 changes: 2 additions & 1 deletion XADArchive.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
#define XAD_NO_DEPRECATED

#import "XADArchive.h"
#import "XADArchiveParser.h"
#import "XADUnarchiver.h"
#import "CSMemoryHandle.h"
#import "CSHandle.h"
#import "Progress.h"
#import "NSDateXAD.h"

Expand Down
269 changes: 265 additions & 4 deletions XADMaster.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions XADMaster.xcodeproj/xcshareddata/xcschemes/XADMaster-iOS.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "223F699D2643C3E400B9ABCA"
BuildableName = "XADMaster.framework"
BlueprintName = "XADMaster-iOS"
ReferencedContainer = "container:XADMaster.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "223F699D2643C3E400B9ABCA"
BuildableName = "XADMaster.framework"
BlueprintName = "XADMaster-iOS"
ReferencedContainer = "container:XADMaster.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
24 changes: 10 additions & 14 deletions XADMaster.xcodeproj/xcshareddata/xcschemes/XADMaster.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1000"
LastUpgradeVersion = "1250"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -27,6 +27,15 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8DC2EF4F0486A6940098B216"
BuildableName = "XADMaster.framework"
BlueprintName = "XADMaster"
ReferencedContainer = "container:XADMaster.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -39,17 +48,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8DC2EF4F0486A6940098B216"
BuildableName = "XADMaster.framework"
BlueprintName = "XADMaster"
ReferencedContainer = "container:XADMaster.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -70,8 +68,6 @@
ReferencedContainer = "container:XADMaster.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1000"
LastUpgradeVersion = "1250"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -23,8 +23,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -36,8 +34,6 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
93 changes: 93 additions & 0 deletions build-ios.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash

# BSD 3-Clause License
#
# Copyright (c) 2021, Tim Oliver
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

set -e

# Main Definitions
UD_REPO="https://www.github.com/icomics/universal-detector.git"
FRAMEWORK_NAME="XADMaster"
BUILD_PATH="build/Build/Products"
DEVICE_PATH="Release-iphoneos"
SIMULATOR_PATH="Release-iphonesimulator"

# Add a module map to a target directory
add_module_map() {
TARGET_DIR=$1

mkdir -p "${TARGET_DIR}/Modules"
cat <<EOT >> ${TARGET_DIR}/Modules/module.modulemap
framework module XADMaster {
header "XADArchive.h"
header "CSHandle.h"
header "XADException.h"
header "ClangAnalyser.h"
export *
}
EOT
}

make_framework() {
# If it doesn't exist, pull down the UniversalDetector repo
if [ ! -d "../UniversalDetector" ]; then
git clone ${UD_REPO} ../UniversalDetector
fi

# Delete the folder if present
rm -r build
mkdir -p build

# Build the simulator slice (But only Intel since we need XCFramework to support Apple Silicon)
xcodebuild -project XADMaster.xcodeproj -scheme XADMaster-iOS -sdk iphonesimulator -destination "generic/platform=iOS Simulator" \
-configuration Release BUILD_LIBRARY_FOR_DISTRIBUTION=YES -derivedDataPath build clean build

# Add the module map for Swift compatibility
add_module_map "${BUILD_PATH}/${SIMULATOR_PATH}/${FRAMEWORK_NAME}.framework"

# Build all of the iOS slices of the framework
xcodebuild -project XADMaster.xcodeproj -scheme XADMaster-iOS -sdk iphoneos -destination "generic/platform=iOS" \
-configuration Release BUILD_LIBRARY_FOR_DISTRIBUTION=YES -derivedDataPath build build

# Add the module map for Swift compatibility
add_module_map "${BUILD_PATH}/${DEVICE_PATH}/${FRAMEWORK_NAME}.framework"

#Convert the library into an xcframework
xcodebuild -create-xcframework \
-framework ${BUILD_PATH}/${DEVICE_PATH}/${FRAMEWORK_NAME}.framework \
-framework ${BUILD_PATH}/${SIMULATOR_PATH}/${FRAMEWORK_NAME}.framework \
-output build/${FRAMEWORK_NAME}.xcframework

# Open the folder for us to see if
open build
}

# Start the build process
make_framework

0 comments on commit 103f0c6

Please sign in to comment.