-
Notifications
You must be signed in to change notification settings - Fork 60
Add Apple CC toolchain setup #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
04a6e15
Add example toolchains setup
keith 92d9c69
Add other var back
keith 8e953ad
Initial mv of crosstool setup
keith a5bb6c3
First pass setup
keith 6bb507e
Remove separate osx_archs.bzl
keith 029317d
Fixup for moved files, fallback to builtin version
keith a0afb2d
Make crosstool tests pass
keith c395f9e
Fix buildifier
keith 245e052
sync with upstream
keith 28f9f2e
Use @local_config_apple_cc for repo
keith a982d7b
buildifier
keith 5c2112d
Add some initial device vs sim constraints
keith 7e7eb22
Add initial tests
keith f946429
Move more tests
keith 978e770
Enable objc_compile for detection
keith b80b588
Add test filegroups
keith 4d1691c
Move wrapped_clang test
keith a024f26
rm
keith 7450436
Add objc-archive back for now
keith 2b6373e
Remove supports_pic
keith 12d0ad4
Add new CI jobs
keith 46b4d51
remove test target
keith 8eb4d6b
all options
keith 3365b62
Move to correct location
keith 0462476
sync upstream no dynamic_lookup
keith 76acb02
Remove unnecessary Xcode logic
keith eec7cd7
Fix setup to not mirror upstream
keith 2889c5b
no rules_cc
keith 1d59f22
bzlmod support
keith 48d65d5
minor todos
keith 0224914
lint
keith 121c3c8
format
keith c3588f4
names
keith 526a361
dup
keith d1f735d
all
keith 2a3bb18
update readme
keith badab2b
more
keith c54b4d7
add env var
keith 77ad32f
Update crosstool/setup.bzl
keith 7a01a5e
Update crosstool/setup.bzl
keith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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. | ||
|
keith marked this conversation as resolved.
|
||
| 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.