Import swift file in script

Not really. It doesn’t look like much activity has happened here of the last few years. But it is something I’ve given thought to.

Ideally we can do something without changing the language. The import statement today is for modules, so would prefer to leave it at that.

The other thing I’d like to do with scripts is to be able to import modules from packages. Maybe once we have a mechanism for that we can solve scripts as multiple files in the same way. Either something in comments at the top of the file, or parameters to the swift command in the #!.

The main problem there is today, SwiftPM isn’t involved with running scripts. The swift driver sends them off to the swift-frontend to interpret them. If, instead, it sent them to SwiftPM and it assembled the dependencies, we could then get swift-frontend all the information it needs about those dependencies to interpret the script.

It’s a fascinating extension to Swift scripts. I’ve tried writing a script when I did the prebuilts work to build the prebuilts and just ended up creating an executableTarget in the SwiftPM package instead. I’d much rather it just be a standalone script that CI could run that would specify its own dependencies. It would be great to have something there.

4 Likes