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

Support scripts w/ @main #163

Open
helje5 opened this issue Aug 23, 2021 · 1 comment · May be fixed by #194
Open

Support scripts w/ @main #163

helje5 opened this issue Aug 23, 2021 · 1 comment · May be fixed by #194

Comments

@helje5
Copy link
Contributor

helje5 commented Aug 23, 2021

It would be nice if swift-sh would support scripts that contain the new @main. Like:

@main
struct MyTool: App {
  
  var body: some Scene {
    WindowGroup { Text("Hello World!") }
  }
}

Suggested implementation:

  • grep the source file for @main or maybe @main[\t\n ]+struct if the script itself is not called main.swift
  • if found, do not copy the script to main.swift but instead keep the original script name (like MyTool.swift)
  • the hashbang line must be removed, it is only allowed in main.swift
  • use Swift package tools version 5.5 (required for working @main), and add this to the Package.swift:
// swift-tools-version:5.5
...
pkg.platforms = [ .macOS(.v11) ]

Another option might be to use the hashbang line to configure an explicit mode? Like:

#!/usr/bin/swift sh #@main
@mxcl
Copy link
Owner

mxcl commented Sep 24, 2021

I agree with your suggested approach.

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 a pull request may close this issue.

2 participants