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
2 changes: 2 additions & 0 deletions Sources/SWBCore/Settings/BuiltinMacros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,7 @@ public final class BuiltinMacros {
public static let SWIFT_INDEX_STORE_PATH = BuiltinMacros.declarePathMacro("SWIFT_INDEX_STORE_PATH")
public static let SWIFT_INSTALL_OBJC_HEADER = BuiltinMacros.declareBooleanMacro("SWIFT_INSTALL_OBJC_HEADER")
public static let SWIFT_INSTALLAPI_LAZY_TYPECHECK = BuiltinMacros.declareBooleanMacro("SWIFT_INSTALLAPI_LAZY_TYPECHECK")
public static let SWIFT_DISABLE_PARSE_AS_LIBRARY = BuiltinMacros.declareBooleanMacro("SWIFT_DISABLE_PARSE_AS_LIBRARY")
public static let SWIFT_LIBRARIES_ONLY = BuiltinMacros.declareBooleanMacro("SWIFT_LIBRARIES_ONLY")
public static let SWIFT_LIBRARY_LEVEL = BuiltinMacros.declareStringMacro("SWIFT_LIBRARY_LEVEL")
public static let SWIFT_LIBRARY_PATH = BuiltinMacros.declarePathMacro("SWIFT_LIBRARY_PATH")
Expand Down Expand Up @@ -2222,6 +2223,7 @@ public final class BuiltinMacros {
_SWIFT_EXPLICIT_MODULES_ALLOW_CXX_INTEROP,
_SWIFT_EXPLICIT_MODULES_ALLOW_BEFORE_SWIFT_5,
_EXPERIMENTAL_SWIFT_EXPLICIT_MODULES,
SWIFT_DISABLE_PARSE_AS_LIBRARY,
SWIFT_ENABLE_BARE_SLASH_REGEX,
SWIFT_ENABLE_EMIT_CONST_VALUES,
SWIFT_ENABLE_OPAQUE_TYPE_ERASURE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,7 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
// If there is only a single input, ensure we pass -parse-as-library as appropriate.
if cbc.inputs.count == 1 {
let filename = cbc.inputs[0].absolutePath.basename
if filename != SwiftCompilerSpec.mainFileName && !cbc.scope.evaluate(BuiltinMacros.SWIFT_LIBRARIES_ONLY) {
if filename != SwiftCompilerSpec.mainFileName && !cbc.scope.evaluate(BuiltinMacros.SWIFT_LIBRARIES_ONLY) && !cbc.scope.evaluate(BuiltinMacros.SWIFT_DISABLE_PARSE_AS_LIBRARY) {
// 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.
args.append("-parse-as-library")
}
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftBuild/ProjectModel/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ extension ProjectModel {
case STRIP_INSTALLED_PRODUCT
case SUPPORTS_TEXT_BASED_API
case SUPPRESS_WARNINGS
case SWIFT_DISABLE_PARSE_AS_LIBRARY
case SWIFT_ENABLE_BARE_SLASH_REGEX
case SWIFT_INDEX_STORE_ENABLE
case SWIFT_INSTALL_MODULE
Expand Down
58 changes: 58 additions & 0 deletions Tests/SWBTaskConstructionTests/SwiftTaskConstructionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4260,6 +4260,64 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
}
}

@Test(.requireSDKs(.host))
func swiftDisableParseAsLibrarySettings() async throws {
let targetName = "targetName"
try await withTemporaryDirectory { tmpDir in
let testProject = try await TestProject(
"ProjectName",
sourceRoot: tmpDir.join("srcroot"),
groupTree: TestGroup(
"SomeFiles",
children: [
TestFile("File1.swift"),
]),
targets: [
TestStandardTarget(
targetName,
type: .framework,
buildConfigurations: [
TestBuildConfiguration("Debug", buildSettings: [
"PRODUCT_NAME": "$(TARGET_NAME)",
"SWIFT_EXEC": swiftCompilerPath.str,
"CODE_SIGN_IDENTITY": "",
"SWIFT_VERSION": swiftVersion,
]),
],
buildPhases: [
TestSourcesBuildPhase([
TestBuildFile("File1.swift"),
]),
])
])

let tester = try await TaskConstructionTester(getCore(), testProject)
await tester.checkBuild(
BuildParameters(configuration: "Debug", overrides: ["SWIFT_DISABLE_PARSE_AS_LIBRARY": "YES"]),
runDestination: .host,
) { results in
results.checkTarget(targetName) { target in
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
task.checkCommandLineDoesNotContain("-parse-as-library")
}
}
}

await tester.checkBuild(
BuildParameters(configuration: "Debug", overrides: ["SWIFT_DISABLE_PARSE_AS_LIBRARY": "NO"]),
runDestination: .host,
) { results in
results.checkTarget(targetName) { target in
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
task.checkCommandLineContains(["-parse-as-library"])
}
}
}


}
}

@Test(.requireSDKs(.macOS))
func layoutStringValueWitnesses() async throws {
try await withTemporaryDirectory { tmpDir in
Expand Down