A Complete Guide to Swift Development on Linux | raywenderlich.com

In this tutorial you’ll discover everything you need to start developing Swift on Linux. You’ll learn about LLDB, using SourceKit-LSP, syntax highlighting and the power of autocomplete.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/8325890-a-complete-guide-to-swift-development-on-linux

Well it did not build. I have swift version 5.2.1. During the build I got the following message:

/home/bruce/sourcekit-lsp/.build/checkouts/indexstore-db/lib/Support/Concurrencyunknown type name ‘dispatch_queue_priority_t’; did you mean 'dispatch_queue_attr

@bmontegani Hmm, that’s odd. Could you share some more info? Like the exact swift version from swift --version, your OS version, what command gave this error and the full stack trace?

That way we can better help figuring out what went wrong. Thanks! :]

@bmontegani you can try

swift build -Xcxx -I${HOME}/bin/swift-5.2.2-RELEASE-ubuntu18.04/usr/lib/swift -Xcxx -I${HOME}/bin/swift-5.2.2-RELEASE-ubuntu18.04/usr/lib/swift/Block

as stated in the official documentation of the project: sourcekit-lsp/Development.md at main · apple/sourcekit-lsp · GitHub

Thank You.
BTW… I have noticed that source kit-lsp recommends using the latest development release of Swift. Is this stable enough if I am only doing server side swift?

@mrlotu Can you please help with this when you get a chance? Thank you - much appreciated! :]

@bmontegani As per Swift’s website:

Development Snapshots are prebuilt binaries that are automatically created from mainline development branches. These snapshots are not official releases. They have gone through automated unit testing, but they have not gone through the full testing that is performed for official releases.

What this means is that you can use them just fine, but I would be careful with. running production code on the snapshots. Usually there isn’t much breaking with them, but they can contain more bugs than the main releases, including big crashes.

Hope this helps :]

Hey @mrlotu! Thanks a lot for the guide :slight_smile: I wonder, does watch variables works in VSCode (or at least where could I enter my po something)? Cheers

Hey @bpashch, awesome to hear you liked the article. When you hit a breakpoint in VSCode you will get access to the lldb console. It should pop up from the bottom or side of the screen. In there you can add watchpoints (see the LLDB docs on how) or use your normal p and po commands :slight_smile:

I am unsure if there are builtin GUI ways in VSCode to add watchpoints, I would suggest looking through the VSCode debugging documentation for this

Hope this helps! :]

Hey @mrlotu! Appreciate the response :slight_smile:

Finding that lldb window is something that I’m struggling with - could you please perhaps point me to it on my screenshot? Typing po anywhere does not seem to work :grimacing:

CheersScreenshot 2020-07-15 at 21.06.31

The lldb console is under the DEBUG CONSOLE tab (next to the currently selected Terminal tab).

Hope this helps! :]

@mrlotu I don’t seem to have luck with that one either :thinking:Screenshot 2020-07-15 at 21.23.47

also attaching my launch.json just in case…
Screenshot 2020-07-15 at 21.26.27

Doesn’t build on Ubuntu 20.04:
‘swift-nio-ssl-support’ openssl.pc: warning: couldn’t find pc file

Swift version 5.2.4 (swift-5.2.4-RELEASE)
Target: x86_64-unknown-linux-gnu

Any help much appreciated. Thanks

@kvyb is this perhaps somewhat related? Update to Swift 5.0.1 breaks builds on Ubuntu 18/04 · Issue #138 · apple/swift-docker · GitHub

@mrlotu is there any obvious problem you could probably point out on my screenshots above? Thanks

I run swift run and got this message at the end:

warning: dependency 'SQLite' is not used by any target
'swift-nio-ssl-support' openssl.pc: warning: couldn't find pc file
/home/dolar/Downloads/Compressed/Todos/Starter/.build/checkouts/swift-nio-ssl/Sources/CNIOOpenSSL/shims.c:16:
/home/dolar/Downloads/Compressed/Todos/Starter/.build/checkouts/swift-nio-ssl/So:17:10: fatal error: 'openssl/conf.h' file not found

         ^~~~~~~~~~~~~~~~
 generated.
[0/50] Compiling CNIOSHA1 c_nio_sha1.c

Then I run $ curl http://localhost:8080` and got this message:

curl: (7) Failed to connect to localhost port 8080: Connection refused

I am new to Ubuntu, But I was able to install swift succesfully by following the official link of swift.

Swift version 5.3.2 (swift-5.3.2-RELEASE)
Ubuntu 20.04.1 LTS