diff --git a/toolchain/BUILD.toolchain.tpl b/toolchain/BUILD.toolchain.tpl index 1200c170..b41b7e64 100644 --- a/toolchain/BUILD.toolchain.tpl +++ b/toolchain/BUILD.toolchain.tpl @@ -34,7 +34,6 @@ filegroup( name = "internal-use-wrapped-tools", srcs = [ "%{wrapper_bin_prefix}cc_wrapper.sh", - "%{wrapper_bin_prefix}host_libtool_wrapper.sh", ], visibility = ["//visibility:private"], ) diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index bf235014..7acb0d95 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -19,7 +19,6 @@ load( load( "//toolchain/internal:common.bzl", _check_os_arch_keys = "check_os_arch_keys", - _host_tool_features = "host_tool_features", _host_tools = "host_tools", _os_arch_pair = "os_arch_pair", ) @@ -304,15 +303,7 @@ def cc_toolchain_config( # TODO: The command line formed on darwin does not work with llvm-ar. ar_binary = tools_path_prefix + "llvm-ar" if host_os == "darwin": - # Bazel uses arg files for longer commands; some old macOS `libtool` - # versions do not support this. - # - # In these cases we want to use `libtool_wrapper.sh` which translates - # the arg file back into command line arguments. - if not _host_tools.tool_supports(host_tools_info, "libtool", features = [_host_tool_features.SUPPORTS_ARG_FILE]): - ar_binary = wrapper_bin_prefix + "host_libtool_wrapper.sh" - else: - ar_binary = host_tools_info["libtool"]["path"] + ar_binary = host_tools_info["libtool"]["path"] # The tool names come from [here](https://github.com/bazelbuild/bazel/blob/c7e58e6ce0a78fdaff2d716b4864a5ace8917626/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java#L76-L90): # NOTE: Ensure these are listed in toolchain_tools in toolchain/internal/common.bzl. diff --git a/toolchain/host_libtool_wrapper.sh.tpl b/toolchain/host_libtool_wrapper.sh.tpl deleted file mode 100644 index 2c00cc29..00000000 --- a/toolchain/host_libtool_wrapper.sh.tpl +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 The Bazel Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Some older `libtool` versions (~macOS 10.12) don't support arg files. -# -# This script flattens arg files into regular command line arguments. - -args=() -for a in "${@}"; do - if [[ ${a} =~ @.* ]]; then - IFS=$'\n' read -d '' -r -a args_in_file < "${a:1}" - for arg in "${args_in_file[@]}"; do - args+=("${arg}") - done - else - args+=("${a}") - fi -done - -exec "%{libtool_path}" "${args[@]}" diff --git a/toolchain/internal/common.bzl b/toolchain/internal/common.bzl index 542c99e6..1d2f0dda 100644 --- a/toolchain/internal/common.bzl +++ b/toolchain/internal/common.bzl @@ -14,10 +14,6 @@ SUPPORTED_TARGETS = [("linux", "x86_64"), ("linux", "aarch64"), ("darwin", "x86_64"), ("darwin", "aarch64")] -host_tool_features = struct( - SUPPORTS_ARG_FILE = "supports_arg_file", -) - toolchain_tools = [ "clang-cpp", "ld.lld", @@ -181,103 +177,31 @@ def attr_dict(attr): return dict(tuples) -# Tries to figure out if a tool supports newline separated arg files (i.e. -# `@file`). -def _tool_supports_arg_file(rctx, tool_path): - # We assume nothing other than that `tool_path` is an executable. - # - # First we have to find out what command line flag gets the tool to just - # print out some text and exit successfully. - # - # Most tools support `-v` or `--version` or (for `libtool`) `-V` but some - # tools don't have such an option (BSD `ranlib` and `ar`, for example). - # - # We just try all the options we know of until one works and if none work - # we return "None" indicating an indeterminate result. - opts = ( - ["-v", "--version", "-version", "-V"] + - ["-h", "--help", "-help", "-H"] - ) - - no_op_opt = None - for opt in opts: - if rctx.execute([tool_path, opt], timeout = 2).return_code == 0: - no_op_opt = opt - break - - if no_op_opt == None: - return None - - # Okay! Once we have an opt that we *know* does nothing but make the - # executable exit successfully, we'll stick that opt in a file and try - # again: - tmp_file = "tmp-arg-file" - rctx.file(tmp_file, content = "{}\n".format(no_op_opt), executable = False) - - res = rctx.execute([tool_path, "@{}".format(tmp_file)]).return_code == 0 - rctx.delete(tmp_file) - - return res - -def _get_host_tool_info(rctx, tool_path, features_to_test = [], tool_key = None): +def _get_host_tool_info(rctx, tool_path, tool_key = None): if tool_key == None: tool_key = tool_path if tool_path == None or not rctx.path(tool_path).exists: return {} - f = host_tool_features - features = {} - for feature in features_to_test: - features[feature] = { - f.SUPPORTS_ARG_FILE: _tool_supports_arg_file, - }[feature](rctx, tool_path) - return { tool_key: struct( path = tool_path, - features = features, + features = [], ), } -def _extract_tool_path_and_features(tool_info): +def _extract_tool_path(tool_info): # Have to support structs or dicts: - tool_path = tool_info.path if type(tool_info) == "struct" else tool_info["path"] - tool_features = tool_info.features if type(tool_info) == "struct" else tool_info["features"] + return tool_info.path if type(tool_info) == "struct" else tool_info["path"] - return (tool_path, tool_features) - -def _check_host_tool_supports(host_tool_info, tool_key, features = []): +def _get_host_tool(host_tool_info, tool_key): if tool_key in host_tool_info: - _, tool_features = _extract_tool_path_and_features(host_tool_info[tool_key]) - - for f in features: - if not f in tool_features or not tool_features[f]: - return False - - return True + return _extract_tool_path(host_tool_info[tool_key]) else: - return False - -def _get_host_tool_and_assert_supports(host_tool_info, tool_key, features = []): - if tool_key in host_tool_info: - tool_path, tool_features = _extract_tool_path_and_features(host_tool_info[tool_key]) - - missing = [f for f in features if not f in tool_features or not tool_features[f]] - - if missing: - fail("Host tool `{key}` (`{path}`) is missing these features: `{missing}`.".format( - key = tool_key, - path = tool_path, - missing = missing, - )) - - return tool_path - else: - return False + return None host_tools = struct( get_tool_info = _get_host_tool_info, - tool_supports = _check_host_tool_supports, - get_and_assert = _get_host_tool_and_assert_supports, + get_and_assert = _get_host_tool, ) diff --git a/toolchain/internal/configure.bzl b/toolchain/internal/configure.bzl index b4521039..b96d26b8 100644 --- a/toolchain/internal/configure.bzl +++ b/toolchain/internal/configure.bzl @@ -18,13 +18,11 @@ load( _canonical_dir_path = "canonical_dir_path", _check_os_arch_keys = "check_os_arch_keys", _host_os_arch_dict_value = "host_os_arch_dict_value", - _host_tool_features = "host_tool_features", _host_tools = "host_tools", _list_to_string = "list_to_string", _os = "os", _os_arch_pair = "os_arch_pair", _os_bzl = "os_bzl", - _pkg_name_from_label = "pkg_name_from_label", _pkg_path_from_label = "pkg_path_from_label", _supported_targets = "SUPPORTED_TARGETS", _toolchain_tools = "toolchain_tools", @@ -40,12 +38,6 @@ load( _aliased_tools = "aliased_tools", ) -def _include_dirs_str(rctx, key): - dirs = rctx.attr.cxx_builtin_include_directories.get(key) - if not dirs: - return "" - return ("\n" + 12 * " ").join(["\"%s\"," % d for d in dirs]) - def llvm_config_impl(rctx): _check_os_arch_keys(rctx.attr.sysroot) _check_os_arch_keys(rctx.attr.cxx_builtin_include_directories) @@ -160,16 +152,16 @@ def llvm_register_toolchains(): host_dl_ext = "dylib" if os == "darwin" else "so" host_tools_info = dict([ pair - for (key, tool_path, features) in [ + for (key, tool_path) in [ # This is used for macOS hosts: - ("libtool", "/usr/bin/libtool", [_host_tool_features.SUPPORTS_ARG_FILE]), + ("libtool", "/usr/bin/libtool"), # This is used with old (pre 7) LLVM versions: - ("strip", "/usr/bin/strip", []), + ("strip", "/usr/bin/strip"), # This is used when lld doesn't support the target platform (i.e. # Mach-O for macOS): - ("ld", "/usr/bin/ld", []), + ("ld", "/usr/bin/ld"), ] - for pair in _host_tools.get_tool_info(rctx, tool_path, features, key).items() + for pair in _host_tools.get_tool_info(rctx, tool_path, key).items() ]) cc_toolchains_str, toolchain_labels_str = _cc_toolchains_str( workspace_name, @@ -221,15 +213,6 @@ def llvm_register_toolchains(): }, ) - # libtool wrapper; used if the host libtool doesn't support arg files: - rctx.template( - "bin/host_libtool_wrapper.sh", - rctx.attr._host_libtool_wrapper_sh_tpl, - { - "%{libtool_path}": "/usr/bin/libtool", - }, - ) - def _cc_toolchains_str( workspace_name, toolchain_info, diff --git a/toolchain/rules.bzl b/toolchain/rules.bzl index 12390309..9c584d0b 100644 --- a/toolchain/rules.bzl +++ b/toolchain/rules.bzl @@ -268,9 +268,6 @@ _llvm_config_attrs.update({ "_cc_wrapper_sh_tpl": attr.label( default = "//toolchain:cc_wrapper.sh.tpl", ), - "_host_libtool_wrapper_sh_tpl": attr.label( - default = "//toolchain:host_libtool_wrapper.sh.tpl", - ), }) llvm = repository_rule(