如何构建包含Mac Catalyst的Fat Framework? [英] How to build a Fat Framework that includes Mac Catalyst?
问题描述
如何构建一个胖框架,其中包括构建Mac Catalyst应用所需的架构?
How does one build a fat framework that includes the architectures necessary to build to Mac Catalyst apps?
推荐答案
Apple引入了(未记录?)新目标:x86_64-apple-ios13.0-macabi
Apple has introduced a (undocumented?) new target: x86_64-apple-ios13.0-macabi
如何为此目标进行构建取决于您的框架构建环境.
How to build for this target depends on your frameworks build environment.
1)XCFramework
如果您的框架是Xcode项目:
In case your framework is an Xcode project:
- 在Xcode中选择目标
- 选择常规"标签
- 在部署信息"下,选中"Mac"复选框:
- 构建
- Select the target in Xcode
- Select the "General" tab
- Under "Deployment Info", tick the "Mac" checkbox:
- build
2)外部版本
如果您要在Xcode之外构建框架,例如C库,而不是针对x86_64& iphonesimulator,为新目标x86_64-apple-ios-13.0-macabi& macosx.
In case you are building your framework outside Xcode, e.g. a C lib, instead of building for x86_64 & iphonesimulator, build for the new target x86_64-apple-ios13.0-macabi & macosx.
使用make的C Lib示例:
Example for C Lib using make:
MIN_IOS_VERSION="10.0"
LIB_NAME= "theNameOfYourLib"
# The build function
build()
{
ARCH=$1
TARGET=$2
HOST=$3
SDK=$4
SDK_PATH=`xcrun -sdk ${SDK} --show-sdk-path`
export PREFIX=build/${ARCH}
export CFLAGS="-arch ${ARCH} -isysroot ${SDK_PATH} -miphoneos-version-min=${MIN_IOS_VERSION} -std=c99 -target ${TARGET}"
export LDFLAGS="-arch ${ARCH}"
export CC="$(xcrun --sdk ${SDK} -f clang) -arch ${ARCH} -isysroot ${SDK_PATH}"
PKG_CONFIG_ALLOW_CROSS=1 PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig ./configure --host=${HOST} --prefix=$PREFIX
make
make install
}
# Build for all required architectures
build "armv7" "armv7-apple-ios" "arm-apple-darwin" "iphoneos" # MIN_IOS_VERSION must be one of arm7 supported ones to. Else remove this line.
build "arm64" "aarch64-apple-ios" "arm-apple-darwin" "iphoneos"
# build "x86_64" "x86_64-apple-ios" "x86_64-apple-darwin" "iphonesimulator" #obsolete due to x86_64-apple-ios13.0-macabi
build "x86_64" "x86_64-apple-ios13.0-macabi" "x86_64-apple-darwin" "macosx"
build "i386" "i386-apple-ios" "i386-apple-darwin" "iphonesimulator" # same as arm7: MIN_IOS_VERSION must be one of arm7 supported ones.
# Now find all the artefacts created above (e.g. build/arm64/lib/${LIB_NAME}.a, build/x86_64/lib/${LIB_NAME}.a ...) and merge them together to a fat lib using lipo
OUTPUT_DIR="fatLib"
lipo -create -output $OUTPUT_DIR/lib/${LIB_NAME}.a build/x86_64/lib/${LIB_NAME}.a build/arm64/lib/${LIB_NAME}.a build/armv7/lib/${LIB_NAME}.a build/i386/lib/${LIB_NAME}.a
# You may also need the header files
cp -R build/armv7/include/* $OUTPUT_DIR/include/
注意:您必须/不能将x86_64-apple-ios
和x86_64-apple-ios13.0-macabi
的切片添加到fat lib中.两者都是x86_64. x86_64-apple-ios13.0-macabi
仅使用一个.
Note: You must/can not add slices for x86_64-apple-ios
and x86_64-apple-ios13.0-macabi
to the fat lib. Both are x86_64. Use only the one for x86_64-apple-ios13.0-macabi
.
这篇关于如何构建包含Mac Catalyst的Fat Framework?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!