Skip to content

Commit a387251

Browse files
committed
SwiftPM complains about @main in non main.swift file when integrated driver is not enabled
One of several different code paths in BuildPlan.swift are taken depending on whether the integrated Swift driver is enabled, whether explicit modules are enabled, etc. In the non-integrated-driver case, the code path for adding a `-parse-as-library` when necessary wasn't taken. This moves that code to a more central place. A unit test is needed that will make sure the flag is added in this case as well. rdar://78080245
1 parent 5e638b0 commit a387251

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,11 @@ public final class SwiftTargetBuildDescription {
757757
}
758758
}
759759
}
760+
761+
// If the target needs to be parsed without any special semantics involving "main.swift", do so now.
762+
if self.needsToBeParsedAsLibrary {
763+
args += ["-parse-as-library"]
764+
}
760765

761766
// Only add the build path to the framework search path if there are binary frameworks to link against.
762767
if !libraryBinaryPaths.isEmpty {
@@ -809,10 +814,6 @@ public final class SwiftTargetBuildDescription {
809814
// FIXME: Eliminate side effect.
810815
result.append(try writeOutputFileMap().pathString)
811816

812-
if self.needsToBeParsedAsLibrary {
813-
result.append("-parse-as-library")
814-
}
815-
816817
if buildParameters.useWholeModuleOptimization {
817818
result.append("-whole-module-optimization")
818819
result.append("-num-threads")
@@ -849,10 +850,6 @@ public final class SwiftTargetBuildDescription {
849850
result.append("-experimental-skip-non-inlinable-function-bodies")
850851
result.append("-force-single-frontend-invocation")
851852

852-
if self.needsToBeParsedAsLibrary {
853-
result.append("-parse-as-library")
854-
}
855-
856853
// FIXME: Handle WMO
857854

858855
for source in target.sources.paths {
@@ -896,9 +893,6 @@ public final class SwiftTargetBuildDescription {
896893
// FIXME: Eliminate side effect.
897894
result.append(try writeOutputFileMap().pathString)
898895

899-
if self.needsToBeParsedAsLibrary {
900-
result.append("-parse-as-library")
901-
}
902896
// FIXME: Handle WMO
903897

904898
result.append("-c")

0 commit comments

Comments
 (0)