Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Swift compiler sandboxing in Xcode 15.3+ to fix nested sandboxing #1206

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -83,6 +83,7 @@ load(
"SWIFT_FEATURE_USE_OLD_DRIVER",
"SWIFT_FEATURE_USE_PCH_OUTPUT_DIR",
"SWIFT_FEATURE_VFSOVERLAY",
"SWIFT_FEATURE__DISABLE_SWIFT_SANDBOX",
"SWIFT_FEATURE__NUM_THREADS_0_IN_SWIFTCOPTS",
"SWIFT_FEATURE__SUPPORTS_CONST_VALUE_EXTRACTION",
"SWIFT_FEATURE__SUPPORTS_MACROS",
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
4 changes: 4 additions & 0 deletions swift/internal/feature_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ 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.
adincebic marked this conversation as resolved.
Show resolved Hide resolved
SWIFT_FEATURE__DISABLE_SWIFT_SANDBOX = "swift._disable_swift_sandbox"
adincebic marked this conversation as resolved.
Show resolved Hide resolved

# 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 @@ -50,6 +50,7 @@ load(
"SWIFT_FEATURE_SUPPORTS_SYSTEM_MODULE_FLAG",
"SWIFT_FEATURE_USE_GLOBAL_MODULE_CACHE",
"SWIFT_FEATURE_USE_RESPONSE_FILES",
"SWIFT_FEATURE__DISABLE_SWIFT_SANDBOX",
adincebic marked this conversation as resolved.
Show resolved Hide resolved
"SWIFT_FEATURE__FORCE_ALWAYSLINK_TRUE",
"SWIFT_FEATURE__SUPPORTS_CONST_VALUE_EXTRACTION",
"SWIFT_FEATURE__SUPPORTS_MACROS",
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)
adincebic marked this conversation as resolved.
Show resolved Hide resolved

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