File tree 4 files changed +42
-0
lines changed
4 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 45
45
"SWIFT_FEATURE_COVERAGE_PREFIX_MAP" ,
46
46
"SWIFT_FEATURE_DBG" ,
47
47
"SWIFT_FEATURE_DEBUG_PREFIX_MAP" ,
48
+ "SWIFT_FEATURE_DISABLE_SWIFT_SANDBOX" ,
48
49
"SWIFT_FEATURE_DISABLE_SYSTEM_INDEX" ,
49
50
"SWIFT_FEATURE_EMIT_BC" ,
50
51
"SWIFT_FEATURE_EMIT_C_MODULE" ,
@@ -564,6 +565,19 @@ def compile_action_configs(
564
565
features = [SWIFT_FEATURE_TREAT_WARNINGS_AS_ERRORS ],
565
566
),
566
567
568
+ # Disable Swift sandbox.
569
+ swift_toolchain_config .action_config (
570
+ actions = [
571
+ swift_action_names .COMPILE ,
572
+ swift_action_names .DERIVE_FILES ,
573
+ swift_action_names .DUMP_AST ,
574
+ ],
575
+ configurators = [
576
+ swift_toolchain_config .add_arg ("-disable-sandbox" ),
577
+ ],
578
+ features = [SWIFT_FEATURE_DISABLE_SWIFT_SANDBOX ],
579
+ ),
580
+
567
581
# Set Developer Framework search paths
568
582
swift_toolchain_config .action_config (
569
583
actions = [
Original file line number Diff line number Diff line change @@ -341,6 +341,11 @@ SWIFT_FEATURE__FORCE_ALWAYSLINK_TRUE = "swift._force_alwayslink_true"
341
341
# feature.
342
342
SWIFT_FEATURE__SUPPORTS_MACROS = "swift._supports_macros"
343
343
344
+ # Disables Swift sandbox which prevents issues with nested sandboxing when Swift code contains system-provided macros.
345
+ # If enabled '#Preview' macro provided by SwiftUI fails to build and probably other system-provided macros.
346
+ # Enabled by default for Swift 5.10+ on macOS.
347
+ SWIFT_FEATURE_DISABLE_SWIFT_SANDBOX = "swift.disable_swift_sandbox"
348
+
344
349
# Pass -warnings-as-errors to the compiler.
345
350
SWIFT_FEATURE_TREAT_WARNINGS_AS_ERRORS = "swift.treat_warnings_as_errors"
346
351
Original file line number Diff line number Diff line change 35
35
"SWIFT_FEATURE_COVERAGE" ,
36
36
"SWIFT_FEATURE_COVERAGE_PREFIX_MAP" ,
37
37
"SWIFT_FEATURE_DEBUG_PREFIX_MAP" ,
38
+ "SWIFT_FEATURE_DISABLE_SWIFT_SANDBOX" ,
38
39
"SWIFT_FEATURE_EMIT_SWIFTDOC" ,
39
40
"SWIFT_FEATURE_EMIT_SWIFTSOURCEINFO" ,
40
41
"SWIFT_FEATURE_ENABLE_BATCH_MODE" ,
@@ -640,6 +641,9 @@ def _xcode_swift_toolchain_impl(ctx):
640
641
requested_features .append (SWIFT_FEATURE__SUPPORTS_MACROS )
641
642
requested_features .append (SWIFT_FEATURE__SUPPORTS_CONST_VALUE_EXTRACTION )
642
643
644
+ if _is_xcode_at_least_version (xcode_config , "15.3" ):
645
+ requested_features .append (SWIFT_FEATURE_DISABLE_SWIFT_SANDBOX )
646
+
643
647
env = _xcode_env (target_triple = target_triple , xcode_config = xcode_config )
644
648
execution_requirements = xcode_config .execution_info ()
645
649
generated_header_rewriter = ctx .executable .generated_header_rewriter
Original file line number Diff line number Diff line change @@ -60,6 +60,14 @@ use_global_index_store_index_while_building_test = make_action_command_line_test
60
60
},
61
61
)
62
62
63
+ disable_swift_sandbox_test = make_action_command_line_test_rule (
64
+ config_settings = {
65
+ "//command_line_option:features" : [
66
+ "swift.disable_swift_sandbox" ,
67
+ ],
68
+ },
69
+ )
70
+
63
71
vfsoverlay_test = make_action_command_line_test_rule (
64
72
config_settings = {
65
73
"//command_line_option:features" : [
@@ -179,6 +187,17 @@ def features_test_suite(name):
179
187
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple" ,
180
188
)
181
189
190
+ disable_swift_sandbox_test (
191
+ name = "{}_disable_swift_sandbox_test" .format (name ),
192
+ tags = [name ],
193
+ expected_argv = [
194
+ "-disable-sandbox" ,
195
+ ],
196
+ mnemonic = "SwiftCompile" ,
197
+ target_compatible_with = ["@platforms//os:macos" ],
198
+ target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple" ,
199
+ )
200
+
182
201
default_opt_test (
183
202
name = "{}_default_opt_test" .format (name ),
184
203
tags = [name ],
You can’t perform that action at this time.
0 commit comments