From c2099d619b263333b893755da88228edf5b268d5 Mon Sep 17 00:00:00 2001 From: Tony Allevato Date: Tue, 13 Sep 2022 15:28:24 -0700 Subject: [PATCH] Remove some no-longer-relevant "supports X" features. All versions of Xcode/Swift that we care about now support the `-fsystem-module` flag, library evolution, and `@_implementationOnly import`. PiperOrigin-RevId: 474139874 --- swift/internal/compiling.bzl | 8 ++--- swift/internal/feature_names.bzl | 17 ----------- swift/swift_library.bzl | 26 ++--------------- swift/toolchains/config/compile_config.bzl | 34 ++-------------------- swift/toolchains/xcode_swift_toolchain.bzl | 9 ------ 5 files changed, 8 insertions(+), 86 deletions(-) diff --git a/swift/internal/compiling.bzl b/swift/internal/compiling.bzl index 673cb5d07..bd85433a7 100644 --- a/swift/internal/compiling.bzl +++ b/swift/internal/compiling.bzl @@ -35,7 +35,6 @@ load( "SWIFT_FEATURE_NO_GENERATED_MODULE_MAP", "SWIFT_FEATURE_OPT", "SWIFT_FEATURE_OPT_USES_WMO", - "SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION", "SWIFT_FEATURE_SYSTEM_MODULE", "SWIFT_FEATURE_USE_EXPLICIT_SWIFT_MODULE_MAP", "SWIFT_FEATURE__NUM_THREADS_1_IN_SWIFTCOPTS", @@ -835,12 +834,9 @@ def _declare_compile_outputs( "{}.swiftsourceinfo".format(module_name), ) - if are_all_features_enabled( + if is_feature_enabled( feature_configuration = feature_configuration, - feature_names = [ - SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION, - SWIFT_FEATURE_EMIT_SWIFTINTERFACE, - ], + feature_name = SWIFT_FEATURE_EMIT_SWIFTINTERFACE, ): swiftinterface_file = actions.declare_file( "{}.swiftinterface".format(module_name), diff --git a/swift/internal/feature_names.bzl b/swift/internal/feature_names.bzl index 3565a1dc5..90bec0b9f 100644 --- a/swift/internal/feature_names.bzl +++ b/swift/internal/feature_names.bzl @@ -78,14 +78,6 @@ SWIFT_FEATURE_LAYERING_CHECK_SWIFT = "swift.layering_check_swift" # If enabled, the C or Objective-C target should be compiled as a system module. SWIFT_FEATURE_SYSTEM_MODULE = "swift.system_module" -# If enabled, the `-Xcc -fsystem-module` flag will be passed when compiling a -# system C/Objective-C module (with feature `swift.system_module`) because the -# compiler is new enough to honor it correctly. If disabled, we attempt to mimic -# this by disabling certain warnings; however, this unfortunately causes `UInt` -# APIs to be imported by ClangImporter as `UInt` instead of `Int` because -# ClangImporter doesn't recognize them as true system modules. -SWIFT_FEATURE_SUPPORTS_SYSTEM_MODULE_FLAG = "swift.supports_system_module_flag" - # If enabled, Swift compilation actions will use batch mode by passing # `-enable-batch-mode` to `swiftc`. This is a new compilation mode as of # Swift 4.2 that is intended to speed up non-incremental non-WMO builds by @@ -176,10 +168,6 @@ SWIFT_FEATURE_USE_RESPONSE_FILES = "swift.use_response_files" # target.swift-extra-clang-flags SWIFT_FEATURE_CACHEABLE_SWIFTMODULES = "swift.cacheable_swiftmodules" -# If enabled, enables features that require the library evolution compilation -# mode. If disabled, features that require library evolution mode are noops. -SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION = "swift.supports_library_evolution" - # If enabled, requests the `-enable-library-evolution` swiftc flag which is # required for newer features like swiftinterface file generation. If the # `SWIFT_FEATURES_SUPPORTS_LIBRARY_EVOLUTION` feature is not enabled, this @@ -191,11 +179,6 @@ SWIFT_FEATURE_ENABLE_LIBRARY_EVOLUTION = "swift.enable_library_evolution" # enabled, this feature is a noop. SWIFT_FEATURE_EMIT_SWIFTINTERFACE = "swift.emit_swiftinterface" -# If enabled, the toolchain supports private deps (implementation-only imports). -# This allows Bazel to avoid propagating swiftmodules of such dependencies -# higher in the dependency graph than they need to be. -SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS = "swift.supports_private_deps" - # If enabled, the .swiftmodule file for the affected target will not be # embedded in debug info and propagated to the linker. # diff --git a/swift/swift_library.bzl b/swift/swift_library.bzl index 901902122..38e03149c 100644 --- a/swift/swift_library.bzl +++ b/swift/swift_library.bzl @@ -31,7 +31,6 @@ load( "@build_bazel_rules_swift//swift/internal:feature_names.bzl", "SWIFT_FEATURE_EMIT_SWIFTINTERFACE", "SWIFT_FEATURE_ENABLE_LIBRARY_EVOLUTION", - "SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS", ) load( "@build_bazel_rules_swift//swift/internal:linking.bzl", @@ -140,28 +139,9 @@ def _swift_library_impl(ctx): unsupported_features = ctx.disabled_features, ) - if swift_common.is_enabled( - feature_configuration = feature_configuration, - feature_name = SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS, - ): - # The implicit deps can be added to the private deps; since they are - # added to the compilation of every library, they don't need to be - # propagated. However, it's not an error to list one of the implicit - # deps in "deps", either, so we need to make sure not to pass them in to - # `_check_deps_are_disjoint`. - deps = ctx.attr.deps - private_deps = ctx.attr.private_deps - _check_deps_are_disjoint(ctx.label, deps, private_deps) - elif ctx.attr.private_deps: - fail( - ("In target '{}', 'private_deps' cannot be used because this " + - "version of the Swift toolchain does not support " + - "implementation-only imports.").format(ctx.label), - attr = "private_deps", - ) - else: - deps = ctx.attr.deps - private_deps = [] + deps = ctx.attr.deps + private_deps = ctx.attr.private_deps + _check_deps_are_disjoint(ctx.label, deps, private_deps) swift_infos = get_providers(deps, SwiftInfo) private_swift_infos = get_providers(private_deps, SwiftInfo) diff --git a/swift/toolchains/config/compile_config.bzl b/swift/toolchains/config/compile_config.bzl index 88f4723d0..27cb7f8a5 100644 --- a/swift/toolchains/config/compile_config.bzl +++ b/swift/toolchains/config/compile_config.bzl @@ -45,8 +45,6 @@ load( "SWIFT_FEATURE_OPT_USES_OSIZE", "SWIFT_FEATURE_OPT_USES_WMO", "SWIFT_FEATURE_REWRITE_GENERATED_HEADER", - "SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION", - "SWIFT_FEATURE_SUPPORTS_SYSTEM_MODULE_FLAG", "SWIFT_FEATURE_SYSTEM_MODULE", "SWIFT_FEATURE_USE_C_MODULES", "SWIFT_FEATURE_USE_EXPLICIT_SWIFT_MODULE_MAP", @@ -162,18 +160,12 @@ def compile_action_configs( SWIFT_ACTION_COMPILE, ], configurators = [add_arg("-enable-library-evolution")], - features = [ - SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION, - SWIFT_FEATURE_ENABLE_LIBRARY_EVOLUTION, - ], + features = [SWIFT_FEATURE_ENABLE_LIBRARY_EVOLUTION], ), ActionConfigInfo( actions = [SWIFT_ACTION_COMPILE], configurators = [_emit_module_interface_path_configurator], - features = [ - SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION, - SWIFT_FEATURE_EMIT_SWIFTINTERFACE, - ], + features = [SWIFT_FEATURE_EMIT_SWIFTINTERFACE], ), ActionConfigInfo( actions = [SWIFT_ACTION_COMPILE], @@ -456,23 +448,6 @@ def compile_action_configs( features = [SWIFT_FEATURE_LAYERING_CHECK], not_features = [SWIFT_FEATURE_SYSTEM_MODULE], ), - ActionConfigInfo( - actions = [SWIFT_ACTION_PRECOMPILE_C_MODULE], - configurators = [ - # Before Swift 5.4, ClangImporter doesn't currently handle the - # IsSystem bit correctly for the input file and ignores the - # `-fsystem-module` flag, which causes the module map to be - # treated as a user input. We can work around this by disabling - # diagnostics for system modules. However, this also disables - # behavior in ClangImporter that causes system APIs that use - # `UInt` to be imported to use `Int` instead. The only solution - # here is to use Xcode 12.5 or higher. - add_arg("-Xcc", "-w"), - add_arg("-Xcc", "-Wno-nullability-declspec"), - ], - features = [SWIFT_FEATURE_SYSTEM_MODULE], - not_features = [SWIFT_FEATURE_SUPPORTS_SYSTEM_MODULE_FLAG], - ), ActionConfigInfo( actions = [SWIFT_ACTION_PRECOMPILE_C_MODULE], configurators = [ @@ -492,10 +467,7 @@ def compile_action_configs( add_arg("-Xcc", "-Xclang"), add_arg("-Xcc", "-fsystem-module"), ], - features = [ - SWIFT_FEATURE_SUPPORTS_SYSTEM_MODULE_FLAG, - SWIFT_FEATURE_SYSTEM_MODULE, - ], + features = [SWIFT_FEATURE_SYSTEM_MODULE], ), ] diff --git a/swift/toolchains/xcode_swift_toolchain.bzl b/swift/toolchains/xcode_swift_toolchain.bzl index ab62e60e6..b89af5a8f 100644 --- a/swift/toolchains/xcode_swift_toolchain.bzl +++ b/swift/toolchains/xcode_swift_toolchain.bzl @@ -44,9 +44,6 @@ load( "SWIFT_FEATURE_DEBUG_PREFIX_MAP", "SWIFT_FEATURE_ENABLE_BATCH_MODE", "SWIFT_FEATURE_MODULE_MAP_HOME_IS_CWD", - "SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION", - "SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS", - "SWIFT_FEATURE_SUPPORTS_SYSTEM_MODULE_FLAG", "SWIFT_FEATURE_USE_RESPONSE_FILES", ) load( @@ -731,14 +728,8 @@ def _xcode_swift_toolchain_impl(ctx): SWIFT_FEATURE_ENABLE_BATCH_MODE, SWIFT_FEATURE_USE_RESPONSE_FILES, SWIFT_FEATURE_DEBUG_PREFIX_MAP, - SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION, - SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS, ]) - # Xcode 12.5 implies Swift 5.4. - if _is_xcode_at_least_version(xcode_config, "12.5"): - requested_features.append(SWIFT_FEATURE_SUPPORTS_SYSTEM_MODULE_FLAG) - env = _xcode_env(target_triple = target_triple, xcode_config = xcode_config) execution_requirements = xcode_config.execution_info() generated_header_rewriter = resolve_optional_tool(