I was able to successfully get the vapor/api-template's App target to successfully link in the Swift REPL which allows some really cool possibilities in the future for Vapor tooling. The steps I followed to get things working:
$ brew install libressl
$ git clone [email protected]:vapor/api-template.git
$ cd api-template
$ git checkout beta
I had to modify the api-template Package.swift to export a dynamic library that could then be linked into the REPL. To add the dynamic lib to the Package.swift I added these lines:
products: [
.library(name: "App", type: .dynamic, targets: ["App"]),
],
Then just needed to build things and start up the REPL
$ swift build
$ swift -I .build/debug -L .build/debug -lApp -L/usr/local/Cellar/libressl/lib -lssl -lcrypto -I/usr/local/Cellar/libressl/include
Welcome to Apple Swift version 4.1 (swiftlang-902.0.43 clang-902.0.37.1). Type :help for assistance.
1> @testable import App
2. import Service
3. import Vapor
4. import Foundation
5.
6. var config = Config.default()
7. var env = try Environment.detect()
8. var services = Services.default()
9.
10. try App.configure(&config, &env, &services)
11.
12. let app = try Application(
13. config: config,
14. environment: env,
15. services: services
16. )
17.
18. try App.boot(app)
19.
20. let conn = try app.requestConnection(to: .sqlite).wait()
21. defer { app.releaseConnection(conn, to: .sqlite) }
22. let todos = try Todo.query(on: conn).all().wait()
23.
24. print(todos)
Migrating sqlite DB
Migrations complete
[]
We could modify the api-template to make the REPL code simpler to setup which we should do
A few gotchas I found, the version number in the libressl link flags actually does need to be present? I think it was somehow cached for me but I had to start adding it. This might be something weird with my home-brew setup though. Also If you try to run each import as a single command the real doesn't keep that import available to future commands for some reason :( You have to copy paste the whole chunk of code you want to run all at once
@kdawgwilk you want to use the /opt/ folder I think:
-I/usr/local/opt/libressl/include -L/usr/local/opt/libressl/lib
Also ignore my comment on api-template, I see you posted all the goodies here. Tyvm :)
I'm closing this one in favour of https://github.com/vapor/toolbox/issues/256. I really like the sound of this, but think it'd be even nicer if we have it included in the toolbox! If you disagree, feel free to re-open :)
Most helpful comment
We could modify the
api-templateto make the REPL code simpler to setup which we should do