Cannot build toolchain on Ubuntu 24.04 LTS

When trying to build the toolchain for current main using swift/utils/build-toolchain and swift-5.10-RELEASE-ubuntu22.04 on Ubuntu 24.04 LTS, I get weird compilation errors:

/home/bastian/Documents/swift/swift-corelibs-foundation/Sources/Foundation/Port.swift:95:37: error: module 'Glibc' has no member named 'SOCK_STREAM'
  93 | #if canImport(Glibc) && !os(Android) && !os(OpenBSD)
  94 | import Glibc
  95 | fileprivate let SOCK_STREAM = Int32(Glibc.SOCK_STREAM.rawValue)
     |                                     `- error: module 'Glibc' has no member named 'SOCK_STREAM'
  96 | fileprivate let SOCK_DGRAM  = Int32(Glibc.SOCK_DGRAM.rawValue)
  97 | fileprivate let IPPROTO_TCP = Int32(Glibc.IPPROTO_TCP)

/home/bastian/Documents/swift/swift-corelibs-foundation/Sources/Foundation/Port.swift:96:37: error: module 'Glibc' has no member named 'SOCK_DGRAM'
  94 | import Glibc
  95 | fileprivate let SOCK_STREAM = Int32(Glibc.SOCK_STREAM.rawValue)
  96 | fileprivate let SOCK_DGRAM  = Int32(Glibc.SOCK_DGRAM.rawValue)
     |                                     `- error: module 'Glibc' has no member named 'SOCK_DGRAM'
  97 | fileprivate let IPPROTO_TCP = Int32(Glibc.IPPROTO_TCP)
  98 | #endif

I checked that all dependencies are installed, and also couldn't find anything related to it here, on GitHub, or elsewhere.

Does anyone know how to resolve this?

We're aware of the issue with the main and 6.0 compilers. Unfortunately, I don't have a workaround or fix yet.

@futurejones, you have 5.9 and 5.10 building for 24.04, any idea about this Swift 6 issue?

We have official images for 5.10 on 24.04. Something changed in both the clang importer, and the glibc header layout that is causing swift (main and 6.0) to import SOCK_DGRAM and SOCK_STREAM through CoreFoundation instead of glibc.

Okay, I lied, there is a hack-around, but you’ll hate your life if you try using it because C imports won’t consistently import through the same modules. You can replace the glibc.SOCK_DGRAM/SOCK_STREAM with CoreFoundation.SOCK_DGRAM/SOCK_STREAM. The overarching issue is that the glibc headers aren’t modular and clang keeps getting stricter about modularity. This isn’t an issue for clang because you don’t have to pass -fmodules and you’ll get normal include behavior. This is an issue for swift because we have to import as modules.

2 Likes