Swift 5.10.1 for Gentoo on GURU

Hi folks! To anyone out there using Gentoo (there are dozens of us!), you might be interested to know that Swift 5.10.1 is now available for installation as an unofficial package via GURU. If you're not aware, GURU is the official repository for unofficial packages, following the standard package manager build and installation process. Project:GURU/Information for End Users - Gentoo wiki has more information, but tl;dr:

  1. eselect repository enable guru to add the GURU repo for packages through emerge
  2. emerge --sync guru to sync
  3. emerge --ask dev-lang/swift

Again, this is an unofficial package, not supported by either the Swift project or the Gentoo developers; I put this together for my own use and figured it might be helpful to others. If you run into trouble installing or running, please let me know and I'll do my best to help.

More Info
  • This is a prebuilt binary distribution using the official swift-5.10.1-RELEASE-fedora39.tar.gz tarball:
    • Although Gentoo is a very build-from-source-locally-focused distro, I went with the prebuilt binaries because:
      1. I can't for the life of me get either release/5.10.1 or release/6.0 to build on my machine (with all of the required dependencies installed, with the same build presets as the Linux buildbots); I plan on following up on this when I have the time so I can explore what it might take to get source builds going
      2. Building Swift from source can be somewhat painful for end-users, and the process differs from what Gentoo users might expect:
        • Swift optimizes for building self-contained toolchains: the way that Swift is built optimizes for having potentially multiple isolated versions of Swift installed simultaneously — great for most end-users, but somewhat painful for building because it bundles its own copies of LLVM, Clang, LLDB, ICU, etc. Not only does this mean that building a release from source requires building each of these projects, the built result can't be installed in a non-isolated way because the toolchain contains files which would conflict with existing system dependencies (e.g., a typical Gentoo system already has LLVM, Clang, LLDB, ICU, and more). This approach lends itself well to "download a built toolchain and point your $PATH at it", but this is very different from the typical Gentoo process, which would have the installation be system-wide, and depend on already-installed system dependencies
        • There is no single tarball containing all Swift sources for a release: this is more of a minor pain point, but it's a bit difficult to actually get all of the Swift source code needed for a build downloaded in one go. In order to get all of a release's dependencies, you either need to fetch the swiftlang/swift source for a release, then run update-checkout --clone to get the dependencies (which even with the flags to skip tags + history takes many, many minutes on my machine), or maintain a list of tarballs to fetch containing sources directly. The latter makes more sense, but the mapping from Swift release ↔︎ dependency versions feels better maintained in some "official" way than copied into the Gentoo ebuild
    • I chose the Fedora package because its required dependencies very closely match what can be found or installed on an up-to-date Gentoo system
  • Because this is a self-contained toolchain, it can't be splatted onto the filesystem in the usual locations; instead, it installs into /usr/lib64/swift-<version>, with swift, swift-*, and sourcekit_lsp symlinked into /usr/bin
    • Theoretically, if the tools are symlinked as /usr/bin/swift-*-<version>, you could have multiple Swift versions installed simultaneously in various slots. I didn't know whether anyone would find this actually useful, but this is possible to adjust in the future. (I'm not sure whether there's an existing USE flag we could use to say "please build this versioned", but theoretically we can add a package-local one. I figured being able to just run swift as opposed to swift-5.10.1 would be more useful)
  • Because I'm relying on the prebuilt Fedora toolchain and there aren't yet any 6.0 builds, only 5.10.1 is available at the moment; when 6.0 Fedora toolchains are available, I can add that too
  • Ideally, it'd be interesting to explore contributing to swiftlang/swift-installer-scripts to better spin up infrastructure for producing better builds tailored for Gentoo, but I'm not sure whether there'd be enough demand to actually justify the infrastructure (and hosting), so for now, I'm happy to piggyback off of existing work

If you have any comments, questions, suggestions, or more, I'd be happy to hear them!

9 Likes