swift: [CMake 3.25+]: Swift 5.8: Fails to compile bootstrap1 modules

Description Ubuntu 23.04 + Swift 5.8: Fails to compile bootstrap1 modules due to possible module map issues with CXX interop

When compiling Swift from source with --bootstrapping=bootstrapping, compilation fails during generation of modules. Specifically on the Basic module.

Steps to reproduce

  1. Download Ubuntu 23.04, which is currently in beta but also in feature freeze so its ABI stable at this point.
  2. Install Swift dependencies as listed in the documentation
  3. Construct a swift source root by running: ./swift/utils/update-checkout --clone --tag swift-5.8-RELEASE
  4. Invoke the build-script as follows:
export SCCACHE_CACHE_SIZE="50G" && ./swift/utils/build-script -R --swift-install-components="autolink-driver;compiler;clang-resource-dir-symlink;stdlib;swift-remote-mirror;sdk-overlay;static-mirror-lib;toolchain-tools;license;sourcekit-inproc" --llvm-install-components="llvm-ar;llvm-cov;llvm-profdata;IndexStore;clang;clang-resource-headers;compiler-rt;clangd;lld;LTO;clang-features-file" --lldb --build-lld=1 --build-ninja=1 --llbuild=1 --libcxx=1 --swiftpm=1 --foundation=1 --libdispatch=1 --indexstore-db=1 --libicu=1 --install-swiftpm=1 --build-swift-static-stdlib --build-swift-static-sdk-overlay --install-llvm=1 --install-swift=1 --install-foundation --install-libdispatch --swiftdocc=1 -j=8 --sccache=1 --skip-test-linux=1 --skip-build-benchmarks --skip-early-swift-driver --skip-early-swiftsyntax --bootstrapping=bootstrapping --install-destdir=/home/jjones/swift-install

Expected behavior Bootstrap compilation should succeed, however a failure occurs when swiftc is invoked and has to deal with cxx-interop.

Build Failure

[1216/1439][ 84%][321.279s] Building swift module Basic
FAILED: bootstrapping1/SwiftCompilerSources/Basic.o /home/jjones/swift-source-root/build/Ninja-ReleaseAssert/swift-linux-x86_64/bootstrapping1/SwiftCompilerSources/Basic.o
cd /home/jjones/swift-source-root/swift/SwiftCompilerSources && /home/jjones/swift-source-root/build/Ninja-ReleaseAssert/swift-linux-x86_64/bootstrapping0/bin/swiftc -c -o /home/jjones/swift-source-root/build/Ninja-ReleaseAssert/swift-linux-x86_64/bootstrapping1/SwiftCompilerSources/Basic.o -I /home/jjones/swift-source-root/build/Ninja-ReleaseAssert/swift-linux-x86_64/bootstrapping0/bin/../lib -I /usr/lib -target x86_64-unknown-linux-gnu -module-name Basic -emit-module -emit-module-path /home/jjones/swift-source-root/build/Ninja-ReleaseAssert/swift-linux-x86_64/bootstrapping1/SwiftCompilerSources/Basic.swiftmodule -parse-as-library /home/jjones/swift-source-root/swift/SwiftCompilerSources/Sources/Basic/SourceLoc.swift /home/jjones/swift-source-root/swift/SwiftCompilerSources/Sources/Basic/Utils.swift -wmo -Xfrontend -validate-tbd-against-ir=none -Xfrontend -enable-experimental-cxx-interop -Xcc -UIBOutlet -Xcc -UIBAction -Xcc -UIBInspectable -Xfrontend -disable-implicit-string-processing-module-import -O -cross-module-optimization -Xcc -I -Xcc /home/jjones/swift-source-root/llvm-project/llvm/include -Xcc -I -Xcc /home/jjones/swift-source-root/build/Ninja-ReleaseAssert/llvm-linux-x86_64/include -Xcc -I -Xcc /home/jjones/swift-source-root/llvm-project/clang/include -Xcc -I -Xcc /home/jjones/swift-source-root/build/Ninja-ReleaseAssert/llvm-linux-x86_64/tools/clang/include -Xcc -I -Xcc /home/jjones/swift-source-root/swift/include -Xcc -I -Xcc /home/jjones/swift-source-root/build/Ninja-ReleaseAssert/swift-linux-x86_64/SwiftCompilerSources/../include -I /home/jjones/swift-source-root/build/Ninja-ReleaseAssert/swift-linux-x86_64/bootstrapping1/SwiftCompilerSources
<unknown>:0: warning: unable to perform implicit import of "_Concurrency" module: no such module found
/home/jjones/swift-source-root/swift/include/swift/AST/ClangModuleLoader.h:19:10: note: while building module 'Clang_AST' imported from /home/jjones/swift-source-root/swift/include/swift/AST/ClangModuleLoader.h:19:
#include "clang/AST/DeclTemplate.h"
         ^
