# \[GSoC 2021\] Scripting in Swift

**URL:** <https://forums.swift.org/t/gsoc-2021-scripting-in-swift/45511>\
**Category:** Package Manager\
**Tags:** gsoc-2021\
**Created:** [March 10, 2021, 1:54am UTC](https://forums.swift.org/t/gsoc-2021-scripting-in-swift/45511 "2021-03-10T01:54:01Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevapple](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stevapple/32/31979_2.png) [@stevapple](https://forums.swift.org/u/stevapple)\
**Post date:** [March 10, 2021, 1:54am UTC](https://forums.swift.org/t/gsoc-2021-scripting-in-swift/45511/1 "2021-03-10T01:54:01Z")

</div>

Hello! I’m YR Chen from University of Science and Technology of China, majoring in Computer Science. I’ve been using Swift for a long time (mostly in server side) and starting last year I began to contribute codes to Swift and other projects. My works include a simple [Swift toolchain management script for Linux](https://github.com/stevapple/swiftbox), and [a forked version of `swift-aws-lambda-runtime`](https://github.com/stevapple/swift-tencent-scf-runtime) for Tencent SCF. I’m also implementing [Windows support for `swift-driver`](https://github.com/apple/swift-driver/pull/419) now.

I’m very interested in the project idea of adding SwiftPM support in Swift scripts. I’ve kept tracking on the [SwiftPM support for Swift scripts](https://forums.swift.org/t/swiftpm-support-for-swift-scripts/33126) thread since nearly a year ago (and also [left a comment](https://forums.swift.org/t/swiftpm-support-for-swift-scripts/33126/77) lol), and I’m really excited that it’s going to be picked up. Here’s my plan for making it an official evolution proposal:

- Draft a proposal based on the original one, and discuss with community members on the API design and working structure;
- Integrate SwiftPM support for scripts in SwiftDriver;
- Linux and macOS are the first target platforms for this proposal;
- Before the proposal is accepted, this feature will be available behind a flag;
- If possible, it should also be integrated into Swift REPL and SourceKit.

Currently, I plan to add the package parsing ability to Swift’s parser. SwiftDriver retrieves the package information from the frontend, and then hands it over to SwiftPM. SwiftPM will gain the ability of caching the build (and probably the script itself) and managing the cache. What do you think about this idea? @abertelrud @tomerd

---

<div class="post-metadata">

**Author:** ![ktoso](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ktoso/32/44526_2.png) [@ktoso](https://forums.swift.org/u/ktoso)\
**Post date:** [March 10, 2021, 2:22am UTC](https://forums.swift.org/t/gsoc-2021-scripting-in-swift/45511/2 "2021-03-10T02:22:46Z")

</div>

Also @NeoNacho 🙂

---

<div class="post-metadata">

**Author:** ![Michael\_Ilseman](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/michael_ilseman/32/44640_2.png) [@Michael\_Ilseman](https://forums.swift.org/u/Michael_Ilseman)\
**Post date:** [March 10, 2021, 2:49am UTC](https://forums.swift.org/t/gsoc-2021-scripting-in-swift/45511/3 "2021-03-10T02:49:32Z")

</div>

This is a very exciting feature and much needed. Good luck!

---

<div class="post-metadata">

**Author:** ![stevapple](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stevapple/32/31979_2.png) [@stevapple](https://forums.swift.org/u/stevapple)\
**Post date:** [March 10, 2021, 2:53am UTC](https://forums.swift.org/t/gsoc-2021-scripting-in-swift/45511/4 "2021-03-10T02:53:39Z")

</div>

Thank you! I just failed to find his ID 😢

---

<div class="post-metadata">

**Author:** ![stevapple](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stevapple/32/31979_2.png) [@stevapple](https://forums.swift.org/u/stevapple)\
**Post date:** [March 10, 2021, 2:55am UTC](https://forums.swift.org/t/gsoc-2021-scripting-in-swift/45511/5 "2021-03-10T02:55:46Z")

</div>

I'm looking forward to it too! Really excited and honored if I can participate.

---

<div class="post-metadata">

**Author:** ![tomerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tomerd/32/3402_2.png) [@tomerd](https://forums.swift.org/u/tomerd)\
**Post date:** [March 11, 2021, 3:57am UTC](https://forums.swift.org/t/gsoc-2021-scripting-in-swift/45511/6 "2021-03-11T03:57:43Z")

</div>

thank you @stevapple for reaching out, getting a proposal out to discuss the design would be a great step forward, looking forward to see what you come up with -- this would be a great addition to the Swift ecosystem

---

<div class="post-metadata">

**Author:** ![stevapple](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stevapple/32/31979_2.png) [@stevapple](https://forums.swift.org/u/stevapple)\
**Post date:** [March 12, 2021, 12:57am UTC](https://forums.swift.org/t/gsoc-2021-scripting-in-swift/45511/7 "2021-03-12T00:57:02Z")

</div>

I’ll try it out. Thanks for your instruction!

---

<div class="post-metadata">

**Author:** ![tomerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tomerd/32/3402_2.png) [@tomerd](https://forums.swift.org/u/tomerd)\
**Post date:** [March 12, 2021, 3:18am UTC](https://forums.swift.org/t/gsoc-2021-scripting-in-swift/45511/8 "2021-03-12T03:18:43Z")

</div>

A good approach is to write a more light-weight version of the proposal and pitch that, then develop it to a full proposal with sample implementation once the pitch converges

---

<div class="post-metadata">

**Author:** ![stevapple](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stevapple/32/31979_2.png) [@stevapple](https://forums.swift.org/u/stevapple)\
**Post date:** [March 19, 2021, 10:32am UTC](https://forums.swift.org/t/gsoc-2021-scripting-in-swift/45511/9 "2021-03-19T10:32:55Z")

</div>

[The revised proposal](https://forums.swift.org/t/pitch-swiftpm-support-for-swift-scripts-revision/46717) is finally posted to the forum! Here are a few highlights for the new parts:

- The new `swift-script` tool for managing scripts and caches;
- Design details on how a script is built and run;
- Some alternative designs.

Welcome to check it out! @abertelrud @NeoNacho @tomerd

---

<div class="post-metadata">

**Author:** ![stevapple](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stevapple/32/31979_2.png) [@stevapple](https://forums.swift.org/u/stevapple)\
**Post date:** [March 19, 2021, 5:20pm UTC](https://forums.swift.org/t/gsoc-2021-scripting-in-swift/45511/10 "2021-03-19T17:20:45Z")

</div>

I’d like to make it clear here that I’m not going to implement the whole proposal during GSoC.

I plan to work out a suitable working logic and implement the key function (`swift script run`, I suppose) as for the GSoC proposal. The current SE proposal is only a draft that provides more details than the original one, and hopefully it will be improved and finalized though community discussions (and the GSoC practice) over time.

P.S. Forgive my awkward English 😂

---

<div class="post-metadata">

**Author:** ![tomerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tomerd/32/3402_2.png) [@tomerd](https://forums.swift.org/u/tomerd)\
**Post date:** [March 19, 2021, 5:43pm UTC](https://forums.swift.org/t/gsoc-2021-scripting-in-swift/45511/11 "2021-03-19T17:43:05Z")

</div>

Having a fully fledged proposal that can be implemented in multiple steps make total sense. The design should allow for such steps, making sure that we can build something useful, even if small, as part of the GSoC project

---

<div class="post-metadata">

**Author:** ![stevapple](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stevapple/32/31979_2.png) [@stevapple](https://forums.swift.org/u/stevapple)\
**Post date:** [March 19, 2021, 5:59pm UTC](https://forums.swift.org/t/gsoc-2021-scripting-in-swift/45511/12 "2021-03-19T17:59:39Z")

</div>

I think the basic `swift-script run <file>` demo will meet the GSoC requirements. For the current proposal, this involves parsing the attributes, dumping the results into a JSON file (frontend), searching the cache, resolving the dependencies, building and running the code (SwiftPM).

Based on a successful demonstration, we can then implement the `swift-script` toolset (breaking into multiple parts), and finally other integrations.

---

<div class="post-metadata">

**Author:** ![stevapple](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stevapple/32/31979_2.png) [@stevapple](https://forums.swift.org/u/stevapple)\
**Post date:** [April 9, 2021, 4:40pm UTC](https://forums.swift.org/t/gsoc-2021-scripting-in-swift/45511/13 "2021-04-09T16:40:11Z")

</div>

Update on GSoC goals:

> The goal for GSoC is some kind of proof-of-concept and is expected to be the foundation of a full implementation of this feature. The outcome is expected to be a prototype of the new `swift-script` tool, which has a limited set of basic operations implemented like `run` and `reset`. There will also be a new flag for Swift Driver which enables a shortcut to the feature through `swift` command.

Really excited to participate!
