Skip to content

Commit 377c9bf

Browse files
authored
Supporting Swift 5.7 Bare Slash Regex Literal (#886)
1 parent 8aca87e commit 377c9bf

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

swift/internal/compiling.bzl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ load(
5757
"SWIFT_FEATURE_OPT_USES_WMO",
5858
"SWIFT_FEATURE_REWRITE_GENERATED_HEADER",
5959
"SWIFT_FEATURE_SPLIT_DERIVED_FILES_GENERATION",
60+
"SWIFT_FEATURE_SUPPORTS_BARE_SLASH_REGEX",
6061
"SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION",
6162
"SWIFT_FEATURE_SUPPORTS_SYSTEM_MODULE_FLAG",
6263
"SWIFT_FEATURE_SYSTEM_MODULE",
@@ -326,6 +327,18 @@ def compile_action_configs(
326327
SWIFT_FEATURE_ENABLE_LIBRARY_EVOLUTION,
327328
],
328329
),
330+
swift_toolchain_config.action_config(
331+
actions = [
332+
swift_action_names.COMPILE,
333+
swift_action_names.DERIVE_FILES,
334+
],
335+
configurators = [
336+
swift_toolchain_config.add_arg("-enable-bare-slash-regex"),
337+
],
338+
features = [
339+
SWIFT_FEATURE_SUPPORTS_BARE_SLASH_REGEX,
340+
],
341+
),
329342
swift_toolchain_config.action_config(
330343
actions = [
331344
swift_action_names.COMPILE,

swift/internal/feature_names.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,8 @@ SWIFT_FEATURE__NUM_THREADS_0_IN_SWIFTCOPTS = "swift._num_threads_0_in_swiftcopts
304304
# A feature to enable setting pch-output-dir
305305
# This is a directory to persist automatically created precompiled bridging headers
306306
SWIFT_FEATURE_USE_PCH_OUTPUT_DIR = "swift.use_pch_output_dir"
307+
308+
# If enabled, Swift compilation actions will pass
309+
# `-enable-bare-slash-regex` to `swiftc`. This is a new flag as of
310+
# Swift 5.7 that enables `/.../` syntax regular-expression literals.
311+
SWIFT_FEATURE_SUPPORTS_BARE_SLASH_REGEX = "swift.supports_bare_slash_regex"

swift/internal/xcode_swift_toolchain.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ load(
3838
"SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES",
3939
"SWIFT_FEATURE_MODULE_MAP_HOME_IS_CWD",
4040
"SWIFT_FEATURE_REMAP_XCODE_PATH",
41+
"SWIFT_FEATURE_SUPPORTS_BARE_SLASH_REGEX",
4142
"SWIFT_FEATURE_SUPPORTS_LIBRARY_EVOLUTION",
4243
"SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS",
4344
"SWIFT_FEATURE_SUPPORTS_SYSTEM_MODULE_FLAG",
@@ -605,6 +606,10 @@ def _xcode_swift_toolchain_impl(ctx):
605606
if _is_xcode_at_least_version(xcode_config, "12.5"):
606607
requested_features.append(SWIFT_FEATURE_SUPPORTS_SYSTEM_MODULE_FLAG)
607608

609+
# Xcode 14 implies Swift 5.7.
610+
if _is_xcode_at_least_version(xcode_config, "14.0"):
611+
requested_features.append(SWIFT_FEATURE_SUPPORTS_BARE_SLASH_REGEX)
612+
608613
env = _xcode_env(target_triple = target_triple, xcode_config = xcode_config)
609614
execution_requirements = xcode_config.execution_info()
610615
generated_header_rewriter = resolve_optional_tool(

0 commit comments

Comments
 (0)