Distributing binaries for linuxes (static linking?)

Ohh, I see, it should be --swift-sdk, but the Swift.org - Getting Started with the Static Linux SDK page currently says just --sdk: the --sdk parameter is wrong on Linux, it doesn't compile the static binary, while the --swift-sdk compiles it under the x86_64-swift-linux-musl folder as expected!

Thank you for helping me figure this out! :slight_smile:

4 Likes

Drat! I'll have to get that fixed. It's very confusing because there is also an --sdk option, but it doesn't do what we want here, and you'll just get the wrong behaviour.

Thank-you for pointing this out.

2 Likes

Sure, it's FB13850220

1 Like

To elaborate on the segfault problem, this isn't actually a problem with the Static SDK for Linux โ€” it's an issue with the toolchain where it's trying to use libraries from the OS, but because of a problem with the OS hosted libraries we end up thinking that things are marked with the in-development availability (9999) are available when in fact in the OS libraries they are not.

This should be fixed already in the Sequoia (macOS 15) developer seed. There is a workaround here: SwiftPM built with Swift 6.0 and later snapshots crashes on macOS 14 ยท Issue #73327 ยท apple/swift ยท GitHub courtesy of @kateinoigakukun which I will reproduce below for convenience:

Step 1. Strip hardened runtime flag by replacing existing signature of toolchain binaries

PATH_TO_TOOLCHAIN=/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-05-15-a.xctoolchain
find $PATH_TO_TOOLCHAIN/usr/bin -type f | \
  while read line; do sudo codesign --force --preserve-metadata=identifier,entitlements --sign - $line; done

Step 2. Use toolchain binaries with DYLD_LIBRARY_PATH

DYLD_LIBRARY_PATH=$PATH_TO_TOOLCHAIN/usr/lib/swift/macosx $PATH_TO_TOOLCHAIN/usr/bin/swift-package --version
3 Likes

I don't know if you saw this, but your new Musl instructions page blew up on HN last week. I was surprised to see some very positive comments about the current direction of Swift posted there, if you avoid the long threads debating the merits of static linking. :smiley:

4 Likes

:-) Yes, I saw. Nice to see people getting enthusiastic about something I've been working on, and indeed about Swift itself.

1 Like

Sorry for the advertisement, but you can use Product | Archive for distribution menu command in Plain Swift. I simply cannot agree that Swift binaries are not portable.

You're replying to a post from five years ago. When he said that Swift binaries were not portable, he was correct in 2019. Obviously today static linking allows you to compile portable code, especially with the new Musl SDK.

Also, he was specifically talking about portability between different Linux distros.

1 Like

Oh, sorry for that. I was not in an adequate state at the time of replying.

1 Like