Installing Swift on Virtual Server with Ubuntu 18.04

I got a virtual server with Ubuntu 18.04 and followed the installation instruction on the Download page. Swift REPL works fine, I can also compile Swift code with swiftc main.swift, for example. But when I run swift build in a package folder (or anywhere else):

$ swift build
error: toolchain is invalid: could not find the `swiftc` at expected path /home/pbouda/swift/usr/bin/swiftc

The swiftc command is definitely in this location and I can use it to compile single files. I tried Swift 5.1 and 5.1.1. What could go wrong here? Can I debug this further somehow?

Check system calls by strace. Is there something like statx ... = -1 ENOSYS (Function not implemented)?

Yes, the line is:

statx(AT_FDCWD, "/home/pbouda/swift/usr/bin/swift", AT_STATX_SYNC_AS_STAT|AT_SYMLINK_NOFOLLOW, STATX_ALL, 0x7fffa84a0020) = -1 ENOSYS (Function not implemented)

Can I do something about this?

Which kernel version are you using (uname -a) as statx should be supported on Ubuntu18.04. I did a quick strace of a package build on Ubuntu18.04 and see statx working:

1353 statx(AT_FDCWD, "/tmp/t/Package.swift", AT_STATX_SYNC_AS_STAT|AT_SYMLINK_NOFOLLOW, STATX_ALL, {stx_mask=STATX_ALL, stx_attributes=0, stx_mode=S_IFREG|0664, stx_size=763, ...}) = 0

uname -a shows:

Linux 4.15.0 #1 SMP Thu Jun 27 15:10:55 MSK 2019 x86_64 x86_64 x86_64 GNU/Linux

Might it be related to the virtualization? I found that seccomp might be a problem with containers that run code that calls statx, statx was added at some point:

Maybe an outdated seccomp on the system that runs my virtual server?

That could be the issue. The kernel version looks fine since statx was added in 4.11. I don't know about libseccomp, Im running under VMware Fusion but don't normally have any restrictions like that.

What VM are you running Linux under? As you say it might just be a case of updating to the latest version, possibly an apt-get update , apt-get upgrade could fix it?

Yeah. That's it. I believe your hoster modified kernel and removed statx function. The fix for this will probably be to patch Foundation framework by excluding statx and restoring old stat call. Of course, we can notify our providers but I don't think they will change something.

There was already a mechanism to fallback to lstat() if statx() returned EPERM, I have done a PR to update it to include ENOSYS. This was originally added due to libseccomp so maybe the return errno for blocked system calls was changed from EPERM to ENOSYS.

Nice, hope that it will be merged soon! I tried to contact my hoster, but they did not really understand the problem, and there is no simple way to have a communication with them. I don’t think they will update anything.

This has been merged now so you should be able to test it in the latest development snapshot

1 Like

Just tried, and swift build works now. Thanks a lot! :grin:

Terms of Service

Privacy Policy

Cookie Policy