Skip to content

Commit

Permalink
Switch to use --@bazel_build_rules_swift//swift:static_stdlib to cont…
Browse files Browse the repository at this point in the history
…rol the flags.
  • Loading branch information
liuliu committed Nov 6, 2021
1 parent fe51145 commit 917000a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
8 changes: 7 additions & 1 deletion swift/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_skylib//rules:common_settings.bzl", "bool_setting")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "bool_setting")
load(
"//swift/internal:build_settings.bzl",
"per_module_swiftcopt_flag",
Expand Down Expand Up @@ -60,6 +60,12 @@ per_module_swiftcopt_flag(
visibility = ["//visibility:public"],
)

# Configuration flag for statically linking stdlib.
bool_flag(
name = "static_stdlib",
build_setting_default = False,
)

# Configuration setting for enabling the generation of swiftinterface files.
bool_setting(
name = "emit_swiftinterface",
Expand Down
8 changes: 8 additions & 0 deletions swift/internal/attrs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ def swift_compilation_attrs(
swift_common_rule_attrs(
additional_deps_aspects = additional_deps_aspects,
),
{
"_static_stdlib": attr.label(
default = "@build_bazel_rules_swift//swift:static_stdlib",
),
},
swift_toolchain_attrs(),
{
"srcs": attr.label_list(
Expand Down Expand Up @@ -366,6 +371,9 @@ that it is invoked in the correct mode (i.e., `swift`, `swiftc`,
`swift-autolink-extract`, etc.).
""",
),
"_static_stdlib": attr.label(
default = "@build_bazel_rules_swift//swift:static_stdlib",
),
"_default_swift_executable": attr.label(
allow_files = True,
cfg = "exec",
Expand Down
11 changes: 0 additions & 11 deletions swift/internal/compiling.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ load(
"SWIFT_FEATURE_USE_GLOBAL_MODULE_CACHE",
"SWIFT_FEATURE_USE_PCH_OUTPUT_DIR",
"SWIFT_FEATURE_VFSOVERLAY",
"SWIFT_FEATURE_STATIC_STDLIB",
"SWIFT_FEATURE__NUM_THREADS_0_IN_SWIFTCOPTS",
"SWIFT_FEATURE__WMO_IN_SWIFTCOPTS",
)
Expand Down Expand Up @@ -911,16 +910,6 @@ def compile_action_configs(
],
configurators = [_static_frameworks_disable_autolink_configurator],
),

# Enable the built modules to reference static Swift standard libraries.
swift_toolchain_config.action_config(
actions = [
swift_action_names.COMPILE,
swift_action_names.DERIVE_FILES,
],
configurators = [swift_toolchain_config.add_arg("-static-stdlib")],
features = [SWIFT_FEATURE_STATIC_STDLIB],
),
]

# NOTE: The positions of these action configs in the list are important,
Expand Down
4 changes: 0 additions & 4 deletions swift/internal/feature_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,6 @@ SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES = "swift.skip_function_bodies_for_deri
# swift.coverage_prefix_map also remap the path in coverage data.
SWIFT_FEATURE_REMAP_XCODE_PATH = "swift.remap_xcode_path"

# If enabled the built binary will statically link Swift standard libraries.
# This requires Swift 5.3.1
SWIFT_FEATURE_STATIC_STDLIB = "swift.static_stdlib"

# A private feature that is set by the toolchain if a flag enabling WMO was
# passed on the command line using `--swiftcopt`. Users should never manually
# enable, disable, or query this feature.
Expand Down
3 changes: 3 additions & 0 deletions swift/internal/swift_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ def _swift_library_impl(ctx):
extra_features.append(SWIFT_FEATURE_ENABLE_LIBRARY_EVOLUTION)
extra_features.append(SWIFT_FEATURE_EMIT_SWIFTINTERFACE)

if ctx.attr._static_stdlib[BuildSettingInfo].value:
copts.append("-static-stdlib")

module_name = ctx.attr.module_name
if not module_name:
module_name = swift_common.derive_module_name(ctx.label)
Expand Down
5 changes: 3 additions & 2 deletions swift/internal/swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ toolchain, see `swift.bzl`.
"""

load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load(":actions.bzl", "swift_action_names")
load(":attrs.bzl", "swift_toolchain_driver_attrs")
Expand All @@ -31,7 +32,6 @@ load(
"SWIFT_FEATURE_MODULE_MAP_HOME_IS_CWD",
"SWIFT_FEATURE_NO_GENERATED_MODULE_MAP",
"SWIFT_FEATURE_USE_RESPONSE_FILES",
"SWIFT_FEATURE_STATIC_STDLIB",
)
load(":features.bzl", "features_for_build_modes")
load(":providers.bzl", "SwiftFeatureAllowlistInfo", "SwiftToolchainInfo")
Expand Down Expand Up @@ -192,14 +192,15 @@ def _swift_linkopts_cc_info(
def _swift_toolchain_impl(ctx):
toolchain_root = ctx.attr.root
cc_toolchain = find_cpp_toolchain(ctx)
static_stdlib = ctx.attr._static_stdlib[BuildSettingInfo].value

swift_linkopts_cc_info = _swift_linkopts_cc_info(
cc_toolchain,
ctx.attr.arch,
ctx.attr.os,
ctx.label,
toolchain_root,
SWIFT_FEATURE_STATIC_STDLIB in ctx.features,
static_stdlib,
)

# Combine build mode features, autoconfigured features, and required
Expand Down

0 comments on commit 917000a

Please sign in to comment.