The current state of Swift for Server and Linux

I wanted to document how easy it is to set up a working swift environment. To give it the most chances, I used a brand new virtual machine with pristine ubuntu, so that there are no problems with old versions of programs, conflicting versions of programs, any hardware issues. Here's how it went:

  1. virutalbox said that install failed when I tried to run the VM the first time. I had to uninstall virutalbox and install it again.

  2. During Ubuntu installation I clicked cancel on the prompt warning me about my disk being overwritten. Disk formatting wouldn't work after that. I rebooted the VM, and it worked after that.

  3. apt search swift doesn't find swiftlang, let's go to the swift.org to download the toolchain there

  4. "Getting started" page has a section "Installing" with subsection "on linux". I assumed it contained instructions how to get started and install swift on linux. It doesn't. Instructions on how to install swift are on the "Download" page. :/ You have to read very carefully to notice that. (you can find scraps of the instructions here, but the complete version is on the Download page) SR-14565

  5. "Installation" section on "Download" page has two subsections number 1 (installing dependencies, and downloading the binary) SR-14566

  6. Why is Ubuntu 16.04 at the top of the list, even though it's older? I almost downloaded that one by accident. SR-14568

  7. Is there a difference between clicking on a "Toolchain" link and "Ubuntu 20.04"? No, they lead to the same url. Why are there two links if there is no difference? Very confusing, especially when for macos version it matters which one you click. SR-14569

  8. Verifying the signature went well! First step that I had no problems with!

  9. "This creates a usr/ directory in the location of the archive." It creates a directory named after the archive, not usr/ but that's just nitpicking SR-14570

  10. "You can now execute the swift command to run the REPL or build Swift projects." This doesn't mention anything about the fact that it will stop working after you close your terminal. It should tell you to add a command to your bashrc SR-14571

  11. Should there be a link to the Getting Started page at the end, to teach people how to use compiler, package manager and repl?

  12. I cannot see any mention of sourcekit-lsp. Let's assume that I know that such tool exists, and I can google the git repo.

  13. "Getting started" section in the README.md is very good. Short, informative, easily found. Good job!

  14. Installing vscode is easy. It has a big button for downloading .deb version on the front page, and it says that it's for Ubuntu.

  15. Why do I have to install the extension from source?:slightly_frowning_face: I don't want to install node and download git repos. I hope sourcekit-lsp won't hate me if I install npm from apt instead of downloading a tar from the website as it recommends.

-- slight intermission for resizing disk on virtual machine --

  1. I compiled and installed the extension without any problems, enabled it, and opened the sourcekit-lsp repository to test it. I got greeted by a giant wall of sourcekit-lsp errors after opening main.swift :/

  2. Maybe the problem is that I never executed swift build before opening the project? Let's try that. Should there be three empty lines and a single full stop in the output? It doesn't look normal. Let's ignore it. Hooray! I have working sourcekit-lsp now!

  3. ...except for the fact that there are errors on importing of some modules... for example "no such module 'SKCore'" in main.swift. Let's ignore that, and get ourselves a debugger.

  4. I'm going to install CodeLLDB because it seems to be popular? and let's make a new, simple project to test the debugger on.

  5. Enabling debugging is pretty easy. When you choose lldb as your debugger and try to start debugging, it prompts you to make a new configuration. It hints where you should type the path to your executable. Slightly annoying that you have to do that, but it works.

  6. Swift doesn't work perfectly with the default debugger. Instead of nice names in the call stack, you get mangled names full of numbers and dollar signs. I know that the solution is to use lldb that is bundled with the toolchain, but someone new might not know that.

  7. Settings page for that extension doesn't have anything that would help with changing the lldb binary. Thankfully CodeLLDB github page tells us the solution (use a special command) that explicitly mentions swift as the use case.

  8. CodeLLDB yells warnings like [2021-05-03T00:23:27.408Z ERROR codelldb::debug_session] name 'equal' is not defined when you hover over anything.

  9. Next day as I'm filing bug reports sourcekit-lsp stops compiling


Resolving https://github.com/apple/indexstore-db.git at main

:28:10: fatal error: 'sqlite3.h' file not found

#include <sqlite3.h>

         ^~~~~~~~~~~

-.- I give up. Swift tools are awful. It's a great language, but pain in the neck to set up on linux. The whole experience was infuriating, even though I did it many, many times already. Every time I find a new pain point. The only straightforward part of this whole ordeal was installing vscode, which is totally unrelated to swift project.

46 Likes