You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pass -parse-as-library when compiling an executable module that has a single source file that isn't named main.swift
The Swift compiler has certain special behaviors regarding main source files:
- if a module has just a single source file of any name, it's treated as the main source file
- if a module has a source file named `main.swift`, it's treated as the main source file
If a source file is considered the main source file, it can have top level code. But a source file that has top level code can't also have `@main`.
This means that a single source file executable module can't use `@main`, regardless of the name of that source file. A second empty source file can be added as a workaround, but we can employ some countermeasures in SwiftPM.
Specifically, if the executable module consists of a single source file and it is not named `main.swift`, we pass `-parse-as-library` so that a single-source file module will work. This matches what can be seen in the build logs in Xcode.
This does not allow use of `@main` in source files named `main.swift`, but that will require compiler support to address.
rdar://76746150
0 commit comments