Compiling Swift with statically linked standard library on Linux

I've been trying to compile a command line application I wrote, inside the official Swift docker container. However, when I run swift build -v --static-swift-stdlib -c release, I get the following:

lsb_release -r
/usr/bin/swiftc --driver-mode=swift -L /usr/lib/swift/pm/4_2 -lPackageDescription -swift-version 5 -I /usr/lib/swift/pm/4_2 -sdk / /code/Package.swift -fileno 7
/usr/bin/swiftc -module-name tree2latex -incremental -emit-dependencies -emit-module -emit-module-path /code/.build/x86_64-unknown-linux/release/tree2latex.swiftmodule -output-file-map /code/.build/x86_64-unknown-linux/release/ -whole-module-optimization -num-threads 2 -c /code/Sources/tree2latex/Tree.swift /code/Sources/tree2latex/helpers.swift /code/Sources/tree2latex/main.swift /code/Sources/tree2latex/template.swift -I /code/.build/x86_64-unknown-linux/release -target x86_64-unknown-linux -swift-version 5 -sdk / -O -j2 -DSWIFT_PACKAGE -module-cache-path /code/.build/x86_64-unknown-linux/release/ModuleCache -Xfrontend -color-diagnostics
/usr/bin/swiftc -sdk / -L /code/.build/x86_64-unknown-linux/release -o /code/.build/x86_64-unknown-linux/release/tree2latex -module-name tree2latex -emit-executable -Xlinker '-rpath=$ORIGIN' @/code/.build/x86_64-unknown-linux/release/tree2latex.product/Objects.LinkFileList

Upon further inspection, ldd shows that, indeed, the binary is not statically linked:

[...] => /usr/lib/swift/linux/ (0x00007f6d242b3000) => /usr/lib/swift/linux/ (0x00007f6d23979000) => /usr/lib/swift/linux/ (0x00007f6d249de000) => /lib/x86_64-linux-gnu/

Shouldn't the swiftc command have an -static-stdlib option when running swift build or am I missing something?

Thank you!

1 Like

It doesn't work on Linux right now:

1 Like

Thank you for pointing me to the bug report! I had not seen that one.

Terms of Service

Privacy Policy

Cookie Policy