<div>One issue with compiling the dependencies is that script startup would be slow. Maybe there should be a per-user or system level cache? System level is better from a disk usage perspective but some thought must be given to security.</div><div><br></div><div>With Ruby and Python, it is not expected that a script's dependencies are installed when it is run but rather they have already been installed via the package manager, although it does seem useful for single files to contain all the relevant information.</div><div><br></div><div>Here is another idea: a Swift script can be run from a project directory with Sources/, Packages/, &c. In that environment, build products are already cached. If the script is symlinked into /usr/local/bin/ it will be on the path but xcrun will still be able to find the project. It is kind of like a source-level .app bundle.</div><div><br><div class="gmail_quote"><div>Maxim Veksler via swift-build-dev <<a href="mailto:swift-build-dev@swift.org">swift-build-dev@swift.org</a>> schrieb am Sa. 18. Feb. 2017 um 11:28:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_msg">Hi,<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Ayaka Nonaka gave a talk[1] about basic scripting[2] support in Swift. <br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The gist of the idea is to use <span class="m_-2980347140651383944inbox-pl-c gmail_msg" 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-wrap">#!</span><span style="color:rgb(150,152,150);font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:12px;white-space:pre-wrap" class="gmail_msg">/usr/bin/env xcrun swift</span></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Therefor it seems the basic building blocks for allowing a swift file to "execute itself" are always laid out and proved to be applicable. </div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">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 CocoaPods. That's not idle because a script I think should be self contained, meaning that you can "just run it" and it works. </div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">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 <span style="font-family:'anonymous pro';font-size:11px;font-variant-ligatures:no-common-ligatures;color:rgb(4,51,255)" class="gmail_msg">import</span><span style="font-family:'anonymous pro';font-size:11px;font-variant-ligatures:no-common-ligatures" class="gmail_msg"> PackageDescription </span>is defined by the user.</div><div class="gmail_msg"><span style="font-family:'anonymous pro';font-size:11px;font-variant-ligatures:no-common-ligatures" class="gmail_msg"><br class="gmail_msg"></span></div><div class="gmail_msg">Then it would follow a 3 step process:</div><div class="gmail_msg">1. It should download and build the dependencies</div><div class="gmail_msg">2. then compile the code inside the file</div><div class="gmail_msg">3. and then run it. </div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Having everything happening behind the scenes, so the "script user" simply calls <font face="monospace" class="gmail_msg">./MyScript.swift</font> or <font face="monospace" class="gmail_msg">swift MyScript.swift</font> and it "just works". </div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Wondering what the community thinks.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">[1] <a href="https://realm.io/news/swift-scripting/" class="gmail_msg" target="_blank">https://realm.io/news/swift-scripting/</a></div><div class="gmail_msg">[2] <a href="https://github.com/ayanonagon/talks/tree/master/2015-swiftsummit/2" class="gmail_msg" target="_blank">https://github.com/ayanonagon/talks/tree/master/2015-swiftsummit/2</a></div></div>
_______________________________________________<br class="gmail_msg">
swift-build-dev mailing list<br class="gmail_msg">
<a href="mailto:swift-build-dev@swift.org" class="gmail_msg" target="_blank">swift-build-dev@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-build-dev" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-build-dev</a><br class="gmail_msg">
</blockquote></div></div>