This repository contains toolchain configuration rules for Bazel that can be used to build apps and frameworks for Apple platforms from non-Apple platforms. Current supported host is x86_64 Linux only. Requires Bazel 9+.
-
Add the dependency to your
MODULE.bazel:bazel_dep(name = "rules_applecross", version = "0.0.3") git_override( module_name = "rules_applecross", remote = "https://github.com/apple-cross-toolchain/rules_applecross.git", commit = "<commit>", )
-
Configure the toolchain in
MODULE.bazel:apple_cross_toolchain = use_extension( "@rules_applecross//toolchain:extensions.bzl", "apple_cross_toolchain", ) apple_cross_toolchain.configure( name = "apple_cross_toolchain", apple_sdk_urls = ["<url-to-apple-sdk-archive>"], apple_sdk_archive_type = "tar.xz", # if not inferrable from URL ) use_repo(apple_cross_toolchain, "apple_cross_toolchain") register_toolchains("@apple_cross_toolchain//:cc-toolchain-ios_x86_64") register_toolchains("@apple_cross_toolchain//:cc-toolchain-ios_arm64") register_toolchains("@apple_cross_toolchain//:swift-toolchain-ios_x86_64") register_toolchains("@apple_cross_toolchain//:swift-toolchain-ios_arm64") # ... add more platforms as needed (darwin, tvos, watchos)
-
Add the following to your
.bazelrc:build --xcode_version_config=@rules_applecross//xcode_config:host_xcodes build --action_env=DEVELOPER_DIR=external/rules_applecross++apple_cross_toolchain+apple_cross_toolchain/Xcode.app/Contents/Developer build --@build_bazel_rules_apple//apple:sdk_tool_files=@apple_cross_toolchain//:sdk_tool_files -
Build an example:
bazel build @rules_applecross//examples/ios/HelloWorldSwiftUI:HelloWorld
- Apple SDKs archives are not publicly available. If you have access to macOS, you
can build one yourself by running
tools/package-sdks.sh.
-
Define a
platformtarget; for example, inplatforms/BUILD:platform( name = "docker_image_platform", constraint_values = [ "@platforms//cpu:x86_64", "@platforms//os:linux", ], exec_properties = { "OSFamily": "Linux", "container-image": "<your-docker-image>", }, )
-
Add the following to your
.bazelrc:build:remote --bes_backend=grpcs://cloud.buildbuddy.io build:remote --bes_results_url=https://app.buildbuddy.io/invocation/ build:remote --jobs=100 build:remote --remote_download_toplevel build:remote --remote_executor=grpcs://cloud.buildbuddy.io build:remote --remote_timeout=3600 build:remote --strategy=SwiftCompile=remote,sandboxed,worker,local build:remote --tls_client_certificate=buildbuddy-cert.pem build:remote --tls_client_key=buildbuddy-key.pem -
Build with
--config=remote:bazel build --config=remote @rules_applecross//examples/ios/HelloWorldSwiftUI:HelloWorld