Skip to content

Commit 5646c0f

Browse files
authored
Merge pull request #775 from bkhouri/t/main/gh9040_snippets
Build Setting: Add a SWIFT_DISABLE_PARSE_AS_LIBRARY Setting
2 parents 3a242d6 + fd9139d commit 5646c0f

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ public final class BuiltinMacros {
10461046
public static let SWIFT_INDEX_STORE_PATH = BuiltinMacros.declarePathMacro("SWIFT_INDEX_STORE_PATH")
10471047
public static let SWIFT_INSTALL_OBJC_HEADER = BuiltinMacros.declareBooleanMacro("SWIFT_INSTALL_OBJC_HEADER")
10481048
public static let SWIFT_INSTALLAPI_LAZY_TYPECHECK = BuiltinMacros.declareBooleanMacro("SWIFT_INSTALLAPI_LAZY_TYPECHECK")
1049+
public static let SWIFT_DISABLE_PARSE_AS_LIBRARY = BuiltinMacros.declareBooleanMacro("SWIFT_DISABLE_PARSE_AS_LIBRARY")
10491050
public static let SWIFT_LIBRARIES_ONLY = BuiltinMacros.declareBooleanMacro("SWIFT_LIBRARIES_ONLY")
10501051
public static let SWIFT_LIBRARY_LEVEL = BuiltinMacros.declareStringMacro("SWIFT_LIBRARY_LEVEL")
10511052
public static let SWIFT_LIBRARY_PATH = BuiltinMacros.declarePathMacro("SWIFT_LIBRARY_PATH")
@@ -2223,6 +2224,7 @@ public final class BuiltinMacros {
22232224
_SWIFT_EXPLICIT_MODULES_ALLOW_CXX_INTEROP,
22242225
_SWIFT_EXPLICIT_MODULES_ALLOW_BEFORE_SWIFT_5,
22252226
_EXPERIMENTAL_SWIFT_EXPLICIT_MODULES,
2227+
SWIFT_DISABLE_PARSE_AS_LIBRARY,
22262228
SWIFT_ENABLE_BARE_SLASH_REGEX,
22272229
SWIFT_ENABLE_EMIT_CONST_VALUES,
22282230
SWIFT_ENABLE_OPAQUE_TYPE_ERASURE,

Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
16281628
// If there is only a single input, ensure we pass -parse-as-library as appropriate.
16291629
if cbc.inputs.count == 1 {
16301630
let filename = cbc.inputs[0].absolutePath.basename
1631-
if filename != SwiftCompilerSpec.mainFileName && !cbc.scope.evaluate(BuiltinMacros.SWIFT_LIBRARIES_ONLY) {
1631+
if filename != SwiftCompilerSpec.mainFileName && !cbc.scope.evaluate(BuiltinMacros.SWIFT_LIBRARIES_ONLY) && !cbc.scope.evaluate(BuiltinMacros.SWIFT_DISABLE_PARSE_AS_LIBRARY) {
16321632
// Add -parse-as-library if the only input's file name isn't main.swift and if we didn't already add it due to SWIFT_LIBRARIES_ONLY.
16331633
args.append("-parse-as-library")
16341634
}

Sources/SwiftBuild/ProjectModel/BuildSettings.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ extension ProjectModel {
9999
case STRIP_INSTALLED_PRODUCT
100100
case SUPPORTS_TEXT_BASED_API
101101
case SUPPRESS_WARNINGS
102+
case SWIFT_DISABLE_PARSE_AS_LIBRARY
102103
case SWIFT_ENABLE_BARE_SLASH_REGEX
103104
case SWIFT_INDEX_STORE_ENABLE
104105
case SWIFT_INSTALL_MODULE

Tests/SWBTaskConstructionTests/SwiftTaskConstructionTests.swift

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4260,6 +4260,64 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
42604260
}
42614261
}
42624262

4263+
@Test(.requireSDKs(.host))
4264+
func swiftDisableParseAsLibrarySettings() async throws {
4265+
let targetName = "targetName"
4266+
try await withTemporaryDirectory { tmpDir in
4267+
let testProject = try await TestProject(
4268+
"ProjectName",
4269+
sourceRoot: tmpDir.join("srcroot"),
4270+
groupTree: TestGroup(
4271+
"SomeFiles",
4272+
children: [
4273+
TestFile("File1.swift"),
4274+
]),
4275+
targets: [
4276+
TestStandardTarget(
4277+
targetName,
4278+
type: .framework,
4279+
buildConfigurations: [
4280+
TestBuildConfiguration("Debug", buildSettings: [
4281+
"PRODUCT_NAME": "$(TARGET_NAME)",
4282+
"SWIFT_EXEC": swiftCompilerPath.str,
4283+
"CODE_SIGN_IDENTITY": "",
4284+
"SWIFT_VERSION": swiftVersion,
4285+
]),
4286+
],
4287+
buildPhases: [
4288+
TestSourcesBuildPhase([
4289+
TestBuildFile("File1.swift"),
4290+
]),
4291+
])
4292+
])
4293+
4294+
let tester = try await TaskConstructionTester(getCore(), testProject)
4295+
await tester.checkBuild(
4296+
BuildParameters(configuration: "Debug", overrides: ["SWIFT_DISABLE_PARSE_AS_LIBRARY": "YES"]),
4297+
runDestination: .host,
4298+
) { results in
4299+
results.checkTarget(targetName) { target in
4300+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
4301+
task.checkCommandLineDoesNotContain("-parse-as-library")
4302+
}
4303+
}
4304+
}
4305+
4306+
await tester.checkBuild(
4307+
BuildParameters(configuration: "Debug", overrides: ["SWIFT_DISABLE_PARSE_AS_LIBRARY": "NO"]),
4308+
runDestination: .host,
4309+
) { results in
4310+
results.checkTarget(targetName) { target in
4311+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
4312+
task.checkCommandLineContains(["-parse-as-library"])
4313+
}
4314+
}
4315+
}
4316+
4317+
4318+
}
4319+
}
4320+
42634321
@Test(.requireSDKs(.macOS))
42644322
func layoutStringValueWitnesses() async throws {
42654323
try await withTemporaryDirectory { tmpDir in

0 commit comments

Comments
 (0)