Skip to content

Commit 917000a

Browse files
committed
Switch to use --@bazel_build_rules_swift//swift:static_stdlib to control the flags.
1 parent fe51145 commit 917000a

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

swift/BUILD

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2-
load("@bazel_skylib//rules:common_settings.bzl", "bool_setting")
2+
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "bool_setting")
33
load(
44
"//swift/internal:build_settings.bzl",
55
"per_module_swiftcopt_flag",
@@ -60,6 +60,12 @@ per_module_swiftcopt_flag(
6060
visibility = ["//visibility:public"],
6161
)
6262

63+
# Configuration flag for statically linking stdlib.
64+
bool_flag(
65+
name = "static_stdlib",
66+
build_setting_default = False,
67+
)
68+
6369
# Configuration setting for enabling the generation of swiftinterface files.
6470
bool_setting(
6571
name = "emit_swiftinterface",

swift/internal/attrs.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ def swift_compilation_attrs(
9090
swift_common_rule_attrs(
9191
additional_deps_aspects = additional_deps_aspects,
9292
),
93+
{
94+
"_static_stdlib": attr.label(
95+
default = "@build_bazel_rules_swift//swift:static_stdlib",
96+
),
97+
},
9398
swift_toolchain_attrs(),
9499
{
95100
"srcs": attr.label_list(
@@ -366,6 +371,9 @@ that it is invoked in the correct mode (i.e., `swift`, `swiftc`,
366371
`swift-autolink-extract`, etc.).
367372
""",
368373
),
374+
"_static_stdlib": attr.label(
375+
default = "@build_bazel_rules_swift//swift:static_stdlib",
376+
),
369377
"_default_swift_executable": attr.label(
370378
allow_files = True,
371379
cfg = "exec",

swift/internal/compiling.bzl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ load(
6262
"SWIFT_FEATURE_USE_GLOBAL_MODULE_CACHE",
6363
"SWIFT_FEATURE_USE_PCH_OUTPUT_DIR",
6464
"SWIFT_FEATURE_VFSOVERLAY",
65-
"SWIFT_FEATURE_STATIC_STDLIB",
6665
"SWIFT_FEATURE__NUM_THREADS_0_IN_SWIFTCOPTS",
6766
"SWIFT_FEATURE__WMO_IN_SWIFTCOPTS",
6867
)
@@ -911,16 +910,6 @@ def compile_action_configs(
911910
],
912911
configurators = [_static_frameworks_disable_autolink_configurator],
913912
),
914-
915-
# Enable the built modules to reference static Swift standard libraries.
916-
swift_toolchain_config.action_config(
917-
actions = [
918-
swift_action_names.COMPILE,
919-
swift_action_names.DERIVE_FILES,
920-
],
921-
configurators = [swift_toolchain_config.add_arg("-static-stdlib")],
922-
features = [SWIFT_FEATURE_STATIC_STDLIB],
923-
),
924913
]
925914

926915
# NOTE: The positions of these action configs in the list are important,

swift/internal/feature_names.bzl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,6 @@ SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES = "swift.skip_function_bodies_for_deri
261261
# swift.coverage_prefix_map also remap the path in coverage data.
262262
SWIFT_FEATURE_REMAP_XCODE_PATH = "swift.remap_xcode_path"
263263

264-
# If enabled the built binary will statically link Swift standard libraries.
265-
# This requires Swift 5.3.1
266-
SWIFT_FEATURE_STATIC_STDLIB = "swift.static_stdlib"
267-
268264
# A private feature that is set by the toolchain if a flag enabling WMO was
269265
# passed on the command line using `--swiftcopt`. Users should never manually
270266
# enable, disable, or query this feature.

swift/internal/swift_library.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ def _swift_library_impl(ctx):
121121
extra_features.append(SWIFT_FEATURE_ENABLE_LIBRARY_EVOLUTION)
122122
extra_features.append(SWIFT_FEATURE_EMIT_SWIFTINTERFACE)
123123

124+
if ctx.attr._static_stdlib[BuildSettingInfo].value:
125+
copts.append("-static-stdlib")
126+
124127
module_name = ctx.attr.module_name
125128
if not module_name:
126129
module_name = swift_common.derive_module_name(ctx.label)

swift/internal/swift_toolchain.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ toolchain, see `swift.bzl`.
2020
"""
2121

2222
load("@bazel_skylib//lib:dicts.bzl", "dicts")
23+
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
2324
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
2425
load(":actions.bzl", "swift_action_names")
2526
load(":attrs.bzl", "swift_toolchain_driver_attrs")
@@ -31,7 +32,6 @@ load(
3132
"SWIFT_FEATURE_MODULE_MAP_HOME_IS_CWD",
3233
"SWIFT_FEATURE_NO_GENERATED_MODULE_MAP",
3334
"SWIFT_FEATURE_USE_RESPONSE_FILES",
34-
"SWIFT_FEATURE_STATIC_STDLIB",
3535
)
3636
load(":features.bzl", "features_for_build_modes")
3737
load(":providers.bzl", "SwiftFeatureAllowlistInfo", "SwiftToolchainInfo")
@@ -192,14 +192,15 @@ def _swift_linkopts_cc_info(
192192
def _swift_toolchain_impl(ctx):
193193
toolchain_root = ctx.attr.root
194194
cc_toolchain = find_cpp_toolchain(ctx)
195+
static_stdlib = ctx.attr._static_stdlib[BuildSettingInfo].value
195196

196197
swift_linkopts_cc_info = _swift_linkopts_cc_info(
197198
cc_toolchain,
198199
ctx.attr.arch,
199200
ctx.attr.os,
200201
ctx.label,
201202
toolchain_root,
202-
SWIFT_FEATURE_STATIC_STDLIB in ctx.features,
203+
static_stdlib,
203204
)
204205

205206
# Combine build mode features, autoconfigured features, and required

0 commit comments

Comments
 (0)