swift-sh
swift-sh copied to clipboard
Support scripts w/ `@main`
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
@mainor maybe@main[\t\n ]+structif the script itself is not calledmain.swift - if found, do not copy the script to
main.swiftbut 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 thePackage.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
I agree with your suggested approach.