Building Swift on Kali Linux or System Requirements for Building Swift

Hello, I recently (yesterday) bought one of those old refurbished laptops to poke at Linux with, Kali in particular. I wanted to try hacking on the Swift compiler with it as well, and tried just following the Ubuntu directions since they’re both based on Debian. Everything went fine until the actual build command, which errored out after a while. On a hunch, I ran the exact same command again (utils/build-script —release-debug) and noticed that it got further before failing... well, 20-30 invocations of that command later, and it’s successfully built.

Now, this is an old refurb... a Lenovo T420 with only 4GB of RAM. I couldn’t help but notice that the system looked to be using all of that and nearly all of the swap right before the build command would throw an error and abort...

So, my question is could this be some weird problem stemming from following the build instructions for one platform (Ubuntu) on a similar not entirely the same platform (Kali), or is this like 99% probably the obvious “crashing because out of memory” and ninja just keeps picking up where it left off?

If it’s the later, how much RAM would I need to avoid this problem? I mean, I know it’ll never build fast, but I’d like it to build unattended if possible. Or is there a way to tell ninja that if a file fails to compile because of some certain error then it should just try again with 1 fewer threads (and I guess not actually fail completely unless that number gets to 0)?

I definitely remember running out of ram when linking with 4 threads on a laptop with 8GB ram so I think that's a pretty likely cause

Linking (which uses the most ram) generally happens near the end of the build, so you could try putting two invocations of ninja, the second one with 1 thread, into your shell separated by a semicolon (so the failure of the first doesn't stop the second from running)

1 Like

K, thanks. I’ll look into that.

Instead of doing this manually, you can control the number of concurrent link jobs independently by setting -DLLVM_PARALLEL_LINK_JOBS=1 (or some higher number, if you think you have enough RAM) in your cmake command.

If you're not already, make sure you're using gold instead of GNU ld as well. (lld works more efficiently than either of them, but is less mature, though many people have used it to build LLVM and Swift successfully too.)

2 Likes