ios 如何构建包含Mac Catalyst的Fat Framework?

8e2ybdfx  于 2023-05-19  发布在  iOS
关注(0)|答案(1)|浏览(179)

如何构建一个包含构建Mac Catalyst应用程序所需架构的胖框架?

xu3bshqb

xu3bshqb1#

苹果推出了一款(无证?)新目标:x86_64-apple-ios13.0-macabi
如何构建此目标取决于您的框架构建环境。

1)XCFramework

如果你的框架是一个Xcode项目:

  • 在Xcode中选择目标

  • 选择“常规”选项卡

  • 在“部署信息”下,勾选“Mac”复选框:

  • 建造
    2)外部构建

如果你在Xcode之外构建你的框架,例如一个C库,而不是为x86_64和iphonesimulator构建,为新的目标x86_64-apple-ios 13.0-macabi和macosx构建。
使用make的C Lib示例:

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-iosx86_64-apple-ios13.0-macabi的切片必须/不能添加到fat库中。两者都是x86_64。仅使用x86_64-apple-ios13.0-macabi的一个。

相关问题