Skip to content

Instantly share code, notes, and snippets.

@heybdj
Created May 22, 2020 00:05
Show Gist options
  • Save heybdj/5853362a0d605b58d58df80dad8308fd to your computer and use it in GitHub Desktop.
Save heybdj/5853362a0d605b58d58df80dad8308fd to your computer and use it in GitHub Desktop.
Cross-Compiling for iOS with Bake
{
// Set `BAKE_OS` to the lowercase, shorthand OS name that matches what
// clang expects for the `sys` portion of the "target triple." See
// clang's cross-compilation docs for more info:
// https://clang.llvm.org/docs/CrossCompilation.html
// Set `BAKE_ARCHITECTURE` to the target architecture (the `arch` portion
// of clang's target triple). To compile for multiple architectures, build
// them one by one and use the `lipo` tool to merge them together.
// Set `DEPLOYMENT_TARGET` to the minimum target OS version you support.
// Be mindful of what Apple hardware actually runs on your given
// archtecture + deployment target combo.
// Set `SDK_NAME` to the official lowercase SDK name that's installed on
// your host machine. Use `xcodebuild -showsdks` to find the appropriate
// `SDK_NAME` for your target platform.
// Set `SDK_ROOT` to the full path pointing to the installed target SDK.
// Use `xcrun --sdk MY_SDK_NAME --show-sdk-path` to find the `SDK_ROOT` for
// your target platform. Be sure to replace `MY_SDK_NAME` with the name
// used for `SDK_NAME`.
// To use the version of clang packaged with your target SDK, set the
// `CC` environment variable to the result of this Terminal command (swap
// "iphoneos" with your target SDK name):
// `xcrun --sdk iphoneos --find clang`.
//
// As of 2020-05-21, using a non-standard version of clang requires a small
// patch to Bake's `lang.c` driver. See this pull request for details:
// https://github.com/SanderMertens/bake/pull/67
"environment": {
"macos": {
"BAKE_OS": "macos",
"BAKE_ARCHITECTURE": "x86_64",
// El Capitan+
"DEPLOYMENT_TARGET": "10.11",
"SDK_NAME": "macosx",
"SDK_ROOT": "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk"
},
"ios": {
"BAKE_OS": "ios",
// iOS 7.0+. Includes iPhone 5s/SE, iPad Air, and everything since
// To target 32 bit devices, set this to "arm", and add `-arch` flags
// to the compiler for each architecture. For example:
// `-arch armv7 -arch armv7s -arch arm64`
"BAKE_ARCHITECTURE": "arm64",
"DEPLOYMENT_TARGET": "7.0",
"SDK_NAME": "iphoneos",
"SDK_ROOT": "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
},
"ios-simulator": {
"BAKE_OS": "ios",
"BAKE_ARCHITECTURE": "x86_64",
"DEPLOYMENT_TARGET": "7.0",
"SDK_NAME": "iphonesimulator",
"SDK_ROOT": "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"
},
"tvos": {
"BAKE_OS": "tvos",
// Apple TV 4+
"BAKE_ARCHITECTURE": "arm64",
// 9.0+ for 4th generation hardware, 13.0+ for Apple Arcade apps
"DEPLOYMENT_TARGET": "9.0",
"SDK_NAME": "appletvos",
"SDK_ROOT": "/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk"
},
"tvos-simulator": {
"BAKE_OS": "tvos",
"BAKE_ARCHITECTURE": "x86_64",
"DEPLOYMENT_TARGET": "9.0",
"SDK_NAME": "appletvsimulator",
"SDK_ROOT": "/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk"
},
"watchos": {
"BAKE_OS": "watchos",
// Apple Watch Series 4+ (use armv7k for Series 3 and under)
"BAKE_ARCHITECTURE": "arm64_32",
"DEPLOYMENT_TARGET": "5.0",
"SDK_NAME": "watchos",
"SDK_ROOT": "/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk"
},
"watchos-simulator": {
"BAKE_OS": "watchos",
"BAKE_ARCHITECTURE": "x86_64",
"DEPLOYMENT_TARGET": "5.0",
"SDK_NAME": "watchsimulator",
"SDK_ROOT": "/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk"
}
}
}
{
// `use` this package in ALL projects that need to be cross-compiled.
// That includes all project dependencies, such as `bake.util`.
// Then, to build for your target platform, run a recursive rebuild
// in the target environment: `bake rebuild -r --env ios`
"id": "apple",
"type": "package",
"value": {
"language": "none"
},
"dependee": {
"lang.c": {
"cflags": [
"-fembed-bitcode",
"-target $BAKE_ARCHITECTURE-apple-$BAKE_OS",
"-isysroot $SDK_ROOT",
"-m$SDK_NAME-version-min=$DEPLOYMENT_TARGET"
],
"ldflags": [
"-fembed-bitcode",
"-target $BAKE_ARCHITECTURE-apple-$BAKE_OS",
"-isysroot $SDK_ROOT",
"-m$SDK_NAME-version-min=$DEPLOYMENT_TARGET"
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment