Failed to compile Swift on Amazon Linux 2023

I am trying to compile Swift 5.7 on Amazon Linux 2023.

It fails with an error message I don't understand. Any suggestions ?

Note: I disabled LTO optimization as explained here

[4420/4431][ 99%][1226.176s] cd /root/rpmbuild/BUILD/swift-source/build/buildbot_linux/llvm-linux-aarch64/tools/clang/runtime/compiler-rt-bins && /root/rpmbuild/BUILD/swift-source/build/cmake-linux-aarch64/bin/cmake -DCMAKE_C_COMPILER=/root/rpmbuild/BUILD/swift-source/build/buildbot_linux/llvm-linux-aarch64/./bin/clang -DCMAKE_CXX_COMPILER=/root/rpmbuild/BUILD/swift-source/build/buildbot_linux/llvm-linux-aarch64/./bin/clang++ -DCMAKE_ASM_COMPILER=/root/rpmbuild/BUILD/swift-source/build/buildbot_linux/llvm-linux-aarch64/./bin/clang -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=/root/rpmbuild/BUILD/swift-source/build/buildbot_linux/ninja-build/ninja -DLLVM_CONFIG_PATH=/root/rpmbuild/BUILD/swift-source/build/buildbot_linux/llvm-linux-aarch64/./bin/llvm-config "-DLLVM_LIT_ARGS=-v --time-tests -j 16" -DCOMPILER_RT_OUTPUT_DIR=/root/rpmbuild/BUILD/swift-source/build/buildbot_linux/llvm-linux-aarch64/./lib/clang/13.0.0 -DCOMPILER_RT_EXEC_OUTPUT_DIR=/root/rpmbuild/BUILD/swift-source/build/buildbot_linux/llvm-linux-aarch64/./bin -DCOMPILER_RT_INSTALL_PATH:PATH=lib/clang/13.0.0 -DCOMPILER_RT_INCLUDE_TESTS=ON -DCMAKE_INSTALL_PREFIX=/usr -DLLVM_LIBDIR_SUFFIX= -DLLVM_RUNTIME_OUTPUT_INTDIR=/root/rpmbuild/BUILD/swift-source/build/buildbot_linux/llvm-linux-aarch64/./bin -DCMAKE_OSX_DEPLOYMENT_TARGET= -DCMAKE_OSX_SYSROOT:PATH= -DCOMPILER_RT_INTERCEPT_LIBDISPATCH=ON -DCOMPILER_RT_PREFIX=/root/rpmbuild/BUILD/swift-source/build/buildbot_linux/llvm-linux-aarch64/projects/compiler-rt -DCOMPILER_RT_SRC_ROOT=/root/rpmbuild/BUILD/swift-source/llvm-project/llvm/../compiler-rt -GNinja /root/rpmbuild/BUILD/swift-source/llvm-project/llvm/../compiler-rt && /root/rpmbuild/BUILD/swift-source/build/cmake-linux-aarch64/bin/cmake -E touch /root/rpmbuild/BUILD/swift-source/build/buildbot_linux/llvm-linux-aarch64/tools/clang/runtime/compiler-rt-stamps//compiler-rt-configure
Re-run cmake no build system arguments
-- The C compiler identification is Clang 13.0.0
-- The CXX compiler identification is Clang 13.0.0
-- The ASM compiler identification is Clang
-- Found assembler: /root/rpmbuild/BUILD/swift-source/build/buildbot_linux/llvm-linux-aarch64/./bin/clang
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /root/rpmbuild/BUILD/swift-source/build/buildbot_linux/llvm-linux-aarch64/./bin/clang
-- Check for working C compiler: /root/rpmbuild/BUILD/swift-source/build/buildbot_linux/llvm-linux-aarch64/./bin/clang - broken
CMake Error at /root/rpmbuild/BUILD/swift-source/cmake/Modules/CMakeTestCCompiler.cmake:66 (message):
  The C compiler

    "/root/rpmbuild/BUILD/swift-source/build/buildbot_linux/llvm-linux-aarch64/./bin/clang"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /root/rpmbuild/BUILD/swift-source/build/buildbot_linux/llvm-linux-aarch64/tools/clang/runtime/compiler-rt-bins/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/root/rpmbuild/BUILD/swift-source/build/buildbot_linux/ninja-build/ninja cmTC_c1705 && [1/2][ 50%][0.024s] Building C object CMakeFiles/cmTC_c1705.dir/testCCompiler.c.o
    clang-13: warning: argument unused during compilation: '-specs=/usr/lib/rpm/redhat/redhat-hardened-cc1' [-Wunused-command-line-argument]
    clang-13: warning: argument unused during compilation: '-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1' [-Wunused-command-line-argument]
    clang-13: warning: argument unused during compilation: '-fstack-clash-protection' [-Wunused-command-line-argument]
    [2/2][100%][0.046s] Linking C executable cmTC_c1705
    FAILED: cmTC_c1705 
    : && /root/rpmbuild/BUILD/swift-source/build/buildbot_linux/llvm-linux-aarch64/./bin/clang -O2 -ftree-vectorize  -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -march=armv8.2-a+crypto -mtune=neoverse-n1 -mbranch-protection=standard -fasynchronous-unwind-tables -fstack-clash-protection -Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -Wl,--build-id=sha1 -Wl,-dT,/root/rpmbuild/BUILD/swift-source/.package_note-swiftlang-5.7.3-1.amzn2023.aarch64.ld CMakeFiles/cmTC_c1705.dir/testCCompiler.c.o -o cmTC_c1705   && :
    clang-13: warning: argument unused during compilation: '-specs=/usr/lib/rpm/redhat/redhat-hardened-cc1' [-Wunused-command-line-argument]
    clang-13: warning: argument unused during compilation: '-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1' [-Wunused-command-line-argument]
    clang-13: warning: argument unused during compilation: '-mbranch-protection=standard' [-Wunused-command-line-argument]
    clang-13: warning: argument unused during compilation: '-specs=/usr/lib/rpm/redhat/redhat-hardened-ld' [-Wunused-command-line-argument]
    clang-13: warning: argument unused during compilation: '-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1' [-Wunused-command-line-argument]
    /usr/bin/ld: cannot find crtbegin.o: No such file or directory
    /usr/bin/ld: cannot find -lgcc: No such file or directory
    /usr/bin/ld: cannot find -lgcc_s: No such file or directory
    clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.

