Skip to content

Commit

Permalink
Remove Bitcode support (#1043)
Browse files Browse the repository at this point in the history
Now that Xcode 14.1 is the minimum supported to the App Store, and Xcode
14.0 dropped support for bitcode, we don't need to handle these flags
anymore.

This keeps support for emitting LLVM Bitcode (confusing naming) for use
with LTO. This changes the relevant tests to test that behavior instead.

(cherry picked from commit 797660a)

Co-authored-by: Tony Allevato <allevato@google.com>
  • Loading branch information
keith and allevato authored May 5, 2023
1 parent 3fa1b7a commit 9215fe5
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 103 deletions.
16 changes: 2 additions & 14 deletions swift/internal/compiling.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ load(":explicit_module_map_file.bzl", "write_explicit_swift_module_map_file")
load(":derived_files.bzl", "derived_files")
load(
":feature_names.bzl",
"SWIFT_FEATURE_BITCODE_EMBEDDED",
"SWIFT_FEATURE_CACHEABLE_SWIFTMODULES",
"SWIFT_FEATURE_CODEVIEW_DEBUG_INFO",
"SWIFT_FEATURE_COVERAGE",
Expand Down Expand Up @@ -2665,12 +2664,6 @@ def _declare_compile_outputs(
feature_name = SWIFT_FEATURE_EMIT_BC,
)

# If enabled the compiler will embed LLVM BC in the object files.
embeds_bc = is_feature_enabled(
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE_BITCODE_EMBEDDED,
)

if not output_nature.emits_multiple_objects:
# If we're emitting a single object, we don't use an object map; we just
# declare the output file that the compiler will generate and there are
Expand All @@ -2697,7 +2690,6 @@ def _declare_compile_outputs(
# object files so that we can pass them all to the archive action.
output_info = _declare_multiple_outputs_and_write_output_file_map(
actions = actions,
embeds_bc = embeds_bc,
emits_bc = emits_bc,
split_derived_file_generation = split_derived_file_generation,
srcs = srcs,
Expand Down Expand Up @@ -2757,7 +2749,6 @@ def _declare_compile_outputs(

def _declare_multiple_outputs_and_write_output_file_map(
actions,
embeds_bc,
emits_bc,
split_derived_file_generation,
srcs,
Expand All @@ -2766,8 +2757,6 @@ def _declare_multiple_outputs_and_write_output_file_map(
Args:
actions: The object used to register actions.
embeds_bc: If `True` the compiler will embed LLVM BC in the object
files.
emits_bc: If `True` the compiler will generate LLVM BC files instead of
object files.
split_derived_file_generation: Whether objects and modules are produced
Expand Down Expand Up @@ -2824,7 +2813,7 @@ def _declare_multiple_outputs_and_write_output_file_map(
for src in srcs:
src_output_map = {}

if embeds_bc or emits_bc:
if emits_bc:
# Declare the llvm bc file (there is one per source file).
obj = derived_files.intermediate_bc_file(
actions = actions,
Expand All @@ -2833,8 +2822,7 @@ def _declare_multiple_outputs_and_write_output_file_map(
)
(output_objs if emits_bc else other_outputs).append(obj)
src_output_map["llvm-bc"] = obj.path

if not emits_bc:
else:
# Declare the object file (there is one per source file).
obj = derived_files.intermediate_object_file(
actions = actions,
Expand Down
6 changes: 0 additions & 6 deletions swift/internal/feature_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ SWIFT_FEATURE_DBG = "swift.dbg"
SWIFT_FEATURE_FASTBUILD = "swift.fastbuild"
SWIFT_FEATURE_OPT = "swift.opt"

# These features correspond to the current Bitcode mode as specified by the
# `apple` configuration fragment when targeting Apple platforms. At most one of
# these will be enabled by the toolchain.
SWIFT_FEATURE_BITCODE_EMBEDDED = "swift.bitcode_embedded"
SWIFT_FEATURE_BITCODE_EMBEDDED_MARKERS = "swift.bitcode_embedded_markers"

# This feature is enabled if coverage collection is enabled for the build. (See
# the note above about not depending on the C++ features.)
SWIFT_FEATURE_COVERAGE = "swift.coverage"
Expand Down
48 changes: 0 additions & 48 deletions swift/internal/xcode_swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ load(":attrs.bzl", "swift_toolchain_driver_attrs")
load(":compiling.bzl", "compile_action_configs", "features_from_swiftcopts")
load(
":feature_names.bzl",
"SWIFT_FEATURE_BITCODE_EMBEDDED",
"SWIFT_FEATURE_BITCODE_EMBEDDED_MARKERS",
"SWIFT_FEATURE_BUNDLED_XCTESTS",
"SWIFT_FEATURE_CACHEABLE_SWIFTMODULES",
"SWIFT_FEATURE_COVERAGE",
Expand Down Expand Up @@ -246,29 +244,6 @@ def _swift_linkopts_providers(
objc_info = apple_common.new_objc_provider(linkopt = depset(linkopts)),
)

def _features_for_bitcode_mode(bitcode_mode):
"""Gets the list of features to enable for the selected Bitcode mode.
Args:
bitcode_mode: The `bitcode_mode` value from the C++ configuration
fragment.
Returns:
A list containing the features to enable.
"""
bitcode_mode_string = str(bitcode_mode)
if bitcode_mode_string == "embedded":
return [SWIFT_FEATURE_BITCODE_EMBEDDED]
elif bitcode_mode_string == "embedded_markers":
return [SWIFT_FEATURE_BITCODE_EMBEDDED_MARKERS]
elif bitcode_mode_string == "none":
return []

fail("Internal error: expected bitcode_mode to be one of: " +
"['embedded', 'embedded_markers', 'none'], but got '{}'".format(
bitcode_mode_string,
))

def _resource_directory_configurator(developer_dir, _prerequisites, args):
"""Configures compiler flags about the toolchain's resource directory.
Expand Down Expand Up @@ -344,26 +319,6 @@ def _all_action_configs(
]

action_configs.extend([
# Bitcode-related flags.
swift_toolchain_config.action_config(
actions = [
swift_action_names.COMPILE,
swift_action_names.PRECOMPILE_C_MODULE,
],
configurators = [swift_toolchain_config.add_arg("-embed-bitcode")],
features = [SWIFT_FEATURE_BITCODE_EMBEDDED],
),
swift_toolchain_config.action_config(
actions = [
swift_action_names.COMPILE,
swift_action_names.PRECOMPILE_C_MODULE,
],
configurators = [
swift_toolchain_config.add_arg("-embed-bitcode-marker"),
],
features = [SWIFT_FEATURE_BITCODE_EMBEDDED_MARKERS],
),

# Xcode path remapping
swift_toolchain_config.action_config(
actions = [
Expand Down Expand Up @@ -604,9 +559,6 @@ def _xcode_swift_toolchain_impl(ctx):
cpp_fragment = cpp_fragment,
) + features_from_swiftcopts(swiftcopts = ctx.fragments.swift.copts())
requested_features.extend(ctx.features)
requested_features.extend(
_features_for_bitcode_mode(cpp_fragment.apple_bitcode_mode),
)
requested_features.extend([
SWIFT_FEATURE_BUNDLED_XCTESTS,
SWIFT_FEATURE_CACHEABLE_SWIFTMODULES,
Expand Down
6 changes: 2 additions & 4 deletions test/output_file_map_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ load(
output_file_map_embed_bitcode_test = make_output_file_map_test_rule(
config_settings = {
"//command_line_option:features": [
"swift.bitcode_embedded",
"swift.emit_bc",
],
},
)
Expand All @@ -34,7 +34,7 @@ output_file_map_embed_bitcode_wmo_test = make_output_file_map_test_rule(
"-whole-module-optimization",
],
"//command_line_option:features": [
"swift.bitcode_embedded",
"swift.emit_bc",
],
},
)
Expand Down Expand Up @@ -63,7 +63,6 @@ def output_file_map_test_suite(name):
name = "{}_embed_bitcode".format(name),
expected_mapping = {
"llvm-bc": "test/fixtures/debug_settings/simple_objs/Empty.swift.bc",
"object": "test/fixtures/debug_settings/simple_objs/Empty.swift.o",
},
file_entry = "test/fixtures/debug_settings/Empty.swift",
output_file_map = "test/fixtures/debug_settings/simple.output_file_map.json",
Expand All @@ -75,7 +74,6 @@ def output_file_map_test_suite(name):
name = "{}_embed_bitcode_wmo".format(name),
expected_mapping = {
"llvm-bc": "test/fixtures/debug_settings/simple_objs/Empty.swift.bc",
"object": "test/fixtures/debug_settings/simple_objs/Empty.swift.o",
},
file_entry = "test/fixtures/debug_settings/Empty.swift",
output_file_map = "test/fixtures/debug_settings/simple.output_file_map.json",
Expand Down
34 changes: 3 additions & 31 deletions test/split_derived_files_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,9 @@ split_swiftmodule_indexing_test = make_action_command_line_test_rule(
)
split_swiftmodule_bitcode_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:apple_bitcode": "embedded",
"//command_line_option:features": [
"swift.split_derived_files_generation",
],
},
)
split_swiftmodule_bitcode_markers_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:apple_bitcode": "embedded_markers",
"//command_line_option:features": [
"swift.split_derived_files_generation",
"swift.emit_bc",
],
},
)
Expand Down Expand Up @@ -385,8 +377,7 @@ def split_derived_files_test_suite(name):

split_swiftmodule_bitcode_test(
name = "{}_bitcode_compile".format(name),
expected_argv = ["-embed-bitcode"],
target_compatible_with = ["@platforms//os:macos"],
expected_argv = ["-emit-bc"],
mnemonic = "SwiftCompile",
tags = [name],
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
Expand All @@ -395,26 +386,7 @@ def split_derived_files_test_suite(name):
split_swiftmodule_bitcode_test(
name = "{}_bitcode_derive_files".format(name),
not_expected_argv = [
"-embed-bitcode",
],
mnemonic = "SwiftDeriveFiles",
tags = [name],
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
)

split_swiftmodule_bitcode_markers_test(
name = "{}_bitcode_markers_compile".format(name),
expected_argv = ["-embed-bitcode-marker"],
target_compatible_with = ["@platforms//os:macos"],
mnemonic = "SwiftCompile",
tags = [name],
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
)

split_swiftmodule_bitcode_markers_test(
name = "{}_bitcode_markers_derive_files".format(name),
not_expected_argv = [
"-embed-bitcode-marker",
"-emit-bc",
],
mnemonic = "SwiftDeriveFiles",
tags = [name],
Expand Down

0 comments on commit 9215fe5

Please sign in to comment.