/home/jjones/swift-source-root/llvm-project/clang/include/clang/AST/APValue.h:16:10: note: while building module 'Clang_Basic' imported from /home/jjones/swift-source-root/llvm-project/clang/include/clang/AST/APValue.h:16:
#include "clang/Basic/LLVM.h"
         ^
/home/jjones/swift-source-root/llvm-project/clang/include/clang/Basic/Sanitizers.h:20:10: note: while building module 'LLVM_Transforms' imported from /home/jjones/swift-source-root/llvm-project/clang/include/clang/Basic/Sanitizers.h:20:
#include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
         ^
/home/jjones/swift-source-root/llvm-project/llvm/include/llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h:20:10: note: while building module 'LLVM_intrinsic_gen' imported from /home/jjones/swift-source-root/llvm-project/llvm/include/llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h:20:
#include "llvm/IR/PassManager.h"
         ^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "IR/Argument.h"
         ^
/home/jjones/swift-source-root/llvm-project/llvm/include/llvm/IR/Argument.h:17:10: note: in file included from /home/jjones/swift-source-root/llvm-project/llvm/include/llvm/IR/Argument.h:17:
#include "llvm/IR/Attributes.h"
         ^
/home/jjones/swift-source-root/llvm-project/llvm/include/llvm/IR/Attributes.h:31:10: note: in file included from /home/jjones/swift-source-root/llvm-project/llvm/include/llvm/IR/Attributes.h:31:
#include <set>
         ^
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/set:60:10: note: in file included from /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/set:60:
#include <bits/stl_tree.h>
         ^
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_tree.h:2008:5: error: missing '#include "gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_pair.h"'; 'pair' must be declared before it is used
    pair<typename _Rb_tree<_Key, _Val, _KeyOfValue,
    ^
/usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_pair.h:185:12: note: declaration here is not visible
    struct pair

Environment

  • Swift compiler: swift-5.8-RELEASE
  • OS: Ubuntu 23.04

The full build-log is attached. swift_build_failure.txt

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 20 (15 by maintainers)

Commits related to this issue

Most upvoted comments

@compnerd FYI I also ran into this issue while building Swift on Exherbo using build-script

I can see there’s an open PR for Swift 5.9, I’ll try building the main branch then (which has been applied a fix).

Edit: I have CMake 3.25.1 installed by the way

After sleeping on it, I realized this is simply because LINUX was probably defined somewhere, and because an expression accepts variable|string, how that expression is interpreted depends on what ${sdk} expands to and whether that value happens to match an existing variable name.

As it turns out, CMake defines LINUX=1 as of 3.25: https://github.com/Kitware/CMake/commit/62cd3904bf22fd75a2502af09ef67f8458ce06e1

So the current way we write these expressions is a little ambiguous. Quoting seems to help, and ensures CMake treats it as a string. I do believe we have more broken checks like this; will create a PR.

@jaredjones, would you reopen this and add the CMake version info to the title? Once @stephank submits a fix, he can close it.

It looks like the modulemap is completely missing, and build.ninja doesn’t have any of the rules for it. So something about the way stdlib/public/Cxx/std/CMakeLists.txt is interpreted. I may have some more time to debug this tomorrow.

 #############################################
 # Utility command for libstdcxx-modulemap
 
-build stdlib/public/Cxx/std/libstdcxx-modulemap: phony stdlib/public/Cxx/std/CMakeFiles/libstdcxx-modulemap stdlib/public/Cxx/std/lib-swift-linux-x86_64-libstdcxx.h stdlib/public/Cxx/std/lib-swift-linux-x86_64-libstdcxx.modulemap
+build stdlib/public/Cxx/std/libstdcxx-modulemap: phony

For what it’s worth, I’m also seeing this exact error packaging Swift 5.8 in NixOS. CMake 3.24.3 works, while 3.25.3 doesn’t. (I’m not sure if it was already established this was a CMake >=3.25 issue. I wanted to narrow the range.)

I tried to diff the result of the configure step for LLVM between the two CMake versions, but nothing really stands out. (But I’m no expert.)