Installing Swift Runtime separately

I’m using Swift to build some small apps for my Raspberry Pi. It would be really nice if there was an option to install only the Swift libraries and runtime, instead of the entire toolchain with the compiler, package manager, and other development tools.

It still waste some space if you plan to use many apps, but I think you can static links your applications to not have to install the runtime on your Raspberry.

2 Likes

Another option is to build for Embedded Swift, which does not have a runtime component.

4 Likes
s_ver=6.1.2
s_file=swift-$s_ver-RELEASE-debian12

wget https://download.swift.org/swift-$s_ver-release/debian12/swift-$s_ver-RELEASE/$s_file.tar.gz
tar xf $s_file.tar.gz
rm -rf /usr/local/libexec/swift /usr/local/lib/swift
mkdir -p /usr/local/libexec/swift /usr/local/lib/swift
cp -R $s_file/usr/lib/swift/linux /usr/local/lib/swift/
cp -R $s_file/usr/libexec/swift/linux /usr/local/libexec/swift/
chmod -R o+r /usr/local/lib/swift /usr/local/libexec/swift

echo "/usr/local/lib/swift/linux" > /etc/ld.so.conf.d/swift-x86_64.conf
ldconfig

rm -rf $s_file $s_file.tar.gz

I use this script on Debian12

4 Likes

You can create statically linked applications that don't need anything installed to run: Getting Started with the Static Linux SDK | Swift.org

1 Like

If I have three Swift programs, it is a waste of space to statically link everything three times.

I think kojirou's solution is the best. Perhaps the basic libraries could be released on the Debian, Ubuntu, Fedora, Arch repositories... so that they can be installed and managed directly with the system’s package manager.

Yes, separating the runtime from the compiler is a desirable property. The Windows builds already does this. However, the reality is currently, the runtime is tied to the compiler - the runtime must match the compiler build precisely due to the lack of ABI stability. In the fullness of time this would be possible, but currently, this isn't entirely safe to do.

Keep in mind that Swift on Linux is not ABI stable, so you must compile all your applications with a compiler that matches exactly the version of the installed runtime.

By using static linking, you are not forced to recompile and redeploy all your applications at once when you upgrade your compiler, and runtime library.

And as the linker strips dead code, the increase in size is usually far less than the size of the runtime and base libraries. With only 3 applications, you may still use less space with static linking than what would be required to deploy the full set of Swift runtime and base libraries.