Skip to content

Commit

Permalink
Move Apple toolchain setup to apple_support
Browse files Browse the repository at this point in the history
This moves the CC toolchain for building Apple platforms besides macOS to the apple_support repo bazelbuild/apple_support#113

The default unix toolchain is now used if someone wants to build for macOS without the apple_support toolchain, but it doesn't handle as many platform specific features as the previous toolchain.

Fixes #15041

Closes #16619.

PiperOrigin-RevId: 515546196
Change-Id: Ia54b53e7093c1edbfe8276730aaed5a11a94a027
  • Loading branch information
keith authored and Copybara-Service committed Mar 10, 2023
1 parent f057c74 commit d56dc18
Show file tree
Hide file tree
Showing 26 changed files with 110 additions and 4,536 deletions.
2 changes: 0 additions & 2 deletions .bazelci/postsubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ tasks:
- "//third_party/ijar/..."
- "//tools/android/..."
- "//tools/aquery_differ/..."
- "//tools/osx/crosstool/..."
- "//tools/python/..."
# C++ coverage is not supported on macOS yet.
- "-//src/test/shell/bazel:bazel_cc_code_coverage_test"
Expand Down Expand Up @@ -266,7 +265,6 @@ tasks:
- "//third_party/ijar/..."
- "//tools/android/..."
- "//tools/aquery_differ/..."
- "//tools/osx/crosstool/..."
- "//tools/python/..."
# C++ coverage is not supported on macOS yet.
- "-//src/test/shell/bazel:bazel_cc_code_coverage_test"
Expand Down
2 changes: 0 additions & 2 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ tasks:
- "//third_party/ijar/..."
- "//tools/android/..."
- "//tools/aquery_differ/..."
- "//tools/osx/crosstool/..."
- "//tools/python/..."
# Re-enable once fixed: https://github.com/bazelbuild/bazel/issues/8162
- "-//src/java_tools/buildjar/..."
Expand Down Expand Up @@ -256,7 +255,6 @@ tasks:
- "//third_party/ijar/..."
- "//tools/android/..."
- "//tools/aquery_differ/..."
- "//tools/osx/crosstool/..."
- "//tools/python/..."
# Re-enable once fixed: https://github.com/bazelbuild/bazel/issues/8162
- "-//src/java_tools/buildjar/..."
Expand Down
2 changes: 0 additions & 2 deletions src/create_embedded_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
('*def_parser.exe', lambda x: 'tools/def_parser/def_parser.exe'),
('*zipper.exe', lambda x: 'tools/zip/zipper/zipper.exe'),
('*zipper', lambda x: 'tools/zip/zipper/zipper'),
('*xcode*make_hashed_objlist.py',
lambda x: 'tools/objc/make_hashed_objlist.py'),
('*xcode*xcode-locator', lambda x: 'tools/objc/xcode-locator'),
('*src/tools/xcode/*', lambda x: 'tools/objc/' + os.path.basename(x)),
# --experimental_sibling_repository_layout=false
Expand Down
10 changes: 10 additions & 0 deletions src/main/starlark/builtins_bzl/common/objc/objc_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ load("@_builtins//:common/objc/attrs.bzl", "common_attrs")
load("@_builtins//:common/objc/objc_common.bzl", "extensions")
load("@_builtins//:common/objc/transitions.bzl", "apple_crosstool_transition")
load("@_builtins//:common/cc/cc_helper.bzl", "cc_helper")
load(":common/cc/cc_common.bzl", "cc_common")
load(":common/cc/cc_info.bzl", "CcInfo")

objc_internal = _builtins.internal.objc_internal
Expand Down Expand Up @@ -55,6 +56,15 @@ def _objc_library_impl(ctx):
_validate_attributes(srcs = ctx.attr.srcs, non_arc_srcs = ctx.attr.non_arc_srcs, label = ctx.label)

cc_toolchain = cc_helper.find_cpp_toolchain(ctx)
feature_configuration = cc_common.configure_features(
ctx = ctx,
cc_toolchain = cc_toolchain,
requested_features = ctx.features,
unsupported_features = ctx.disabled_features,
)

if not cc_common.action_is_enabled(feature_configuration = feature_configuration, action_name = "objc-compile"):
fail("Compiling objc_library targets requires the Apple CC toolchain which can be found here: https://github.com/bazelbuild/apple_support")

