Skip to content

Commit 28f0e80

Browse files
committed
Build wrapped_clang and wrapped_clang_pp in action
This compiles wrapped_clang and wrapped_clang_pp inside of an action. bazelbuild#8902 has a larger definition of the issue. This action needs the DEVELOPER_DIR as an input in order to select the correct clang. This is passed in from apple_common.XcodeVersionConfig. Note that this works for local execution and needs to address the TODO for cc_wrapper.sh in tools/cpp/osx_cc_configure.bzl.
1 parent c6838bd commit 28f0e80

File tree

3 files changed

+117
-84
lines changed

3 files changed

+117
-84
lines changed

tools/cpp/osx_cc_configure.bzl

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -53,35 +53,6 @@ def _get_escaped_xcode_cxx_inc_directories(repository_ctx, cc, xcode_toolchains)
5353

5454
return include_dirs
5555

56-
def _compile_cc_file(repository_ctx, src_name, out_name):
57-
env = repository_ctx.os.environ
58-
xcrun_result = repository_ctx.execute([
59-
"env",
60-
"-i",
61-
"DEVELOPER_DIR={}".format(env.get("DEVELOPER_DIR", default = "")),
62-
"xcrun",
63-
"--sdk",
64-
"macosx",
65-
"clang",
66-
"-mmacosx-version-min=10.9",
67-
"-std=c++11",
68-
"-lc++",
69-
"-O3",
70-
"-o",
71-
out_name,
72-
src_name,
73-
], 30)
74-
if (xcrun_result.return_code != 0):
75-
error_msg = (
76-
"return code {code}, stderr: {err}, stdout: {out}"
77-
).format(
78-
code = xcrun_result.return_code,
79-
err = xcrun_result.stderr,
80-
out = xcrun_result.stdout,
81-
)
82-
fail(out_name + " failed to generate. Please file an issue at " +
83-
"https://github.com/bazelbuild/bazel/issues with the following:\n" +
84-
error_msg)
8556

8657
def configure_osx_toolchain(repository_ctx, overriden_tools):
8758
"""Configure C++ toolchain on macOS.
@@ -121,6 +92,10 @@ def configure_osx_toolchain(repository_ctx, overriden_tools):
12192
# cc_wrapper.sh script. The wrapped_clang binary is already hardcoded
12293
# into the Objective-C crosstool actions, anyway, so this ensures that
12394
# the C++ actions behave consistently.
95+
96+
# Consider building cc_wrapper.sh an in action with a dep on
97+
# wrapped_clang
98+
# e.g. bazel-out/host/bin/external/local_config_cc/wrapped_clang
12499
cc = repository_ctx.path("wrapped_clang")
125100

126101
cc_path = '"$(/usr/bin/dirname "$0")"/wrapped_clang'
@@ -151,13 +126,6 @@ def configure_osx_toolchain(repository_ctx, overriden_tools):
151126
libtool_check_unique_src_path = str(repository_ctx.path(
152127
paths["@bazel_tools//tools/objc:libtool_check_unique.cc"],
153128
))
154-
_compile_cc_file(repository_ctx, libtool_check_unique_src_path, "libtool_check_unique")
155-
wrapped_clang_src_path = str(repository_ctx.path(
156-
paths["@bazel_tools//tools/osx/crosstool:wrapped_clang.cc"],
157-
))
158-
_compile_cc_file(repository_ctx, wrapped_clang_src_path, "wrapped_clang")
159-
repository_ctx.symlink("wrapped_clang", "wrapped_clang_pp")
160-
161129
tool_paths = {}
162130
gcov_path = repository_ctx.os.environ.get("GCOV")
163131
if gcov_path != None:

tools/osx/crosstool/BUILD.tpl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package(default_visibility = ["//visibility:public"])
22

33
load("@local_config_cc_toolchains//:osx_archs.bzl", "OSX_TOOLS_ARCHS")
44
load("@rules_cc//cc:defs.bzl", "cc_toolchain_suite", "cc_library")
5-
load(":cc_toolchain_config.bzl", "cc_toolchain_config")
5+
load(":cc_toolchain_config.bzl", "cc_toolchain_config", "toolchain_binary")
66

77
# Reexporting osx_arch.bzl for backwards compatibility
88
# Originally this file was present in @local_config_cc, but with the split in
@@ -11,6 +11,9 @@ load(":cc_toolchain_config.bzl", "cc_toolchain_config")
1111
# compatible (and serves no other purpose).
1212
alias(name = "osx_archs.bzl", actual = "@local_config_cc_toolchains//:osx_archs.bzl")
1313

14+
toolchain_binary(name="wrapped_clang", src="@bazel_tools//tools/osx/crosstool:wrapped_clang.cc")
15+
toolchain_binary(name="wrapped_clang_pp", src="@bazel_tools//tools/osx/crosstool:wrapped_clang.cc")
16+
1417
CC_TOOLCHAINS = [(
1518
cpu + "|compiler",
1619
":cc-compiler-" + cpu,
@@ -85,6 +88,8 @@ cc_toolchain_suite(
8588
cc_toolchain_config(
8689
name = (arch if arch != "armeabi-v7a" else "stub_armeabi-v7a"),
8790
compiler = "compiler",
91+
wrapped_clang = ":wrapped_clang",
92+
wrapped_clang = ":wrapped_clang_pp",
8893
cpu = arch,
8994
cxx_builtin_include_directories = [
9095
%{cxx_builtin_include_directories}

0 commit comments

Comments
 (0)