Skip to content
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
4 changes: 4 additions & 0 deletions swift/internal/actions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ swift_action_names = struct(
# Precompiles an explicit module for a C/Objective-C module map and its
# headers, emitting a `.pcm` file.
PRECOMPILE_C_MODULE = "SwiftPrecompileCModule",

# Produces files that are usually fallout of the compilation such as
# .swiftmodule, -Swift.h and more.
DERIVE_FILES = "SwiftDeriveFiles",
)

def _apply_configurator(configurator, prerequisites, args):
Expand Down
284 changes: 234 additions & 50 deletions swift/internal/compiling.bzl

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions swift/internal/feature_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,12 @@ SWIFT_FEATURE_NO_EMBED_DEBUG_MODULE = "swift.no_embed_debug_module"
# files where the protoc command line might not be crafted correctly, so it
# remains opt in.
SWIFT_FEATURE_GENERATE_FROM_RAW_PROTO_FILES = "swift.generate_from_raw_proto_files"

# If enabled and whole module optimisation is being used, the `*.swiftdoc`,
# `*.swiftmodule` and `*-Swift.h` are generated with a separate action
# rather than as part of the compilation.
SWIFT_FEATURE_SPLIT_DERIVED_FILES_GENERATION = "swift.split_derived_files_generation"

# If enabled the skip function bodies frontend flag is passed when using derived
# files generation. This requires Swift 5.2
SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES = "swift.skip_function_bodies_for_derived_files"
11 changes: 11 additions & 0 deletions swift/internal/swift_autoconfiguration.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ load(
"@build_bazel_rules_swift//swift/internal:feature_names.bzl",
"SWIFT_FEATURE_DEBUG_PREFIX_MAP",
"SWIFT_FEATURE_ENABLE_BATCH_MODE",
"SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES",
"SWIFT_FEATURE_IMPLICIT_MODULES",
"SWIFT_FEATURE_MODULE_MAP_NO_PRIVATE_HEADERS",
"SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS",
Expand Down Expand Up @@ -75,6 +76,15 @@ def _check_enable_batch_mode(repository_ctx, swiftc_path, temp_dir):
"-enable-batch-mode",
)

def _check_skip_function_bodies(repository_ctx, swiftc_path, temp_dir):
"""Returns True if `swiftc` supports skip function bodies."""
return _swift_succeeds(
repository_ctx,
swiftc_path,
"-version",
"-experimental-skip-non-inlinable-function-bodies",
)