common_variables = compilation_support.build_common_variables(
ctx = ctx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public final class MockObjcSupport {
"tvos_x86_64",
"tvos_arm64");

private static final ImmutableList<String> DEFAULT_OSX_CROSSTOOL_DEPS_DIRS =
ImmutableList.of("third_party/bazel/tools/osx/crosstool");
public static final String DEFAULT_OSX_CROSSTOOL_DIR = "tools/osx/crosstool";
private static final String MOCK_OSX_TOOLCHAIN_CONFIG_PATH =
"com/google/devtools/build/lib/packages/util/mock/osx_cc_toolchain_config.bzl";
Expand Down Expand Up @@ -235,9 +233,6 @@ public static void setup(MockToolsConfig config) throws IOException {
public static void setupCcToolchainConfig(
MockToolsConfig config, CcToolchainConfig.Builder ccToolchainConfig) throws IOException {
if (config.isRealFileSystem()) {
for (String depDir : DEFAULT_OSX_CROSSTOOL_DEPS_DIRS) {
config.linkTools(depDir);
}
config.linkTools(DEFAULT_OSX_CROSSTOOL_DIR);
} else {
CcToolchainConfig toolchainConfig = ccToolchainConfig.build();
Expand All @@ -261,9 +256,6 @@ public static void setupCcToolchainConfig(

public static void setupCcToolchainConfig(MockToolsConfig config) throws IOException {
if (config.isRealFileSystem()) {
for (String depDir : DEFAULT_OSX_CROSSTOOL_DEPS_DIRS) {
config.linkTools(depDir);
}
config.linkTools(DEFAULT_OSX_CROSSTOOL_DIR);
} else {
new Crosstool(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,7 @@ def _impl(ctx):

if (ctx.attr.cpu == "x64_windows"):
objc_compile_action = action_config(
enabled = True,
action_name = ACTION_NAMES.objc_compile,
flag_sets = [
flag_set(
Expand Down Expand Up @@ -1255,6 +1256,7 @@ def _impl(ctx):
)
elif (ctx.attr.cpu == "ios_arm64"):
objc_compile_action = action_config(
enabled = True,
action_name = ACTION_NAMES.objc_compile,
flag_sets = [
flag_set(
Expand Down Expand Up @@ -1287,6 +1289,7 @@ def _impl(ctx):
)
elif (ctx.attr.cpu == "tvos_arm64"):
objc_compile_action = action_config(
enabled = True,
action_name = ACTION_NAMES.objc_compile,
flag_sets = [
flag_set(
Expand Down Expand Up @@ -1319,6 +1322,7 @@ def _impl(ctx):
)
elif (ctx.attr.cpu == "ios_armv7"):
objc_compile_action = action_config(
enabled = True,
action_name = ACTION_NAMES.objc_compile,
flag_sets = [
flag_set(
Expand Down Expand Up @@ -1351,6 +1355,7 @@ def _impl(ctx):
)
elif (ctx.attr.cpu == "watchos_armv7k"):
objc_compile_action = action_config(
enabled = True,
action_name = ACTION_NAMES.objc_compile,
flag_sets = [
flag_set(
Expand Down Expand Up @@ -1383,6 +1388,7 @@ def _impl(ctx):
)
elif (ctx.attr.cpu == "watchos_arm64_32"):
objc_compile_action = action_config(
enabled = True,
action_name = ACTION_NAMES.objc_compile,
flag_sets = [
flag_set(
Expand Down Expand Up @@ -1415,6 +1421,7 @@ def _impl(ctx):
)
elif (ctx.attr.cpu == "ios_i386"):
objc_compile_action = action_config(
enabled = True,
action_name = ACTION_NAMES.objc_compile,
flag_sets = [
flag_set(
Expand Down Expand Up @@ -1448,6 +1455,7 @@ def _impl(ctx):
)
elif (ctx.attr.cpu == "watchos_i386"):
objc_compile_action = action_config(
enabled = True,
action_name = ACTION_NAMES.objc_compile,
flag_sets = [
flag_set(
Expand Down Expand Up @@ -1481,6 +1489,7 @@ def _impl(ctx):
)
elif (ctx.attr.cpu == "watchos_x86_64"):
objc_compile_action = action_config(
enabled = True,
action_name = ACTION_NAMES.objc_compile,
flag_sets = [
flag_set(
Expand Down Expand Up @@ -1514,6 +1523,7 @@ def _impl(ctx):
)
elif (ctx.attr.cpu == "ios_x86_64"):
objc_compile_action = action_config(
enabled = True,
action_name = ACTION_NAMES.objc_compile,
flag_sets = [
flag_set(
Expand Down Expand Up @@ -1547,6 +1557,7 @@ def _impl(ctx):
)
elif (ctx.attr.cpu == "tvos_x86_64"):
objc_compile_action = action_config(
enabled = True,
action_name = ACTION_NAMES.objc_compile,
flag_sets = [
flag_set(
Expand Down Expand Up @@ -1580,6 +1591,7 @@ def _impl(ctx):
)
elif (ctx.attr.cpu == "darwin_x86_64"):
objc_compile_action = action_config(
enabled = True,
action_name = ACTION_NAMES.objc_compile,
flag_sets = [
flag_set(
Expand Down
2 changes: 1 addition & 1 deletion src/test/py/bazel/bzlmod/bzlmod_query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def testAqueryModuleRepoTargetsBelow(self):
allow_failure=False)
# This label is stringified into a "purpose" in some action before it
# reaches aquery code, so can't decanonicalize it.
self.assertEqual(stdout[0], 'cc_library-compile for @aaa~1.0//:lib_aaa')
self.assertIn('cc_library-compile for @aaa~1.0//:lib_aaa', stdout)
self.assertIn('Target: @my_repo//:lib_aaa', stdout)

def testAqueryModuleRepoTransitiveDeps(self):
Expand Down
1 change: 0 additions & 1 deletion src/test/shell/bazel/apple/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ sh_test(
"//:workspace-file",
"//src/test/shell/bazel:test-deps",
],
shard_count = 3,
tags = ["no_windows"],
)

Expand Down
Loading

0 comments on commit d56dc18

Please sign in to comment.