diff --git a/tools/cpp/osx_cc_configure.bzl b/tools/cpp/osx_cc_configure.bzl index e254350edde869..1cdf84949c86e0 100644 --- a/tools/cpp/osx_cc_configure.bzl +++ b/tools/cpp/osx_cc_configure.bzl @@ -53,7 +53,8 @@ def _get_escaped_xcode_cxx_inc_directories(repository_ctx, cc, xcode_toolchains) return include_dirs -def _compile_cc_file(repository_ctx, src_name, out_name): +# TODO: Remove once Xcode 12 is the minimum supported version +def _compile_cc_file_single_arch(repository_ctx, src_name, out_name): env = repository_ctx.os.environ xcrun_result = repository_ctx.execute([ "env", @@ -83,6 +84,32 @@ def _compile_cc_file(repository_ctx, src_name, out_name): "https://github.com/bazelbuild/bazel/issues with the following:\n" + error_msg) +def _compile_cc_file(repository_ctx, src_name, out_name): + env = repository_ctx.os.environ + xcrun_result = repository_ctx.execute([ + "env", + "-i", + "DEVELOPER_DIR={}".format(env.get("DEVELOPER_DIR", default = "")), + "xcrun", + "--sdk", + "macosx", + "clang", + "-mmacosx-version-min=10.9", + "-std=c++11", + "-lc++", + "-arch", + "arm64", + "-arch", + "x86_64", + "-O3", + "-o", + out_name, + src_name, + ], 30) + + if xcrun_result.return_code != 0: + _compile_cc_file_single_arch(repository_ctx, src_name, out_name) + def configure_osx_toolchain(repository_ctx, cpu_value, overriden_tools): """Configure C++ toolchain on macOS.