The Swift build tries to build LLVM first, including clang and compiler-rt, and that new clang is used to build compiler-rt.

CMake is complaining that it is unable to build a simple C executable with that new clang, as it cannot find the C runtime in your linux setup. Make sure you have all build dependencies linked from the Swift documentation for building on linux installed, and you can use that test command CMake is running to try and figure out what's going wrong, perhaps by adding -v to see what it's doing:

/root/rpmbuild/BUILD/swift-source/build/buildbot_linux/llvm-linux-aarch64/./bin/clang
-O2 -ftree-vectorize  -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong
-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -march=armv8.2-a+crypto -mtune=neoverse-n1 -mbranch-protection=standard
-fasynchronous-unwind-tables -fstack-clash-protection -Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld
-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -Wl,--build-id=sha1 -Wl,-dT,/root/rpmbuild/BUILD/swift-source/.package_note-swiftlang-5.7.3-1.amzn2023.aarch64.ld
CMakeFiles/cmTC_c1705.dir/testCCompiler.c.o -o cmTC_c1705

You could also look at the public logs of the Amazon Linux CI to see if they're doing something differently than you are. I recommend that you build Swift 5.8 instead, as that is the latest release.

What build-script invocation do you use to build? Most likely you need to use a preset to build it the same way that CI builds it:

./swift/utils/build-script --preset buildbot_linux,no_test \
    install_destdir=/home/build-user/swift-nightly-install \
    installable_package=/home/build-user/installable-swift.tar.gz

I am using the scripts provided here

Trying to adapt the one from Amazon Linux 2 to Amazon Linux 2023.