Swift.org Blog: REPL Support for Swift Packages


(Ankit Aggarwal) #1

Hi,

There is a new blog post titled REPL Support for Swift Packages on the Swift.org website. It discusses the new REPL support that was recently merged to SwiftPM.

Feel free to use this thread for any questions or discussions.


#2

Will this affect Xcode Playgrounds in any way? Maybe in future releases? Like drag & drop a SwiftPM package from the finder onto/ into a Playground to experiment with it there?


#3

swift run --repl provides the option to import targets, but what are your thoughts on automatically importing targets? Being able to run code before showing a prompt might also be a good option, and could yield some interesting tooling.


(Ankit Aggarwal) #4

Yeah, I was also thinking of a similar thing where we would pre-import the root package's targets. I'll try to discuss the possibilities with @Jim_Ingham soon.

What kind of scenarios are you thinking? Like boilerplate-y setup code?


#5

Specifically there was talk of setting up a vapor console similar to rails console where users could execute ORM queries and whatnot.

Something like:

$ vapor console
> Todo.query(on: conn).all()
[{id:1, title: "Wash The Dog"},{id:2, title:"take out the trash"}]
>

The details are a little fuzzy, but for that to work you'd need to import a few things (Fluent, Vapor, The app itself), run configurations, and retain a database connection (let conn = databaseConnection).

I'll --repl up and running so I can give you a more solid answer.

I'm sure folks would think of other uses too, but that's what I'm looking at right now.


#6

Any idea what might be going wrong here?

$ swift run --repl
Compile CYaml src/writer.c
Compile CYaml src/emitter.c
Compile CYaml src/scanner.c
Compile CYaml src/parser.c
Compile CYaml src/api.c
Compile CYaml src/reader.c
Compile Swift Module 'Yams' (16 sources)

Linking ./.build/x86_64-apple-macosx10.10/debug/libYams__REPL.dylib
ld: unexpected token: !tapi-tbd-v3 file '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd' for architecture x86_64

<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

$ swift -v
Apple Swift version 4.2-dev (LLVM aeaaca98ed, Clang 1ddef2249a, Swift 20bb815b62)
Target: x86_64-apple-darwin17.7.0
/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2018-10-03-a.xctoolchain/usr/bin/lldb "--repl=-enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics"

(Ankit Aggarwal) #7

Interesting. I can't really reproduce this but it most likely due to a difference in OS or Xcode installation. Can you try it with the latest Xcode beta? Also, please file a JIRA!


#8

https://bugs.swift.org/browse/SR-8946

Any other logs or info I can grab for you?


(Adrian Zubarev) #9

Might be a bunch of silly questions:

  • Is there a way to integrate REPL in to custom tooling?
  • Does REPL provide a way to observe it's output?

REPL support for SwiftPM looks almost like Xcode Playground without the UI layer.


(Shane Qi) #10

Isn't this feature included in Xcode 10.1 (swift 4.2.1)?

I updated my Xcode to 10.1 and tried to use this feature by swift run --repl, but got error: unknown option --repl; use --help to list available options

Bold:~ shane$ swift --version
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
Target: x86_64-apple-darwin18.2.0
Bold:~ shane$ swift package --version
Apple Swift Package Manager - Swift 4.2.0 (swiftpm-14460.2)


(Ankit Aggarwal) #11

Nope, this feature aligns with Swift 5 release.


(Shane Qi) #12

Got it, look forward to it. Thanks!