<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I have a crazy idea about how this could work by integrating with SwiftPM -- would love to see someone mock up a prototype...<div class=""><br class=""></div><div class="">1. Define a special syntax for describing a script's dependencies inline in the script source</div><div class="">2. Create a mode for the Swift package manager where it analyzes the input script, extracts the package dependencies, and creates a custom Swift package just for that script.</div><div class="">3. Identify the created Swift package by hash, and stash it somewhere in the user's home directory, so that it would be cached</div><div class="">4. Automatically build and run the package</div><div class=""><br class=""></div><div class="">The cool thing about this model is it would seamlessly integrate command line scripting and the Swift package ecosystem, and it would provide a seamless user experience that avoids needing to worry about building anything to get good script performance. As the package manager got smarter about being able to share build artifacts it would transparently get faster, but user's wouldn't need to worry about managing the dependencies.</div><div class=""><br class=""></div><div class="">Strawman:</div><div class=""><br class=""></div><div class="">--</div><div class="">#!/usr/bin/env swift run --script</div><div class=""><br class=""></div><div class="">// Uses: SuperCoolCommandLine: 1.x</div><div class=""><div class="">// Uses: AreYouFeelingANSI: 1.3.x</div></div><div class=""><br class=""></div><div class="">import SuperCoolCommandLine</div><div class="">import AreYouFeelingANSI</div><div class=""><br class=""></div><div class="">...</div><div class="">--</div><div class=""><br class=""></div><div class="">&nbsp;`swift` will already happily look for binaries like `swift-run` today (like git), so there is nothing blocking someone from hacking this up as a quick and dirty script to see how it works...</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">&nbsp;- Daniel</div><div class=""><br class=""></div><div class=""><div class=""><div><blockquote type="cite" class=""><div class="">On Feb 18, 2017, at 11:26 AM, Maxim Veksler via swift-build-dev &lt;<a href="mailto:swift-build-dev@swift.org" class="">swift-build-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi,<div class=""><br class=""></div><div class="">Ayaka Nonaka gave a talk[1] about basic scripting[2] support in Swift.&nbsp;<br class=""></div><div class=""><br class=""></div><div class="">The gist of the idea is to use&nbsp;<span class="inbox-pl-c" style="box-sizing:border-box;color:rgb(150,152,150);font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:12px;white-space:pre">#!</span><span style="color:rgb(150,152,150);font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:12px;white-space:pre" class="">/usr/bin/env xcrun swift</span></div><div class=""><br class=""></div><div class="">Therefor it seems the basic building blocks for allowing a swift file to "execute itself" are always laid out and proved to be applicable.&nbsp;</div><div class=""><br class=""></div><div class="">What's missing IMHO is a better support for dependencies, the suggested solutions in the talk are using the -F for including frameworks that were built using Carthage or&nbsp;CocoaPods. That's not idle because a script I think should be self contained, meaning that you can "just run it" and it works.&nbsp;</div><div class=""><br class=""></div><div class="">So, I'm wondering what if it was possible to include the dependencies inside the swift file itself? Probably using the same format as the Package.swift syntax. The the swift binary would "detect" that it's a self contained file, it could make this distinction because&nbsp;<span style="font-family:'anonymous pro';font-size:11px;font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="">import</span><span style="font-family:'anonymous pro';font-size:11px;font-variant-ligatures:no-common-ligatures" class=""> PackageDescription&nbsp;</span>is defined by the user.</div><div class=""><span style="font-family:'anonymous pro';font-size:11px;font-variant-ligatures:no-common-ligatures" class=""><br class=""></span></div><div class="">Then it would follow a 3 step process:</div><div class="">1. It should download and build the dependencies</div><div class="">2. then compile the code inside the file</div><div class="">3. and then run it.&nbsp;</div><div class=""><br class=""></div><div class="">Having everything happening behind the scenes, so the "script user" simply calls <font face="monospace" class="">./MyScript.swift</font> or <font face="monospace" class="">swift MyScript.swift</font> and it "just works".&nbsp;</div><div class=""><br class=""></div><div class="">Wondering what the community thinks.</div><div class=""><br class=""></div><div class="">[1]&nbsp;<a href="https://realm.io/news/swift-scripting/" class="">https://realm.io/news/swift-scripting/</a></div><div class="">[2]&nbsp;<a href="https://github.com/ayanonagon/talks/tree/master/2015-swiftsummit/2" class="">https://github.com/ayanonagon/talks/tree/master/2015-swiftsummit/2</a></div></div>
_______________________________________________<br class="">swift-build-dev mailing list<br class=""><a href="mailto:swift-build-dev@swift.org" class="">swift-build-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-build-dev<br class=""></div></blockquote></div><br class=""></div></div></body></html>