From db7888b13f94fd59194f0a2003968e7c11ac46d7 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 21 Mar 2024 12:30:16 -0700 Subject: [PATCH] Detect supported features instead of using a Xcode version check This is 1 step towards allowing us to support the Xcode Command Line Tools without easily being able to tell what version of those are installed. --- crosstool/BUILD.tpl | 3 +++ crosstool/cc_toolchain_config.bzl | 3 +-- crosstool/osx_cc_configure.bzl | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/crosstool/BUILD.tpl b/crosstool/BUILD.tpl index 8495ae5..1a1be01 100644 --- a/crosstool/BUILD.tpl +++ b/crosstool/BUILD.tpl @@ -79,6 +79,9 @@ cc_toolchain_suite( cc_toolchain_config( name = arch, cpu = arch, + features = [ +%{features} + ], cxx_builtin_include_directories = [ %{cxx_builtin_include_directories} ], diff --git a/crosstool/cc_toolchain_config.bzl b/crosstool/cc_toolchain_config.bzl index 3353145..dc8868a 100644 --- a/crosstool/cc_toolchain_config.bzl +++ b/crosstool/cc_toolchain_config.bzl @@ -31,7 +31,6 @@ load( "with_feature_set", ) load("@build_bazel_apple_support//lib:apple_support.bzl", "apple_support") -load("@build_bazel_apple_support//lib:xcode_support.bzl", "xcode_support") # TODO: Remove when we drop bazel 6.x support _OBJC_ARCHIVE_ACTION_NAME = "objc-archive" @@ -2509,7 +2508,7 @@ please file an issue at https://github.com/bazelbuild/apple_support/issues/new # these warnings. no_warn_duplicate_libraries_feature = feature( name = "no_warn_duplicate_libraries", - enabled = xcode_support.is_xcode_at_least_version(xcode_config, "15.0.0"), + enabled = "no_warn_duplicate_libraries" in ctx.features, flag_sets = [ flag_set( actions = _DYNAMIC_LINK_ACTIONS, diff --git a/crosstool/osx_cc_configure.bzl b/crosstool/osx_cc_configure.bzl index 94d4ca4..eb5b9b4 100644 --- a/crosstool/osx_cc_configure.bzl +++ b/crosstool/osx_cc_configure.bzl @@ -49,6 +49,19 @@ def _get_escaped_xcode_cxx_inc_directories(repository_ctx, xcode_toolchains): return include_dirs +def _succeeds(repository_ctx, *args): + env = repository_ctx.os.environ + result = repository_ctx.execute([ + "env", + "-i", + "DEVELOPER_DIR={}".format(env.get("DEVELOPER_DIR", default = "")), + "xcrun", + "--sdk", + "macosx", + ] + list(args)) + + return result.return_code == 0 + def _compile_cc_file(repository_ctx, src_name, out_name): env = repository_ctx.os.environ xcrun_result = repository_ctx.execute([ @@ -175,6 +188,10 @@ def configure_osx_toolchain(repository_ctx): gcov_path = repository_ctx.which(gcov_path) tool_paths["gcov"] = gcov_path + features = [] + if _succeeds(repository_ctx, "ld", "-no_warn_duplicate_libraries", "-v"): + features.append("no_warn_duplicate_libraries") + escaped_include_paths = _get_escaped_xcode_cxx_inc_directories(repository_ctx, xcode_toolchains) escaped_cxx_include_directories = [] for path in escaped_include_paths: @@ -186,6 +203,7 @@ def configure_osx_toolchain(repository_ctx): build_template, { "%{cxx_builtin_include_directories}": "\n".join(escaped_cxx_include_directories), + "%{features}": "\n".join(['"{}"'.format(x) for x in features]), "%{tool_paths_overrides}": ",\n ".join( ['"%s": "%s"' % (k, v) for k, v in tool_paths.items()], ),