Skip to content

Commit

Permalink
Detect supported features instead of using a Xcode version check (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
keith committed Apr 9, 2024
1 parent d59a3e0 commit d2f24eb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions crosstool/BUILD.tpl
Expand Up @@ -79,6 +79,9 @@ cc_toolchain_suite(
cc_toolchain_config(
name = arch,
cpu = arch,
features = [
%{features}
],
cxx_builtin_include_directories = [
%{cxx_builtin_include_directories}
],
Expand Down
3 changes: 1 addition & 2 deletions crosstool/cc_toolchain_config.bzl
Expand Up @@ -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"
Expand Down Expand Up @@ -2504,7 +2503,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,
Expand Down
18 changes: 18 additions & 0 deletions crosstool/osx_cc_configure.bzl
Expand Up @@ -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([
Expand Down Expand Up @@ -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:
Expand All @@ -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()],
),
Expand Down

0 comments on commit d2f24eb

Please sign in to comment.