Swift is regularly built successfully on stable versions of Ubuntu, as you can see from CI logs:
To replicate builds off main locally:
- Make sure you have everything checked out in sync with
update-checkoutfrom themainscheme. Frequently, when you keep updating only a single repository but not other repositories, they go out of sync due to breaking API changes. - Make sure you have all of the dependencies installed, the exact list of dependencies for building the toolchain is available in the
swift-cidirectory inDockerfilescorresponding to the distribution you're building on, for example here's one for Ubuntu 22.04 swift-docker/swift-ci/main/ubuntu/22.04/Dockerfile at main · swiftlang/swift-docker · GitHub. - Make sure you have enough RAM available for the build process, some linker jobs may need 16 GB or more for large binaries.
- Build with the exactly same preset and exactly the same invocation of
build-scriptas on CI. For example, on Linux the invocation that produces toolchain distributions ready for installation is this one
./swift/utils/build-script --preset buildbot_linux install_destdir=/home/build-user/swift-nightly-install installable_package=/home/build-user/swift-DEVELOPMENT-SNAPSHOT-2025-04-06-a-ubuntu2204.tar.gz'
- Lastly, if you have any trouble replicating the build in your environment, you can use the CI
DockerfileI linked above and build everything in a container to replicate the CI environment as closely as possible.