您需要构建二进制文件两次,例如,对于一个以 macOS 为目标的项目,您将使用编译一次,-target x86_64-apple-macos10.15
另一次使用-target arm64-apple-macos10.15
.
之后,您可以lipo -create
像这样将它们拼接成一个文件lipo -create <path/to/arm64-slice> <path/to/x86_64-slice> -output <path/to/universal/binary>
。
我是这样做的:
➜ UniversalBinaryTest swiftc source.swift -target x86_64-apple-macos10.15 -o binary_x86-64
➜ UniversalBinaryTest lipo -archs binary_x86-64
x86_64
➜ UniversalBinaryTest swiftc source.swift -target arm64-apple-macos10.15 -o binary_arm64
➜ UniversalBinaryTest lipo -archs binary_arm64
arm64
➜ UniversalBinaryTest lipo -create binary_x86-64 binary_arm64 -output binary_universal
➜ UniversalBinaryTest lipo -archs binary_universal
x86_64 arm64
毕竟,您可能想要重新签署新的二进制文件。
编辑:实际上,如果两个切片都已签名,则看起来 lipo 会为您签名:
➜ UniversalBinaryTest codesign -s - binary_x86-64
➜ UniversalBinaryTest codesign -vvv binary_x86-64
binary_x86-64: valid on disk
binary_x86-64: satisfies its Designated Requirement
➜ UniversalBinaryTest codesign -vvvvv binary_x86-64
binary_x86-64: valid on disk
binary_x86-64: satisfies its Designated Requirement
➜ UniversalBinaryTest codesign -s - binary_arm64
➜ UniversalBinaryTest lipo -create binary_x86-64 binary_arm64 -output binary_universal
➜ UniversalBinaryTest codesign -vvv binary_universal
binary_universal: valid on disk
binary_universal: satisfies its Designated Requirement