Skip to content

Commit

Permalink
Remove some no-longer-relevant "supports X" features.
Browse files Browse the repository at this point in the history
All versions of Xcode/Swift that we care about now support the `-fsystem-module` flag, library evolution, and `@_implementationOnly import`.

PiperOrigin-RevId: 474139874
  • Loading branch information
allevato authored and swiple-rules-gardener committed Sep 13, 2022
1 parent 0a1d9f8 commit c2099d6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 86 deletions.
8 changes: 2 additions & 6 deletions swift/internal/compiling.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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),
Expand Down
17 changes: 0 additions & 17 deletions swift/internal/feature_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
#
Expand Down
26 changes: 3 additions & 23 deletions swift/swift_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
34 changes: 3 additions & 31 deletions swift/toolchains/config/compile_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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 = [
Expand All @@ -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],
),
]

Expand Down
9 changes: 0 additions & 9 deletions swift/toolchains/xcode_swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit c2099d6

Please sign in to comment.