Skip to content

Change executable template to use main.swift #6197

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

Merged
merged 1 commit into from
Feb 28, 2023
Merged

Change executable template to use main.swift #6197

merged 1 commit into from
Feb 28, 2023

Conversation

neonichu
Copy link
Contributor

@neonichu neonichu commented Feb 28, 2023

The recent changes to templates switched this template away from using @main which seems to not be compatible with Xcode's build system. The only non-@main way for executables that is supported is naming the primary source file "main.swift", so that is what this PR does.

@neonichu neonichu requested a review from bitjammer February 28, 2023 20:55
@neonichu neonichu requested a review from abertelrud as a code owner February 28, 2023 20:55
@neonichu neonichu self-assigned this Feb 28, 2023
@neonichu neonichu requested a review from tomerd as a code owner February 28, 2023 20:55
@neonichu
Copy link
Contributor Author

@swift-ci please smoke test

The recent changes to templates switched this template away from using `@main` which seems to not be compatible with Xcode's build system. The only non-`@main` way for executables that is supported is naming the primary source file "main.swift", so that is what this PR does.
@neonichu
Copy link
Contributor Author

@swift-ci please smoke test

@neonichu neonichu changed the title Change executable and tool templates to use main.swift Change executable template to use main.swift Feb 28, 2023
Copy link
Contributor

@bitjammer bitjammer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I manually verified that all generated packages build with swift build and xcodebuild.

@neonichu neonichu merged commit 0e4b432 into main Feb 28, 2023
@neonichu neonichu deleted the main-character branch February 28, 2023 22:26
yim-lee pushed a commit to yim-lee/swift-package-manager that referenced this pull request Feb 28, 2023
The recent changes to templates switched this template away from using `@main` which seems to not be compatible with Xcode's build system. The only non-`@main` way for executables that is supported is naming the primary source file "main.swift", so that is what this PR does.
plemarquand added a commit to plemarquand/swift-package-manager that referenced this pull request Mar 18, 2025
plemarquand added a commit to plemarquand/swift-package-manager that referenced this pull request Mar 24, 2025
plemarquand added a commit that referenced this pull request Apr 3, 2025
…8371)

### Motivation:

Since `@main` is the general purpose way of marking the entry point to
executables, use it over top level code when generating an executable
template.

### Modifications:

Update the template output when the specified `--type` is executable.

### Result:

The template is now:

```swift
@main
struct MyProject {
  static func main() {
    print("Hello, world!")
  }
}
```

This patch reverts
#6197 and
partially reverts
#6144

---------

Co-authored-by: David Nadoba <[email protected]>
Co-authored-by: Joseph Heck <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants