What flags to you have to pass to the compiler to tell it to generate an executable from a file that isn’t called
main.swift? How does it know to treat top‐level code as a function body? How does it decide what to name the main function? How does it set up the entry point? Is Windows any different?
Such a thing must be possible:
- SwiftPM generates an executable from
- CMake doesn’t care what the file name is; @compnerd’s example uses
hello.swiftand works across all platforms.
My main motivation for asking is the hope of finding a workaround for this, but as I hunt through the source of both SwiftPM and CMake, I’ve mostly just realized I have no idea how the compiler works in this area in the first place. I’m finding nothing mostly because I don’t even know what I’m looking for.