Building on Linux from release tarball

Hello,

I am trying to build Swift packages for openSUSE, from scratch. There are a few constraints to this which are causing me issues.

  1. I want to build from the release tarball.
  2. I want to use the packaged tools, rather than build all of LLVM, CMake, etc.

I thought I could tell build-script that I wanted hosttools with --bootstrapping=hosttools, but it fails looking for CMake sources. So I specify --cmake=/usr/bin/cmake and it's failing on trying to find CMake sources.

I do have cmake installed: cmake version 3.31.3

Build output:

[   11s] + utils/build-script --cmake=/usr/bin/cmake --release-debuginfo --bootstrapping=hosttools
[   11s] [utils/build-script] NOTE: Using toolchain default
[   11s] + /usr/bin/cmake --version
[   11s] --- Build Script Analyzer ---
[   11s] Skip build script analyzer
[   11s] .build_script_log file not found at /home/abuild/rpmbuild/BUILD/swift-swift-6.0.3-RELEASE/build/.build_script_log
[   11s] Traceback (most recent call last):
[   11s]   File "/home/abuild/rpmbuild/BUILD/swift-swift-6.0.3-RELEASE/utils/build-script", line 815, in <module>
[   11s]     exit_code = main()
[   11s]                 ^^^^^^
[   11s]   File "/home/abuild/rpmbuild/BUILD/swift-swift-6.0.3-RELEASE/utils/build-script", line 810, in main
[   11s]     return main_normal()
[   11s]            ^^^^^^^^^^^^^
[   11s]   File "/home/abuild/rpmbuild/BUILD/swift-swift-6.0.3-RELEASE/utils/build-script", line 700, in main_normal
[   11s]     cmake_path = cmake.check_cmake_version(SWIFT_SOURCE_ROOT, SWIFT_BUILD_ROOT)
[   11s]                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[   11s]   File "/home/abuild/rpmbuild/BUILD/swift-swift-6.0.3-RELEASE/utils/swift_build_support/swift_build_support/cmake.py", line 309, in check_cmake_version
[   11s]     if installed_ver >= self.cmake_source_version(cmake_source_dir):
[   11s]                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[   11s]   File "/home/abuild/rpmbuild/BUILD/swift-swift-6.0.3-RELEASE/utils/swift_build_support/swift_build_support/cmake.py", line 240, in cmake_source_version
[   11s]     file = open(cmake_version_file, "r")
[   11s]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[   11s] FileNotFoundError: [Errno 2] No such file or directory: '/home/abuild/rpmbuild/BUILD/swift-swift-6.0.3-RELEASE/cmake/Source/CMakeVersion.cmake'
[   11s] error: Bad exit status from /var/tmp/rpm-tmp.uaZ4mL (%build)

To build Swift you also need a bunch of other repos as well- not just the swift tarball. You can get the sources by doing:

./utils/update-checkout --clone --tag swift-6.0.3-RELEASE

Note that this build-script command will only build the compiler and stdlib, not the core libraries like Foundation and certainly not the package manager. For that, you will want to invoke a linux build preset, like the official Fedora build does (you can still patch the preset, as they do).

If using your build-script command above, it should use the CMake and other tools in your PATH: there's no reason to add those cmake/bootstrapping flags. You will also want to download and add a prebuilt Swift toolchain to your PATH: another OpenSUSE user reported that the prebuilt AL2 toolchain worked for that.

If you use the preset, you may want to patch out the flag where it tries to build CMake from source first.

Note that you have no choice but to build LLVM, as the Swift version of LLVM adds some patches to upstream. However, you can swap in your own prebuilt clang to build various parts of the Swift toolchain after the Swift compiler and lightly-modified clang have been built, if you really want to do that.

Feel free to open an issue on the compiler repo and ping me, if you plan to put together a Swift toolchain package for OpenSUSE and run into build problems. I maintain a Swift toolchain package myself and have probably seen a lot of the same issues you may run into. :wink:

Yes, Jesse's right, see the doc on getting started.