-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This migrates the Apple CC toolchain from bazel into this repo. This allows this to evolve and be updated without a full bazel udpate. Bazel's built in unix toolchain can still be used to build macOS C++ targets, but this repo handles a wider variety of Apple specific flags and requires you have Xcode installed.
- Loading branch information
Showing
26 changed files
with
6,376 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,59 @@ | ||
# Apple Support for [Bazel](https://bazel.build) | ||
|
||
This repository contains helper methods that support building rules that | ||
target Apple platforms. See [the | ||
docs](https://github.com/bazelbuild/apple_support/tree/master/doc) for | ||
how you can use these helpers. Also see | ||
[rules_apple](https://github.com/bazelbuild/rules_apple) and | ||
[rules_swift](https://github.com/bazelbuild/rules_swift) for more Apple | ||
platform rules. | ||
|
||
## Quick setup | ||
|
||
Copy the `WORKSPACE` snippet from [the releases | ||
page](https://github.com/bazelbuild/apple_support/releases). | ||
This repository contains the [Apple CC toolchain](#toolchain-setup), | ||
Apple related [platforms](platforms/BUILD) and | ||
[constraints](constraints/BUILD) definitions, and small helper functions | ||
for rules authors targeting Apple platforms. | ||
|
||
If you want to build iOS, tvOS, watchOS, or macOS apps, use | ||
[`rules_apple`][rules_apple]. | ||
|
||
If you want to build Swift use | ||
[`rules_swift`](https://github.com/bazelbuild/rules_swift). | ||
|
||
See [the documentation](doc) for the helper rules provided by this | ||
repository. | ||
|
||
## Installation | ||
|
||
Copy the `MODULE.bazel` or `WORKSPACE` snippets from [the releases | ||
page](https://github.com/bazelbuild/apple_support/releases) into your | ||
project. | ||
|
||
## Toolchain setup | ||
|
||
The Apple CC toolchain in by this repository provides toolchains for | ||
building for Apple platforms besides macOS. Since Bazel 7 this toolchain | ||
is required when targeting those platforms but the toolchain also | ||
supports Bazel 6. | ||
|
||
To use the Apple CC toolchain, pull this repository into your build and | ||
add this to your `.bazelrc`: | ||
|
||
```bzl | ||
build --enable_platform_specific_config | ||
build:macos --apple_crosstool_top=@local_config_apple_cc//:toolchain | ||
build:macos --crosstool_top=@local_config_apple_cc//:toolchain | ||
build:macos --host_crosstool_top=@local_config_apple_cc//:toolchain | ||
``` | ||
|
||
This ensures that all rules provided by [`rules_apple`][rules_apple], as | ||
well as other rules like `cc_binary`, all use the toolchain provided by | ||
this repository when building on macOS. | ||
|
||
NOTE: This toolchain requires a full Xcode installation, not just the | ||
Xcode Command Line Tools. If you only need to build for macOS and don't | ||
want to require a full Xcode installation in your build, use the builtin | ||
Unix toolchain provided by Bazel. | ||
|
||
### Incompatible toolchain resolution | ||
|
||
Bazel is currently working on migrating C++ toolchain configuration to a | ||
new discovery method that no longer uses the `--*crosstool_top` flags. | ||
If you would like to test this upcoming feature, or need to use this in | ||
your build for other reasons, you can use this toolchain with | ||
`--incompatible_enable_cc_toolchain_resolution` as long as you provide a | ||
`platform_mappings` file. Please file any issues you find as you test | ||
this work in progress configuration. | ||
|
||
[rules_apple]: https://github.com/bazelbuild/rules_apple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
# Files which shouldn't be publicly visible and dependencies of all objc_* or ios_* rules should be excluded. | ||
exports_files(glob( | ||
["**"], | ||
)) | ||
|
||
cc_binary( | ||
name = "wrapped_clang", | ||
testonly = True, | ||
srcs = [ | ||
"wrapped_clang.cc", | ||
], | ||
) | ||
|
||
# Consumed by bazel tests. | ||
filegroup( | ||
name = "for_bazel_tests", | ||
testonly = True, | ||
srcs = glob(["**"]), | ||
visibility = ["//:__pkg__"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
# Target constraints for each arch. | ||
# TODO(apple-rules): Rename osx constraint to macOS. | ||
OSX_TOOLS_CONSTRAINTS = { | ||
"armeabi-v7a": ["@platforms//cpu:arm"], | ||
"darwin_arm64": [ | ||
"@platforms//os:osx", | ||
"@platforms//cpu:arm64", | ||
], | ||
"darwin_arm64e": [ | ||
"@platforms//os:osx", | ||
"@platforms//cpu:arm64", | ||
], | ||
"darwin_x86_64": [ | ||
"@platforms//os:osx", | ||
"@platforms//cpu:x86_64", | ||
], | ||
"ios_arm64": [ | ||
"@platforms//os:ios", | ||
"@platforms//cpu:arm64", | ||
"@build_bazel_apple_support//constraints:device", | ||
], | ||
"ios_arm64e": [ | ||
"@platforms//os:ios", | ||
"@platforms//cpu:arm64", | ||
], | ||
"ios_armv7": [ | ||
"@platforms//os:ios", | ||
"@platforms//cpu:armv7", | ||
], | ||
"ios_i386": [ | ||
"@platforms//os:ios", | ||
"@platforms//cpu:i386", | ||
], | ||
"ios_x86_64": [ | ||
"@platforms//os:ios", | ||
"@platforms//cpu:x86_64", | ||
], | ||
"ios_sim_arm64": [ | ||
"@platforms//os:ios", | ||
"@platforms//cpu:arm64", | ||
"@build_bazel_apple_support//constraints:simulator", | ||
], | ||
"tvos_arm64": [ | ||
"@platforms//os:tvos", | ||
"@platforms//cpu:arm64", | ||
"@build_bazel_apple_support//constraints:device", | ||
], | ||
"tvos_x86_64": [ | ||
"@platforms//os:tvos", | ||
"@platforms//cpu:x86_64", | ||
], | ||
"tvos_sim_arm64": [ | ||
"@platforms//os:tvos", | ||
"@platforms//cpu:arm64", | ||
"@build_bazel_apple_support//constraints:simulator", | ||
], | ||
"watchos_arm64": [ | ||
"@platforms//os:watchos", | ||
"@platforms//cpu:arm64", | ||
], | ||
"watchos_arm64_32": [ | ||
"@platforms//os:watchos", | ||
"@platforms//cpu:arm64_32", | ||
], | ||
"watchos_armv7k": [ | ||
"@platforms//os:watchos", | ||
"@platforms//cpu:armv7k", | ||
], | ||
"watchos_i386": [ | ||
"@platforms//os:watchos", | ||
"@platforms//cpu:i386", | ||
], | ||
"watchos_x86_64": [ | ||
"@platforms//os:watchos", | ||
"@platforms//cpu:x86_64", | ||
], | ||
} | ||
|
||
OSX_DEVELOPER_PLATFORM_CPUS = [ | ||
"arm64", | ||
"x86_64", | ||
] | ||
|
||
[ | ||
toolchain( | ||
name = "cc-toolchain-" + arch + "-" + cpu, | ||
exec_compatible_with = [ | ||
# These only execute on macOS. | ||
"@platforms//os:osx", | ||
"@platforms//cpu:" + cpu, | ||
], | ||
target_compatible_with = OSX_TOOLS_CONSTRAINTS[arch], | ||
toolchain = "@local_config_apple_cc//:cc-compiler-" + arch, | ||
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", | ||
) | ||
for arch in OSX_TOOLS_CONSTRAINTS.keys() | ||
for cpu in OSX_DEVELOPER_PLATFORM_CPUS | ||
] |
Oops, something went wrong.