Skip to content

Commit 6c11adb

Browse files
committed
Add SWIFTC_DISABLE_SANDBOX Swift compiler xcspec settings
Some package systems (e.g: HomeBrew, Nix) use a custom build sandbox. Within the outer sandbox, Swift Toolchain should not create their own sandbox, which is why SwiftPM offers a `--disable-sandbox` options. Add a Swift compiler XCSpec setting that, when set, passes the respective command line argument to the swiftc compiler. Relates to: swiftlang/swift-package-manager#7098 Issue: rdar://179641209
1 parent fab0c1c commit 6c11adb

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

Sources/SWBUniversalPlatform/Specs/Swift.xcspec

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,17 @@
12031203
};
12041204
},
12051205

1206+
{
1207+
Name = "SWIFTC_DISABLE_SANDBOX";
1208+
Type = Boolean;
1209+
DefaultValue = NO;
1210+
CommandLineArgs = {
1211+
YES = (
1212+
"-disable-sandbox",
1213+
);
1214+
NO = ();
1215+
};
1216+
},
12061217
{
12071218
Name = "ENABLE_CODESIZE_PROFILE";
12081219
Type = Boolean;

Tests/SWBTaskConstructionTests/SwiftTaskConstructionTests.swift

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4855,6 +4855,88 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
48554855
}
48564856
}
48574857

4858+
@Test(
4859+
.requireSDKs(.host),
4860+
)
4861+
func swiftcDisableSandboxSetting() async throws {
4862+
let targetName = "targetName"
4863+
let swiftCompilerPath = try await self.swiftCompilerPath
4864+
let swiftVersion = try await self.swiftVersion
4865+
let libtoolPath = try await self.libtoolPath
4866+
try await withTemporaryDirectory { tmpDir in
4867+
let testProject = try await TestProject(
4868+
"ProjectName",
4869+
sourceRoot: tmpDir.join("srcroot"),
4870+
groupTree: TestGroup(
4871+
"SomeFiles",
4872+
children: [
4873+
TestFile("File1.swift"),
4874+
],
4875+
),
4876+
targets: [
4877+
TestStandardTarget(
4878+
targetName,
4879+
type: .staticLibrary,
4880+
buildConfigurations: [
4881+
TestBuildConfiguration(
4882+
"Debug",
4883+
buildSettings: [
4884+
"PRODUCT_NAME": "$(TARGET_NAME)",
4885+
"SWIFT_EXEC": swiftCompilerPath.str,
4886+
"LIBTOOL": libtoolPath.str,
4887+
"SWIFT_VERSION": swiftVersion,
4888+
],
4889+
),
4890+
],
4891+
buildPhases: [
4892+
TestSourcesBuildPhase(
4893+
[
4894+
TestBuildFile("File1.swift"),
4895+
],
4896+
),
4897+
],
4898+
),
4899+
],
4900+
)
4901+
4902+
let tester = try await TaskConstructionTester(getCore(), testProject)
4903+
4904+
// Default (setting unset) should not pass -disable-sandbox.
4905+
await tester.checkBuild(
4906+
BuildParameters(configuration: "Debug"),
4907+
runDestination: .host,
4908+
) { results in
4909+
results.checkTarget(targetName) { target in
4910+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
4911+
task.checkCommandLineDoesNotContain("-disable-sandbox")
4912+
}
4913+
}
4914+
}
4915+
4916+
await tester.checkBuild(
4917+
BuildParameters(configuration: "Debug", overrides: ["SWIFTC_DISABLE_SANDBOX": "YES"]),
4918+
runDestination: .host,
4919+
) { results in
4920+
results.checkTarget(targetName) { target in
4921+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
4922+
task.checkCommandLineContains(["-disable-sandbox"])
4923+
}
4924+
}
4925+
}
4926+
4927+
await tester.checkBuild(
4928+
BuildParameters(configuration: "Debug", overrides: ["SWIFTC_DISABLE_SANDBOX": "NO"]),
4929+
runDestination: .host,
4930+
) { results in
4931+
results.checkTarget(targetName) { target in
4932+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
4933+
task.checkCommandLineDoesNotContain("-disable-sandbox")
4934+
}
4935+
}
4936+
}
4937+
}
4938+
}
4939+
48584940
@Test(.requireSDKs(.macOS))
48594941
func layoutStringValueWitnesses() async throws {
48604942
try await withTemporaryDirectory { tmpDir in

0 commit comments

Comments
 (0)