def _check_debug_prefix_map(repository_ctx, swiftc_path, temp_dir):
"""Returns True if `swiftc` supports debug prefix mapping."""
return _swift_succeeds(
Expand Down Expand Up @@ -187,6 +197,7 @@ def _compute_feature_values(repository_ctx, swiftc_path):
_FEATURE_CHECKS = {
SWIFT_FEATURE_DEBUG_PREFIX_MAP: _check_debug_prefix_map,
SWIFT_FEATURE_ENABLE_BATCH_MODE: _check_enable_batch_mode,
SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES: _check_skip_function_bodies,
SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS: _check_supports_private_deps,
SWIFT_FEATURE_USE_RESPONSE_FILES: _check_use_response_files,
}
Expand Down
19 changes: 11 additions & 8 deletions swift/internal/swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ def _all_tool_configs(
"""
_swift_driver_tool_config = swift_toolchain_config.driver_tool_config

compile_tool_config = _swift_driver_tool_config(
driver_mode = "swiftc",
swift_executable = swift_executable,
toolchain_root = toolchain_root,
use_param_file = use_param_file,
worker_mode = "persistent",
additional_tools = additional_tools,
)

return {
swift_action_names.AUTOLINK_EXTRACT: _swift_driver_tool_config(
driver_mode = "swift-autolink-extract",
Expand All @@ -67,14 +76,8 @@ def _all_tool_configs(
worker_mode = "wrap",
additional_tools = additional_tools,
),
swift_action_names.COMPILE: _swift_driver_tool_config(
driver_mode = "swiftc",
swift_executable = swift_executable,
toolchain_root = toolchain_root,
use_param_file = use_param_file,
worker_mode = "persistent",
additional_tools = additional_tools,
),
swift_action_names.COMPILE: compile_tool_config,
swift_action_names.DERIVE_FILES: compile_tool_config,
swift_action_names.MODULEWRAP: _swift_driver_tool_config(
# This must come first after the driver name.
args = ["-modulewrap"],
Expand Down
30 changes: 21 additions & 9 deletions swift/internal/xcode_swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ load(
"SWIFT_FEATURE_BUNDLED_XCTESTS",
"SWIFT_FEATURE_DEBUG_PREFIX_MAP",
"SWIFT_FEATURE_ENABLE_BATCH_MODE",
"SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES",
"SWIFT_FEATURE_MODULE_MAP_HOME_IS_CWD",
"SWIFT_FEATURE_MODULE_MAP_NO_PRIVATE_HEADERS",
"SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION",
Expand Down Expand Up @@ -287,6 +288,7 @@ def _all_action_configs(
swift_toolchain_config.action_config(
actions = [
swift_action_names.COMPILE,
swift_action_names.DERIVE_FILES,
swift_action_names.PRECOMPILE_C_MODULE,
],
configurators = [
Expand Down Expand Up @@ -317,6 +319,7 @@ def _all_action_configs(
swift_toolchain_config.action_config(
actions = [
swift_action_names.COMPILE,
swift_action_names.DERIVE_FILES,
swift_action_names.PRECOMPILE_C_MODULE,
],
configurators = [swift_toolchain_config.add_arg("-embed-bitcode")],
Expand All @@ -325,6 +328,7 @@ def _all_action_configs(
swift_toolchain_config.action_config(
actions = [
swift_action_names.COMPILE,
swift_action_names.DERIVE_FILES,
swift_action_names.PRECOMPILE_C_MODULE,
],
configurators = [
Expand All @@ -342,6 +346,7 @@ def _all_action_configs(
swift_toolchain_config.action_config(
actions = [
swift_action_names.COMPILE,
swift_action_names.DERIVE_FILES,
swift_action_names.PRECOMPILE_C_MODULE,
],
configurators = [
Expand Down Expand Up @@ -389,16 +394,19 @@ def _all_tool_configs(
env = dict(env)
env["TOOLCHAINS"] = custom_toolchain

tool_config = swift_toolchain_config.driver_tool_config(
driver_mode = "swiftc",
env = env,
execution_requirements = execution_requirements,
swift_executable = swift_executable,
toolchain_root = toolchain_root,
use_param_file = use_param_file,
worker_mode = "persistent",
)

tool_configs = {
swift_action_names.COMPILE: swift_toolchain_config.driver_tool_config(
driver_mode = "swiftc",
env = env,
execution_requirements = execution_requirements,
swift_executable = swift_executable,
toolchain_root = toolchain_root,
use_param_file = use_param_file,
worker_mode = "persistent",
),
swift_action_names.COMPILE: tool_config,
swift_action_names.DERIVE_FILES: tool_config,
}

# Xcode 12.0 implies Swift 5.3.
Expand Down Expand Up @@ -594,6 +602,10 @@ def _xcode_swift_toolchain_impl(ctx):
requested_features.append(SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION)
requested_features.append(SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS)

# Xcode 11.4 implies Swift 5.2.
if _is_xcode_at_least_version(xcode_config, "11.4"):
requested_features.append(SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES)

command_line_copts = _command_line_objc_copts(
ctx.var["COMPILATION_MODE"],
ctx.fragments.objc,
Expand Down
3 changes: 3 additions & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ load(":coverage_settings_tests.bzl", "coverage_settings_test_suite")
load(":generated_header_tests.bzl", "generated_header_test_suite")
load(":private_deps_tests.bzl", "private_deps_test_suite")
load(":swift_through_non_swift_tests.bzl", "swift_through_non_swift_test_suite")
load(":split_derived_files_tests.bzl", "split_derived_files_test_suite")

licenses(["notice"])

Expand All @@ -17,6 +18,8 @@ private_deps_test_suite()

swift_through_non_swift_test_suite()

split_derived_files_test_suite()

test_suite(
name = "all_tests",
)
Expand Down
Loading