When building on a Linux system with libstdc++ higher than version 10 (the current version is 14, and Ubuntu Jammy ships 11) there is a cyclic dependency in the clang module graph for the standard library.
The check in <prefix>//lib/swift/linux/libstdcxx.h includes <execution> in c++17 or higher modes. With libstdc++-11-dev or higher and libtbb-dev, installed, this introduces a cyclic dependency between the _Builtin_intrinsics module and std.
Reproduction
With the following 3 files, the issue is easy to see with the official swift 6.0 snapshot docker containers:
After putting all these 4 files in one directory, the error can be reproduced with the following shell commands that launch a swift nightly docker container, and installs libtbb-dev.
Description
When building on a Linux system with libstdc++ higher than version 10 (the current version is 14, and Ubuntu Jammy ships 11) there is a cyclic dependency in the clang module graph for the standard library.
The check in
<prefix>//lib/swift/linux/libstdcxx.h
includes<execution>
in c++17 or higher modes. Withlibstdc++-11-dev
or higher andlibtbb-dev
, installed, this introduces a cyclic dependency between the_Builtin_intrinsics
module andstd
.Reproduction
With the following 3 files, the issue is easy to see with the official swift 6.0 snapshot docker containers:
Lib.h
module.modulemap
main.swift
After putting all these 4 files in one directory, the error can be reproduced with the following shell commands that launch a swift nightly docker container, and installs
libtbb-dev
.The error is as follows:
- error: cyclic dependency in module 'std': std -> _Builtin_intrinsics -> std
``` /workspace/Lib.h:1:10: note: while building module 'std' imported from /workspace/Lib.h:1: 1 | #includeRemoving the
-Xcc -std=c++17
causes the error to go away, because we are no longer trying to use tbb/executionExpected behavior
including any C++ standard library header in C++17, C++20, C++23 or C++26 mode should not error out the swift compiler.
The support for
<execution>
on Linux should either be removed or fixed for Swift 6.0.Note that this was not an issue in the Ubuntu 20.04 containers, because they only ship libstdc++-10-dev.
Environment
swiftc -version: Swift version 6.0-dev (LLVM d83ae228657c9e1, Swift 038299666d5d822) Target: x86_64-unknown-linux-gnu
docker image list: swiftlang/swift nightly-6.0-jammy dbdffe58b5a0 13 hours ago 3.51GB
Additional information
https://forums.swift.org/t/swift-5-9-release-on-ubuntu-22-04-fails-to-build-std-module/67659/4