Skip to content

Un-conditionalize logic for features that require Xcode 15.0 or higher (dropping support for Xcode 14) #1311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions swift/internal/compiling.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ load(
"SWIFT_FEATURE_USE_EXPLICIT_SWIFT_MODULE_MAP",
"SWIFT_FEATURE_VFSOVERLAY",
"SWIFT_FEATURE__NUM_THREADS_0_IN_SWIFTCOPTS",
"SWIFT_FEATURE__SUPPORTS_CONST_VALUE_EXTRACTION",
"SWIFT_FEATURE__SUPPORTS_MACROS",
"SWIFT_FEATURE__WMO_IN_SWIFTCOPTS",
)
load(
Expand Down Expand Up @@ -493,13 +491,7 @@ def compile(
feature_name = SWIFT_FEATURE_EMIT_SWIFTSOURCEINFO,
)

if is_feature_enabled(
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE__SUPPORTS_CONST_VALUE_EXTRACTION,
):
const_protocols_to_gather_file = swift_toolchain.const_protocols_to_gather
else:
const_protocols_to_gather_file = []
const_protocols_to_gather_file = swift_toolchain.const_protocols_to_gather

compile_outputs, other_outputs = _declare_compile_outputs(
srcs = srcs,
Expand Down Expand Up @@ -1313,10 +1305,7 @@ def _declare_compile_outputs(
else:
indexstore_directory = None

if is_feature_enabled(
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE__SUPPORTS_MACROS,
) and not is_feature_enabled(
if not is_feature_enabled(
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE_OPT,
):
Expand Down
10 changes: 0 additions & 10 deletions swift/internal/feature_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,6 @@ SWIFT_FEATURE_OBJC_LINK_FLAGS = "swift.objc_link_flag"
# all Swift compilations to always be linked.
SWIFT_FEATURE__FORCE_ALWAYSLINK_TRUE = "swift._force_alwayslink_true"

# A private feature that is set by the toolchain if it supports macros (Swift
# 5.9 and above). Users should never manually enable, disable, or query this
# feature.
SWIFT_FEATURE__SUPPORTS_MACROS = "swift._supports_macros"

# Disables Swift sandbox which prevents issues with nested sandboxing when Swift code contains system-provided macros.
# If enabled '#Preview' macro provided by SwiftUI fails to build and probably other system-provided macros.
# Enabled by default for Swift 5.10+ on macOS.
Expand All @@ -341,11 +336,6 @@ SWIFT_FEATURE_EMIT_SWIFTSOURCEINFO = "swift.emit_swiftsourceinfo"
# multiple frameworks with different target name, but same module name.
SWIFT_FEATURE_ADD_TARGET_NAME_TO_OUTPUT = "swift.add_target_name_to_output"

# A private feature that is set by the toolchain if it supports constant values
# extraction (Swift 5.8 and above). Users should never manually enable, disable, or query this
# feature.
SWIFT_FEATURE__SUPPORTS_CONST_VALUE_EXTRACTION = "swift._supports_const_value_extraction"

# Enable thin LTO and update output-file-map correctly
SWIFT_FEATURE_THIN_LTO = "swift.thin_lto"

Expand Down
29 changes: 0 additions & 29 deletions swift/internal/swift_autoconfiguration.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ load(
"SWIFT_FEATURE_USE_AUTOLINK_EXTRACT",
"SWIFT_FEATURE_USE_MODULE_WRAP",
"SWIFT_FEATURE_USE_OLD_DRIVER",
"SWIFT_FEATURE__SUPPORTS_MACROS",
)

def _scratch_file(repository_ctx, temp_dir, name, content = ""):
Expand Down Expand Up @@ -154,30 +153,6 @@ def _write_swift_version(repository_ctx, swiftc_path):
repository_ctx.file(filename, contents, executable = False)
return filename

def _fetch_supported_features(repository_ctx, swiftc_path):
"""Fetch the json config of supported features from Swift

This can be used to flip rules specific features

Args:
repository_ctx: The repository context.
swiftc_path: The `path` to the `swiftc` executable.

Returns:
The list of supported features, or an empty array if it fails
"""
repository_ctx.file("empty.swift")
result = repository_ctx.execute([
swiftc_path,
"-frontend",
"-emit-supported-features",
"empty.swift",
])
if result.return_code == 0:
return json.decode(result.stdout.strip()).get("SupportedArguments", [])

return []

def _compute_feature_values(repository_ctx, swiftc_path):
"""Computes a list of supported/unsupported features by running checks.

Expand Down Expand Up @@ -259,10 +234,6 @@ def _create_linux_toolchain(repository_ctx):
feature_values.append(SWIFT_FEATURE_USE_AUTOLINK_EXTRACT)
feature_values.append(SWIFT_FEATURE_USE_MODULE_WRAP)

swift_features_config = _fetch_supported_features(repository_ctx, path_to_swiftc)
if "load-plugin-executable" in swift_features_config:
feature_values.append(SWIFT_FEATURE__SUPPORTS_MACROS)

repository_ctx.file(
"BUILD",
"""
Expand Down
7 changes: 0 additions & 7 deletions swift/swift_compiler_plugin.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ load(
load(
"@build_bazel_rules_swift//swift/internal:feature_names.bzl",
"SWIFT_FEATURE_ADD_TARGET_NAME_TO_OUTPUT",
"SWIFT_FEATURE__SUPPORTS_MACROS",
)
load("//swift/internal:features.bzl", "is_feature_enabled")
load(
Expand Down Expand Up @@ -59,12 +58,6 @@ def _swift_compiler_plugin_impl(ctx):
unsupported_features = ctx.disabled_features,
)

if not is_feature_enabled(
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE__SUPPORTS_MACROS,
):
fail("Swift compiler plugins require Swift 5.9+")

deps = ctx.attr.deps
srcs = ctx.files.srcs
module_contexts = []
Expand Down
4 changes: 0 additions & 4 deletions swift/toolchains/config/compile_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ load(
"SWIFT_FEATURE_USE_PCH_OUTPUT_DIR",
"SWIFT_FEATURE_VFSOVERLAY",
"SWIFT_FEATURE__NUM_THREADS_0_IN_SWIFTCOPTS",
"SWIFT_FEATURE__SUPPORTS_CONST_VALUE_EXTRACTION",
"SWIFT_FEATURE__SUPPORTS_MACROS",
"SWIFT_FEATURE__WMO_IN_SWIFTCOPTS",
)
load(":action_config.bzl", "ActionConfigInfo", "ConfigResultInfo", "add_arg")
Expand Down Expand Up @@ -254,7 +252,6 @@ def compile_action_configs(
ActionConfigInfo(
actions = [SWIFT_ACTION_COMPILE],
configurators = [_constant_value_extraction_configurator],
features = [SWIFT_FEATURE__SUPPORTS_CONST_VALUE_EXTRACTION],
),

# Link Time Optimization (LTO).
Expand Down Expand Up @@ -811,7 +808,6 @@ def compile_action_configs(
SWIFT_ACTION_DERIVE_FILES,
],
configurators = [_macro_expansion_configurator],
features = [SWIFT_FEATURE__SUPPORTS_MACROS],
),

# swift-symbolgraph-extract doesn't yet support explicit Swift module
Expand Down
20 changes: 3 additions & 17 deletions swift/toolchains/xcode_swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ load(
"SWIFT_FEATURE_REMAP_XCODE_PATH",
"SWIFT_FEATURE_SUPPORTS_BARE_SLASH_REGEX",
"SWIFT_FEATURE_USE_GLOBAL_MODULE_CACHE",
"SWIFT_FEATURE_USE_OLD_DRIVER",
"SWIFT_FEATURE__FORCE_ALWAYSLINK_TRUE",
"SWIFT_FEATURE__SUPPORTS_CONST_VALUE_EXTRACTION",
"SWIFT_FEATURE__SUPPORTS_MACROS",
)
load("//swift/internal:features.bzl", "features_for_build_modes")
load("//swift/internal:target_triples.bzl", "target_triples")
Expand Down Expand Up @@ -699,34 +696,23 @@ def _xcode_swift_toolchain_impl(ctx):
SWIFT_FEATURE_CACHEABLE_SWIFTMODULES,
SWIFT_FEATURE_COVERAGE_PREFIX_MAP,
SWIFT_FEATURE_DEBUG_PREFIX_MAP,
SWIFT_FEATURE_DISABLE_SYSTEM_INDEX,
SWIFT_FEATURE_EMIT_SWIFTDOC,
SWIFT_FEATURE_EMIT_SWIFTSOURCEINFO,
SWIFT_FEATURE_ENABLE_BATCH_MODE,
SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES,
SWIFT_FEATURE_DISABLE_SYSTEM_INDEX,
SWIFT_FEATURE_FILE_PREFIX_MAP,
SWIFT_FEATURE_OBJC_LINK_FLAGS,
SWIFT_FEATURE_OPT_USES_WMO,
SWIFT_FEATURE_REMAP_XCODE_PATH,
SWIFT_FEATURE_SUPPORTS_BARE_SLASH_REGEX,
SWIFT_FEATURE_USE_GLOBAL_MODULE_CACHE,
])

# The new driver had response file bugs in Xcode 13.x that are fixed in
# Xcode 14.
if not _is_xcode_at_least_version(xcode_config, "14.0"):
requested_features.append(SWIFT_FEATURE_USE_OLD_DRIVER)

# Xcode 14 implies Swift 5.7.
if _is_xcode_at_least_version(xcode_config, "14.0"):
requested_features.append(SWIFT_FEATURE_FILE_PREFIX_MAP)
requested_features.append(SWIFT_FEATURE_SUPPORTS_BARE_SLASH_REGEX)

if getattr(ctx.fragments.objc, "alwayslink_by_default", False):
requested_features.append(SWIFT_FEATURE__FORCE_ALWAYSLINK_TRUE)

if _is_xcode_at_least_version(xcode_config, "15.0"):
requested_features.append(SWIFT_FEATURE__SUPPORTS_MACROS)
requested_features.append(SWIFT_FEATURE__SUPPORTS_CONST_VALUE_EXTRACTION)

if _is_xcode_at_least_version(xcode_config, "15.3"):
requested_features.append(SWIFT_FEATURE_DISABLE_SWIFT_SANDBOX)

Expand Down
21 changes: 0 additions & 21 deletions test/const_values_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ load(

const_values_test = make_action_command_line_test_rule()

no_const_values_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:features": [
"-swift._supports_const_value_extraction",
],
},
)

const_values_wmo_test = make_provider_test_rule(
config_settings = {
str(Label("@build_bazel_rules_swift//swift:copt")): [
Expand Down Expand Up @@ -98,19 +90,6 @@ def const_values_test_suite(name, tags = []):
target_under_test = "@build_bazel_rules_swift//test/fixtures/basic:first",
)

no_const_values_test(
name = "{}_not_expected_argv".format(name),
not_expected_argv = [
"-Xfrontend -const-gather-protocols-file",
"-Xfrontend swift/toolchains/config/const_protocols_to_gather.json",
"-emit-const-values-path",
"first.swift.swiftconstvalues",
],
mnemonic = "SwiftCompile",
tags = all_tags,
target_under_test = "@build_bazel_rules_swift//test/fixtures/basic:first",
)

native.test_suite(
name = name,
tags = all_tags,
Expand Down