在 Linux 平台上为 iOS 做交叉编译
The procedure for this is somewhat complex and requires a lot of steps, but once you have the environment properly configured you can compile Godot for iOS anytime you want.
免责声明
While it is possible to compile for iOS on a Linux environment, Apple is very restrictive about the tools to be used (especially hardware-wise), allowing pretty much only their products to be used for development. So this is not official. However, in 2010 Apple said they relaxed some of the App Store review guidelines to allow any tool to be used, as long as the resulting binary does not download any code, which means it should be OK to use the procedure described here and cross-compiling the binary.
需求
XCode 及 iOS SDK(登入 Apple ID 才能下载 Xcode)。
Clang >= 3.5 for your development machine installed and in the
PATH
. It has to be version >= 3.5 to targetarm64
architecture.xar and pbzx (required to extract the
.xip
archive Xcode comes in).For building xar and pbzx, you may want to follow this guide.
cctools-port 用于所需的构建工具. 构建过程非常特殊, 下面将进行描述.
这也有一些额外的依赖:automake,autogen,libtool.
配置环境
准备 SDK
Extract the Xcode .xip
file you downloaded from Apple's developer website:
mkdir xcode
xar -xf /path/to/Xcode_X.x.xip -C xcode
pbzx -n Content | cpio -i
[...]
######### Blocks
Note that for the commands below, you will need to replace the version (x.x
)
with whatever iOS SDK version you're using. If you don't know your iPhone SDK
version, you can see the JSON file inside of
Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs
.
解压缩 iOS SDK:
export IOS_SDK_VERSION="x.x"
mkdir -p iPhoneSDK/iPhoneOS${IOS_SDK_VERSION}.sdk
cp -r xcode/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/* iPhoneSDK/iPhoneOS${IOS_SDK_VERSION}.sdk
cp -r xcode/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/* iPhoneSDK/iPhoneOS${IOS_SDK_VERSION}.sdk/usr/include/c++
fusermount -u xcode
Pack the SDK so that cctools can use it:
cd iPhoneSDK
tar -cf - * | xz -9 -c - > iPhoneOS${IOS_SDK_VERSION}.sdk.tar.xz
工具链
构建 cctools:
git clone https://github.com/tpoechtrager/cctools-port.git
cd cctools-port/usage_examples/ios_toolchain
./build.sh /path/iPhoneOS${IOS_SDK_VERSION}.sdk.tar.xz arm64
将工具复制到更好的位置. 请注意, 用于构建的SCons脚本将在你为工具链二进制文件提供的目录中的 usr/bin
下查找, 因此, 你必须复制到这样的子目录, 类似于以下命令:
mkdir -p "$HOME/iostoolchain/usr"
cp -r target/bin "$HOME/iostoolchain/usr/"
Now you should have the iOS toolchain binaries in
$HOME/iostoolchain/usr/bin
.
为 iPhone 编译 Godot
完成上述步骤后, 应在环境中保留两件事: 构建的工具链和iPhoneOS SDK目录. 那些可以留在你想要的任何地方, 因此你必须提供它们的路径给SCons构建命令.
为了检测iPhone平台, 你需要将 OSXCROSS_IOS
环境变量定义为 anything
.
export OSXCROSS_IOS="anything"
现在你可以使用SCons像标准Godot方式一样编译iPhone, 带有一些其他参数以提供正确的路径:
scons platform=ios arch=arm64 target=template_release IOS_SDK_PATH="/path/to/iPhoneSDK" IOS_TOOLCHAIN_PATH="/path/to/iostoolchain" ios_triple="arm-apple-darwin11-"