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
14 changes: 14 additions & 0 deletions swift/internal/compiling.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ load(
"SWIFT_FEATURE_COVERAGE_PREFIX_MAP",
"SWIFT_FEATURE_DBG",
"SWIFT_FEATURE_DEBUG_PREFIX_MAP",
"SWIFT_FEATURE_DISABLE_SWIFT_SANDBOX",
"SWIFT_FEATURE_DISABLE_SYSTEM_INDEX",
"SWIFT_FEATURE_EMIT_BC",
"SWIFT_FEATURE_EMIT_C_MODULE",
Expand Down Expand Up @@ -564,6 +565,19 @@ def compile_action_configs(
features = [SWIFT_FEATURE_TREAT_WARNINGS_AS_ERRORS],
),

# Disable Swift sandbox.
swift_toolchain_config.action_config(
actions = [
swift_action_names.COMPILE,
swift_action_names.DERIVE_FILES,
swift_action_names.DUMP_AST,
],
configurators = [
swift_toolchain_config.add_arg("-disable-sandbox"),
],
features = [SWIFT_FEATURE_DISABLE_SWIFT_SANDBOX],
),

# Set Developer Framework search paths
swift_toolchain_config.action_config(
actions = [
Expand Down
5 changes: 5 additions & 0 deletions swift/internal/feature_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ SWIFT_FEATURE__FORCE_ALWAYSLINK_TRUE = "swift._force_alwayslink_true"
# feature.
SWIFT_FEATURE__SUPPORTS_MACROS = "swift._supports_macros"

# Disables Swift sandbox which prevents issues with nested sandboxing when Swift code contains system-provided macros.
# If enabled '#Preview' macro provided by SwiftUI fails to build and probably other system-provided macros.
# Enabled by default for Swift 5.10+ on macOS.
SWIFT_FEATURE_DISABLE_SWIFT_SANDBOX = "swift.disable_swift_sandbox"

# Pass -warnings-as-errors to the compiler.
SWIFT_FEATURE_TREAT_WARNINGS_AS_ERRORS = "swift.treat_warnings_as_errors"

Expand Down
4 changes: 4 additions & 0 deletions swift/internal/xcode_swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ load(
"SWIFT_FEATURE_COVERAGE",
"SWIFT_FEATURE_COVERAGE_PREFIX_MAP",
"SWIFT_FEATURE_DEBUG_PREFIX_MAP",
"SWIFT_FEATURE_DISABLE_SWIFT_SANDBOX",
"SWIFT_FEATURE_EMIT_SWIFTDOC",
"SWIFT_FEATURE_EMIT_SWIFTSOURCEINFO",
"SWIFT_FEATURE_ENABLE_BATCH_MODE",
Expand Down Expand Up @@ -640,6 +641,9 @@ def _xcode_swift_toolchain_impl(ctx):
requested_features.append(SWIFT_FEATURE__SUPPORTS_MACROS)
requested_features.append(SWIFT_FEATURE__SUPPORTS_CONST_VALUE_EXTRACTION)

if _is_xcode_at_least_version(xcode_config, "15.3"):
requested_features.append(SWIFT_FEATURE_DISABLE_SWIFT_SANDBOX)

env = _xcode_env(target_triple = target_triple, xcode_config = xcode_config)
execution_requirements = xcode_config.execution_info()
generated_header_rewriter = ctx.executable.generated_header_rewriter
Expand Down
19 changes: 19 additions & 0 deletions test/features_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ use_global_index_store_index_while_building_test = make_action_command_line_test
},
)

disable_swift_sandbox_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:features": [
"swift.disable_swift_sandbox",
],
},
)

vfsoverlay_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:features": [
Expand Down Expand Up @@ -179,6 +187,17 @@ def features_test_suite(name):
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
)

disable_swift_sandbox_test(
name = "{}_disable_swift_sandbox_test".format(name),
tags = [name],
expected_argv = [
"-disable-sandbox",
],
mnemonic = "SwiftCompile",
target_compatible_with = ["@platforms//os:macos"],
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple",
)

default_opt_test(
name = "{}_default_opt_test".format(name),
tags = [name],
Expand Down