Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swift: Add swift_implicit_main target kwarg #14298

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

2xsaiko
Copy link
Contributor

@2xsaiko 2xsaiko commented Feb 25, 2025

This is a more customizable approach to #14267. (Closes #14267.)

The '-parse-as-library' compiler option forbids emitting top-level statements as part of an implicitly generated main function. This happens either in Swift modules consisting of only one file, or modules containing a 'main.swift' file. As a consequence, library targets should usually have this argument applied in order to not cause duplicate main symbols when linking the final executable. This is the new default behavior. Sometimes it is necessary to override this behavior, for example in case your Swift program has a struct annotated with @​main, or you have an executable Swift target that gets its main function from elsewhere (for example, linked C code). For this, targets can be passed the 'swift_implicit_main' kwarg, either with 'auto', which specifies Swift's default behavior, or 'never', which passes the '-parse-as-library' flag.

@2xsaiko 2xsaiko force-pushed the push-ryrwqlsyumsx branch 2 times, most recently from de65bfe to b210239 Compare March 7, 2025 19:39
The '-parse-as-library' compiler option forbids emitting top-level
statements as part of an implicitly generated main function. This
happens either in Swift modules consisting of only one file, or
modules containing a 'main.swift' file. As a consequence, library
targets should usually have this argument applied in order to not
cause duplicate main symbols when linking the final executable. This
is the new default behavior. Sometimes it is necessary to override
this behavior, for example in case your Swift executable has a struct
annotated with @main, or you have an executable Swift target that gets
its main function from elsewhere (for example, linked C code). For
this, targets can be passed the 'swift_implicit_main' kwarg, either
with 'auto', which specifies Swift's default behavior, or 'never',
which passes the '-parse-as-library' flag.
@2xsaiko 2xsaiko force-pushed the push-ryrwqlsyumsx branch from b210239 to f1c04f0 Compare March 25, 2025 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants