From 221dcf75c6bdc6221c5c56cd79c26b2e010aadd6 Mon Sep 17 00:00:00 2001 From: Armando Montanez Date: Fri, 1 Dec 2023 21:34:25 +0000 Subject: [PATCH] pw_toolchain_bazel: Remove deprecated API Removes the deprecated API created as part of the initial exploratory work done for pw_toolchain_bazel. Bug: b/309533028 Change-Id: Iefb9bd96b94c5e8e867e0450d2853ac707e70214 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/183235 Reviewed-by: Erik Gilling Commit-Queue: Armando Montanez --- pw_toolchain_bazel/cc_toolchain/defs.bzl | 7 - .../cc_toolchain/private/cc_toolchain.bzl | 146 +----------- .../cc_toolchain/private/providers.bzl | 9 - .../private/toolchain_feature.bzl | 215 ------------------ pw_toolchain_bazel/features/BUILD.bazel | 70 ------ pw_toolchain_bazel/features/macos/BUILD.bazel | 11 - .../private/xcode_command_line_tools.bzl | 99 ++------ 7 files changed, 24 insertions(+), 533 deletions(-) delete mode 100644 pw_toolchain_bazel/cc_toolchain/private/toolchain_feature.bzl diff --git a/pw_toolchain_bazel/cc_toolchain/defs.bzl b/pw_toolchain_bazel/cc_toolchain/defs.bzl index 57d8280b22..9cca1f1465 100644 --- a/pw_toolchain_bazel/cc_toolchain/defs.bzl +++ b/pw_toolchain_bazel/cc_toolchain/defs.bzl @@ -34,10 +34,6 @@ load( _pw_cc_flag_group = "pw_cc_flag_group", _pw_cc_flag_set = "pw_cc_flag_set", ) -load( - "//cc_toolchain/private:toolchain_feature.bzl", - _pw_cc_toolchain_feature = "pw_cc_toolchain_feature", -) load( "//cc_toolchain/private:utils.bzl", _ALL_AR_ACTIONS = "ALL_AR_ACTIONS", @@ -74,6 +70,3 @@ pw_cc_flag_group = _pw_cc_flag_group pw_cc_flag_set = _pw_cc_flag_set pw_cc_toolchain = _pw_cc_toolchain - -# TODO: b/309533028 - This is deprecated, and will soon be removed. -pw_cc_toolchain_feature = _pw_cc_toolchain_feature diff --git a/pw_toolchain_bazel/cc_toolchain/private/cc_toolchain.bzl b/pw_toolchain_bazel/cc_toolchain/private/cc_toolchain.bzl index 5c9c5cd0e6..41b3adabde 100644 --- a/pw_toolchain_bazel/cc_toolchain/private/cc_toolchain.bzl +++ b/pw_toolchain_bazel/cc_toolchain/private/cc_toolchain.bzl @@ -22,20 +22,14 @@ load( "feature", "flag_group", "flag_set", - "tool", "variable_with_value", ) load( "//cc_toolchain/private:providers.bzl", "ActionConfigListInfo", - "ToolchainFeatureInfo", ) load( "//cc_toolchain/private:utils.bzl", - "ALL_ASM_ACTIONS", - "ALL_CPP_COMPILER_ACTIONS", - "ALL_C_COMPILER_ACTIONS", - "ALL_LINK_ACTIONS", "actionless_flag_set", "check_deps_provide", ) @@ -61,9 +55,8 @@ PW_CC_TOOLCHAIN_DEPRECATED_TOOL_ATTRS = { } PW_CC_TOOLCHAIN_CONFIG_ATTRS = { - "action_configs": "List of pw_cc_action_config labels that match tools to the appropriate actions", - "action_config_flag_sets": "List of flag sets to apply to the respective action_configs", - "feature_deps": "pw_cc_toolchain_feature labels that provide features for this toolchain", + "action_configs": "List of `pw_cc_action_config` labels that match tools to the appropriate actions", + "action_config_flag_sets": "List of `pw_cc_flag_set`s to apply to their respective action configs", # Attributes originally part of create_cc_toolchain_config_info. "toolchain_identifier": "See documentation for cc_common.create_cc_toolchain_config_info()", @@ -84,36 +77,11 @@ PW_CC_TOOLCHAIN_SHARED_ATTRS = ["toolchain_identifier"] PW_CC_TOOLCHAIN_BLOCKED_ATTRS = { "toolchain_config": "pw_cc_toolchain includes a generated toolchain config", "artifact_name_patterns": "pw_cc_toolchain does not yet support artifact name patterns", - "features": "Use feature_deps to add pw_cc_toolchain_feature deps to the toolchain", - "tool_paths": "pw_cc_toolchain does not support tool_paths, use \"ar\", \"cpp\", \"gcc\", \"gcov\", \"ld\", and \"strip\" attributes to set toolchain tools", + "features": "pw_cc_toolchain does not yet support features", + "tool_paths": "pw_cc_toolchain does not support tool_paths, use \"action_configs\" to set toolchain tools", "make_variables": "pw_cc_toolchain does not yet support make variables", } -def _action_configs(action_tool, action_list, flag_sets_by_action): - """Binds a tool to an action. - - Args: - action_tool (File): Tool to bind to the specified actions. - action_list (List[str]): List of actions to bind to the specified tool. - flag_sets_by_action: Dictionary mapping action names to lists of applicable flag sets. - - Returns: - action_config: A action_config binding the provided tool to the - specified actions. - """ - return [ - action_config( - action_name = action, - tools = [ - tool( - tool = action_tool, - ), - ], - flag_sets = flag_sets_by_action.get(action, default = []), - ) - for action in action_list - ] - def _archiver_flags_feature(is_mac): """Returns our implementation of the legacy archiver_flags feature. @@ -187,72 +155,6 @@ def _archiver_flags_feature(is_mac): ], ) -def _generate_action_configs(ctx, flag_sets_by_action): - """Legacy logic for generation of `action_config`s. - - Args: - ctx: Rule context. - flag_sets_by_action: A mapping of action name to a list of FlagSetInfo - providers. - - Returns: - list of `action_config` providers. - """ - all_actions = [] - all_actions += _action_configs(ctx.executable.gcc, ALL_ASM_ACTIONS, flag_sets_by_action) - all_actions += _action_configs(ctx.executable.gcc, ALL_C_COMPILER_ACTIONS, flag_sets_by_action) - all_actions += _action_configs(ctx.executable.cpp, ALL_CPP_COMPILER_ACTIONS, flag_sets_by_action) - all_actions += _action_configs(ctx.executable.cpp, ALL_LINK_ACTIONS, flag_sets_by_action) - all_actions += [ - action_config( - action_name = ACTION_NAMES.cpp_link_static_library, - implies = ["archiver_flags", "linker_param_file"], - tools = [ - tool( - tool = ctx.executable.ar, - ), - ], - flag_sets = flag_sets_by_action.get(ACTION_NAMES.cpp_link_static_library, default = []), - ), - action_config( - action_name = ACTION_NAMES.llvm_cov, - tools = [ - tool( - tool = ctx.executable.gcov, - ), - ], - flag_sets = flag_sets_by_action.get(ACTION_NAMES.llvm_cov, default = []), - ), - action_config( - action_name = OBJ_COPY_ACTION_NAME, - tools = [ - tool( - tool = ctx.executable.objcopy, - ), - ], - flag_sets = flag_sets_by_action.get(OBJ_COPY_ACTION_NAME, default = []), - ), - action_config( - action_name = OBJ_DUMP_ACTION_NAME, - tools = [ - tool( - tool = ctx.executable.objdump, - ), - ], - flag_sets = flag_sets_by_action.get(OBJ_DUMP_ACTION_NAME, default = []), - ), - action_config( - action_name = ACTION_NAMES.strip, - tools = [ - tool( - tool = ctx.executable.strip, - ), - ], - flag_sets = flag_sets_by_action.get(ACTION_NAMES.strip, default = []), - ), - ] - return all_actions - def _extend_action_set_flags(action, flag_sets_by_action): extended_flags = flag_sets_by_action.get(action.action_name, default = []) for x in extended_flags: @@ -331,37 +233,18 @@ def _pw_cc_toolchain_config_impl(ctx): Returns: CcToolchainConfigInfo """ - check_deps_provide(ctx, "feature_deps", ToolchainFeatureInfo, "pw_cc_toolchain_feature") check_deps_provide(ctx, "action_config_flag_sets", FlagSetInfo, "pw_cc_flag_set") flag_sets_by_action = _create_action_flag_set_map([dep[FlagSetInfo] for dep in ctx.attr.action_config_flag_sets]) + all_actions = _collect_action_configs(ctx, flag_sets_by_action) + builtin_include_dirs = ctx.attr.cxx_builtin_include_directories if ctx.attr.cxx_builtin_include_directories else [] + sysroot_dir = ctx.attr.builtin_sysroot if ctx.attr.builtin_sysroot else None - all_actions = [] - - should_generate_action_configs = False - for key in PW_CC_TOOLCHAIN_DEPRECATED_TOOL_ATTRS.keys(): - if getattr(ctx.attr, key, None): - if ctx.attr.action_configs: - fail("Specifying tool names is incompatible with action configs") - should_generate_action_configs = True - if should_generate_action_configs: - all_actions = _generate_action_configs(ctx, flag_sets_by_action) - else: - all_actions = _collect_action_configs(ctx, flag_sets_by_action) + # TODO: b/309533028 - Support features. + features = [] - features = [dep[ToolchainFeatureInfo].feature for dep in ctx.attr.feature_deps] + # TODO: b/297413805 - This could be externalized. features.append(_archiver_flags_feature(ctx.attr.target_libc == "macosx")) - builtin_include_dirs = ctx.attr.cxx_builtin_include_directories if ctx.attr.cxx_builtin_include_directories else [] - for dep in ctx.attr.feature_deps: - builtin_include_dirs.extend(dep[ToolchainFeatureInfo].cxx_builtin_include_directories) - - sysroot_dir = ctx.attr.builtin_sysroot if ctx.attr.builtin_sysroot else None - for dep in ctx.attr.feature_deps: - dep_sysroot = dep[ToolchainFeatureInfo].builtin_sysroot - if dep_sysroot: - if sysroot_dir: - fail("Failed to set sysroot at `{}`, already have sysroot at `{}` ".format(dep_sysroot, sysroot_dir)) - sysroot_dir = dep_sysroot return cc_common.create_cc_toolchain_config_info( ctx = ctx, @@ -384,15 +267,6 @@ pw_cc_toolchain_config = rule( implementation = _pw_cc_toolchain_config_impl, attrs = { # Attributes new to this rule. - "feature_deps": attr.label_list(), - "gcc": attr.label(allow_single_file = True, executable = True, cfg = "exec"), - "ld": attr.label(allow_single_file = True, executable = True, cfg = "exec"), - "ar": attr.label(allow_single_file = True, executable = True, cfg = "exec"), - "cpp": attr.label(allow_single_file = True, executable = True, cfg = "exec"), - "gcov": attr.label(allow_single_file = True, executable = True, cfg = "exec"), - "objcopy": attr.label(allow_single_file = True, executable = True, cfg = "exec"), - "objdump": attr.label(allow_single_file = True, executable = True, cfg = "exec"), - "strip": attr.label(allow_single_file = True, executable = True, cfg = "exec"), "action_configs": attr.label_list(), "action_config_flag_sets": attr.label_list(), diff --git a/pw_toolchain_bazel/cc_toolchain/private/providers.bzl b/pw_toolchain_bazel/cc_toolchain/private/providers.bzl index a7c2ceea19..e90a822054 100644 --- a/pw_toolchain_bazel/cc_toolchain/private/providers.bzl +++ b/pw_toolchain_bazel/cc_toolchain/private/providers.bzl @@ -22,12 +22,3 @@ ActionConfigListInfo = provider( "action_configs": "List[ActionConfigInfo]: A list of ActionConfigInfo providers.", }, ) - -ToolchainFeatureInfo = provider( - doc = "A provider containing cc_toolchain features and related fields.", - fields = { - "feature": "feature: A group of build flags structured as a toolchain feature.", - "cxx_builtin_include_directories": "List[str]: Builtin C/C++ standard library include directories.", - "builtin_sysroot": "str: Path to the sysroot directory. Use `external/[repo_name]` for sysroots provided as an external repository.", - }, -) diff --git a/pw_toolchain_bazel/cc_toolchain/private/toolchain_feature.bzl b/pw_toolchain_bazel/cc_toolchain/private/toolchain_feature.bzl deleted file mode 100644 index e16d331dab..0000000000 --- a/pw_toolchain_bazel/cc_toolchain/private/toolchain_feature.bzl +++ /dev/null @@ -1,215 +0,0 @@ -# Copyright 2023 The Pigweed 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 -# -# https://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. -"""Implementation of the pw_cc_toolchain_feature rule.""" - -load( - "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", - "feature", - "flag_group", - "flag_set", -) -load( - "//cc_toolchain/private:providers.bzl", - "ToolchainFeatureInfo", -) -load("//cc_toolchain/private:utils.bzl", "ACTION_MAP") - -TOOLCHAIN_FEATURE_INFO_ATTRS = { - "aropts": "List[str]: Flags to pass to all archive actions", - "asmopts": "List[str]: Flags to pass to assembler actions", - "copts": "List[str]: Flags to pass to all C/C++ compile actions", - "conlyopts": "List[str]: Flags to pass to C compile actions", - "cxxopts": "List[str]: Flags to pass to C++ compile actions", - "linkopts": "List[str]: Flags to pass to C compile actions", - "linker_files": "List[File]: Files to link", - "cxx_builtin_include_directories": "List[str]: Paths to C++ standard library include directories", - "builtin_sysroot": "str: Path to the directory containing the sysroot", -} - -def _dict_to_str(dict_to_stringify): - """Converts a dictionary to a multi-line string. - - Args: - dict_to_stringify (Dict[str, str]): Dictionary to stringify. - - Returns: - str: Multi-line string representing the dictionary, or {empty}. - """ - result = [] - for key in dict_to_stringify.keys(): - result.append(" {}: {}".format(key, dict_to_stringify[key])) - if not result: - return "{empty}" - return "\n".join(["{"] + result + ["}"]) - -def _feature_flag_set(actions, flags): - """Transforms a list of flags and actions into a flag_set. - - Args: - actions (List[str]): Actions that the provided flags will be applied to. - flags (List[str]): List of flags to apply to the specified actions. - - Returns: - flag_set: A flag_set binding the provided flags to the specified - actions. - """ - return flag_set( - actions = actions, - flag_groups = ([ - flag_group( - flags = flags, - ), - ]), - ) - -def _check_args(ctx, **kwargs): - """Checks that args provided to build_toolchain_feature_info are valid. - - Args: - ctx: The context of the current build rule. - **kwargs: All attributes supported by pw_cc_toolchain_feature. - - Returns: - None - """ - for key in kwargs.keys(): - if key not in TOOLCHAIN_FEATURE_INFO_ATTRS: - fail( - "Unknown attribute \"{}\" used by {}. Valid attributes are:\n{}".format( - key, - ctx.label, - _dict_to_str(TOOLCHAIN_FEATURE_INFO_ATTRS), - ), - ) - -def _build_flag_sets(**kwargs): - """Transforms a dictionary of arguments into a list of flag_sets. - - Args: - **kwargs: All attributes supported by pw_cc_toolchain_feature. - - Returns: - List[flag_set]: A list of flag_sets that bind all provided flags to - their appropriate actions. - """ - all_flags = [] - for action in ACTION_MAP.keys(): - if kwargs[action]: - all_flags.append(_feature_flag_set(ACTION_MAP[action], kwargs[action])) - return all_flags - -def _initialize_args(**kwargs): - """Initializes build_toolchain_feature_info arguments. - - Args: - **kwargs: All attributes supported by pw_cc_toolchain_feature. - - Returns: - Dict[str, Any]: Dictionary containing arguments default initialized to - be compatible with _build_flag_sets. - """ - initialized_args = {} - for action in ACTION_MAP.keys(): - if action in kwargs: - initialized_args[action] = kwargs[action] - else: - initialized_args[action] = [] - - if "linker_files" in kwargs: - linker_files = kwargs["linker_files"] - linker_flags = [file.path for file in linker_files] - - initialized_args["linkopts"] = initialized_args["linkopts"] + linker_flags - initialized_args["linker_files"] = depset(linker_files) - else: - initialized_args["linker_files"] = depset() - - if "cxx_builtin_include_directories" in kwargs: - initialized_args["cxx_builtin_include_directories"] = kwargs["cxx_builtin_include_directories"] - else: - initialized_args["cxx_builtin_include_directories"] = [] - - if "builtin_sysroot" in kwargs: - initialized_args["builtin_sysroot"] = kwargs["builtin_sysroot"] - else: - initialized_args["builtin_sysroot"] = None - return initialized_args - -def build_toolchain_feature_info(ctx, **kwargs): - """Builds a ToolchainFeatureInfo provider. - - Args: - ctx: The context of the current build rule. - **kwargs: All attributes supported by pw_cc_toolchain_feature. - - Returns: - ToolchainFeatureInfo, DefaultInfo: All providers supported by - pw_cc_toolchain_feature. - """ - _check_args(ctx, **kwargs) - - initialized_args = _initialize_args(**kwargs) - - new_feature = feature( - name = ctx.attr.name, - enabled = True, - flag_sets = _build_flag_sets(**initialized_args), - ) - - return [ - ToolchainFeatureInfo( - feature = new_feature, - cxx_builtin_include_directories = initialized_args["cxx_builtin_include_directories"], - builtin_sysroot = initialized_args["builtin_sysroot"], - ), - DefaultInfo(files = initialized_args["linker_files"]), - ] - -def _pw_cc_toolchain_feature_impl(ctx): - """Rule that provides ToolchainFeatureInfo. - - Args: - ctx: The context of the current build rule. - - Returns: - ToolchainFeatureInfo, DefaultInfo - """ - return build_toolchain_feature_info( - ctx = ctx, - aropts = ctx.attr.aropts, - asmopts = ctx.attr.asmopts, - copts = ctx.attr.copts, - conlyopts = ctx.attr.conlyopts, - cxxopts = ctx.attr.cxxopts, - linkopts = ctx.attr.linkopts, - linker_files = ctx.files.linker_files, - cxx_builtin_include_directories = ctx.attr.cxx_builtin_include_directories, - builtin_sysroot = ctx.attr.builtin_sysroot, - ) - -pw_cc_toolchain_feature = rule( - implementation = _pw_cc_toolchain_feature_impl, - attrs = { - "aropts": attr.string_list(), - "asmopts": attr.string_list(), - "copts": attr.string_list(), - "conlyopts": attr.string_list(), - "cxxopts": attr.string_list(), - "linkopts": attr.string_list(), - "linker_files": attr.label_list(allow_files = True), - "cxx_builtin_include_directories": attr.string_list(), - "builtin_sysroot": attr.string(), - }, - provides = [ToolchainFeatureInfo, DefaultInfo], -) diff --git a/pw_toolchain_bazel/features/BUILD.bazel b/pw_toolchain_bazel/features/BUILD.bazel index c41e013960..8b13f55e37 100644 --- a/pw_toolchain_bazel/features/BUILD.bazel +++ b/pw_toolchain_bazel/features/BUILD.bazel @@ -12,76 +12,6 @@ # License for the specific language governing permissions and limitations under # the License. -load("//cc_toolchain:defs.bzl", "pw_cc_toolchain_feature") - package(default_visibility = ["//visibility:public"]) licenses(["notice"]) - -# Optimization level option -pw_cc_toolchain_feature( - name = "o2", - copts = ["-O2"], - linkopts = ["-O2"], -) - -# Disables linking of the default C++ standard library to allow linking of a -# different version. -pw_cc_toolchain_feature( - name = "no_default_cpp_stdlib", - linkopts = ["-nostdlib++"], -) - -# Prevent relative paths from being converted to absolute paths. -pw_cc_toolchain_feature( - name = "no_canonical_prefixes", - copts = [ - "-no-canonical-prefixes", - ], -) - -# Compile without runtime type information (RTTI). This produces smaller binaries. -pw_cc_toolchain_feature( - name = "no_rtti", - cxxopts = [ - "-fno-rtti", - ], -) - -# Allow uses of the register keyword, which may appear in C headers. -pw_cc_toolchain_feature( - name = "wno_register", - cxxopts = [ - "-Wno-register", - ], -) - -# Compile for the C++17 standard. -pw_cc_toolchain_feature( - name = "c++17", - cxxopts = ["-std=c++17"], - linkopts = ["-std=c++17"], -) - -# Issue a warning when a class appears to be polymorphic, yet it declares a -# non-virtual destructor -pw_cc_toolchain_feature( - name = "wnon_virtual_dtor", - cxxopts = ["-Wnon-virtual-dtor"], -) - -# Standard compiler flags to reduce output binary size. -pw_cc_toolchain_feature( - name = "reduced_size", - copts = [ - "-fno-common", - "-fno-exceptions", - "-ffunction-sections", - "-fdata-sections", - ], -) - -pw_cc_toolchain_feature( - name = "debugging", - copts = ["-g"], -) diff --git a/pw_toolchain_bazel/features/macos/BUILD.bazel b/pw_toolchain_bazel/features/macos/BUILD.bazel index dc28cfad6f..8b13f55e37 100644 --- a/pw_toolchain_bazel/features/macos/BUILD.bazel +++ b/pw_toolchain_bazel/features/macos/BUILD.bazel @@ -12,17 +12,6 @@ # License for the specific language governing permissions and limitations under # the License. -load("//features/macos/private:xcode_command_line_tools.bzl", "pw_macos_sysroot") - package(default_visibility = ["//visibility:public"]) licenses(["notice"]) - -# Provides the `--sysroot` flag for macOS using Xcode command line tools. -pw_macos_sysroot( - name = "macos_sysroot", - # This repository is generated by xcode_command_line_tools_repository() - # in the build's WORKSPACE file. - sdk = "@pw_xcode_command_line_tools//:default", - target_compatible_with = ["@platforms//os:macos"], -) diff --git a/pw_toolchain_bazel/features/macos/private/xcode_command_line_tools.bzl b/pw_toolchain_bazel/features/macos/private/xcode_command_line_tools.bzl index bbfa65c8f0..a565bfd244 100644 --- a/pw_toolchain_bazel/features/macos/private/xcode_command_line_tools.bzl +++ b/pw_toolchain_bazel/features/macos/private/xcode_command_line_tools.bzl @@ -17,16 +17,6 @@ This replaces xcode_configure, but only intends to work with macOS host builds, and exclusively attempts to support xcode command-line tools. """ -load("//cc_toolchain/private:providers.bzl", "ToolchainFeatureInfo") # buildifier: disable=bzl-visibility -load("//cc_toolchain/private:toolchain_feature.bzl", "build_toolchain_feature_info") # buildifier: disable=bzl-visibility - -XcodeSdkInfo = provider( - doc = "A simple provider that provides the path to the macOS Xcode SDK", - fields = { - "sdk_path": "str: Path to the macOS sdk", - }, -) - def _pw_xcode_repository_impl(repository_ctx): """Generated repository containing a pw_xcode_info target. @@ -37,19 +27,18 @@ def _pw_xcode_repository_impl(repository_ctx): None """ - # This is required to make a repository, so make a stub for all other - # operating systems. - if repository_ctx.os.name != "mac os x": - build_file_contents = [ - "package(default_visibility = [\"//visibility:public\"])", - "", - "filegroup(", - " name = \"default\",", - " visibility = [\"@pw_toolchain//features/macos:__pkg__\"],", - ")", - ] - repository_ctx.file("BUILD", "\n".join(build_file_contents)) + build_file_contents = [ + "package(default_visibility = [\"//visibility:public\"])", + "", + "filegroup(", + " name = \"default\",", + " visibility = [\"//visibility:private\"],", + ")", + ] + repository_ctx.file("BUILD", "\n".join(build_file_contents)) + # Generate a stub and early return if not on macOS. + if repository_ctx.os.name != "mac os x": # Generate the constant, but make it empty. defs_file_contents = [ "XCODE_SDK_PATH = \"\"", @@ -62,73 +51,13 @@ def _pw_xcode_repository_impl(repository_ctx): fail("Failed locating Xcode SDK: {}".format(xcrun_result.stderr)) sdk_path = xcrun_result.stdout.replace("\n", "") - - # DEPRECATED: Generate pw_xcode_info for backwards compatibility. - build_file_contents = [ - "load(\"@pw_toolchain//features/macos/private:xcode_command_line_tools.bzl\", \"pw_xcode_info\")", - "", - "package(default_visibility = [\"//visibility:public\"])", - "", - "pw_xcode_info(", - " name = \"default\",", - " sdk_path = \"{}\",".format(sdk_path), - " visibility = [\"@pw_toolchain//features/macos:__pkg__\"],", - ")", + defs_file_contents = [ + "XCODE_SDK_PATH = \"{}\"".format(sdk_path), ] - - if xcrun_result.return_code == 0: - repository_ctx.file("BUILD", "\n".join(build_file_contents)) - - defs_file_contents = [ - "XCODE_SDK_PATH = \"{}\"".format(sdk_path), - ] - repository_ctx.file("defs.bzl", "\n".join(defs_file_contents)) + repository_ctx.file("defs.bzl", "\n".join(defs_file_contents)) pw_xcode_repository = repository_rule( _pw_xcode_repository_impl, attrs = {}, doc = "Initializes a macOS SDK repository", ) - -def _xcode_info_impl(ctx): - """Rule that provides XcodeSdkInfo. - - Args: - ctx: The context of the current build rule. - - Returns: - XcodeSdkInfo - """ - return [XcodeSdkInfo(sdk_path = ctx.attr.sdk_path)] - -pw_xcode_info = rule( - implementation = _xcode_info_impl, - attrs = { - "sdk_path": attr.string(), - }, - provides = [XcodeSdkInfo], -) - -def _pw_macos_sysroot_impl(ctx): - """Rule that provides an Xcode-provided sysroot as ToolchainFeatureInfo. - - Args: - ctx: The context of the current build rule. - - Returns: - ToolchainFeatureInfo - """ - sdk_path = ctx.attr.sdk[XcodeSdkInfo].sdk_path - return build_toolchain_feature_info( - ctx = ctx, - cxx_builtin_include_directories = ["%sysroot%/usr/include"], - builtin_sysroot = sdk_path, - ) - -pw_macos_sysroot = rule( - implementation = _pw_macos_sysroot_impl, - attrs = { - "sdk": attr.label(), - }, - provides = [ToolchainFeatureInfo], -)