apple / swift-nio

Event-driven network application framework for high performance protocol servers & clients, non-blocking.
https://swiftpackageindex.com/apple/swift-nio/documentation
Apache License 2.0
7.93k stars 644 forks source link

Build errors when building against a Static Linux SDK #2893

Open briancoyner opened 2 hours ago

briancoyner commented 2 hours ago

Expected behavior

An application with a dependency on SwiftNIO successfully builds with a Swift 6 OSS toolchain + Static Linux SDK.

Note: The swift-6.0-DEVELOPMENT-SNAPSHOT-2024-09-17-a toolchain is used vs the swift-6.0-RELEASE because of another issue with swift-collections. That issue is fixed in the "09-17" toolchain release.

Note: Xcode 15.4.0 vs Xcode 16.0.0 because of an issue described here:

Actual behavior

main branch error

$ xcrun --toolchain org.swift.600202409171a swift build --swift-sdk aarch64-swift-linux-musl
Building for debugging...
In file included from /Users/someuser/Developer/some-app/.build/checkouts/swift-nio/Sources/CNIOLinux/shim.c:25:
/Users/someuser/Developer/some-app/.build/checkouts/swift-nio/Sources/CNIOLinux/include/CNIOLinux.h:33:10: fatal error: 'linux/udp.h' file not found
   33 | #include <linux/udp.h>
      |          ^~~~~~~~~~~~~
1 error generated.

2.72.0 tag error

$ xcrun --toolchain org.swift.600202409171a swift build --swift-sdk aarch64-swift-linux-musl
/Users/someuser/Developer/some-app/.build/checkouts/swift-nio/Sources/NIOPosix/PosixSingletons+ConcurrencyTakeOver.swift:76:12: error: conflicting arguments to generic parameter 'T' ('Optional<UnsafeRawPointer>.AtomicRepresentation' vs. 'Optional<UnsafeRawPointer>.AtomicRepresentation')

...

/Users/someuser/Developer/some-app/.build/checkouts/swift-nio/Sources/NIOPosix/PosixSingletons+ConcurrencyTakeOver.swift:112:35: error: 'nil' requires a contextual type

...

additional errors 

Steps to reproduce

  1. Install the Swift 6 OSS toolchain + SDK (swift-6.0-DEVELOPMENT-SNAPSHOT-2024-09-17-a).
  2. A simple application using SPM with a dependency on SwiftNIO.
  3. Execute the following to build the application.
$ xcrun --toolchain org.swift.600202409171a swift build --swift-sdk aarch64-swift-linux-musl
See errors noted above (for both `main` and `2.72.0`)

Also, building without the Static Linux SDK succeeds:

$ xcrun --toolchain org.swift.600202409171a swift build                                     
Building for debugging...
[215/215] Applying Demo
Build complete! (20.94s)

If possible, minimal yet complete reproducer code (or URL to code)

Here's a basic Package.swift manifest that can be used:

// swift-tools-version: 6.0
import PackageDescription

let package = Package(
    name: "Demo",
    platforms: [
       .macOS(.v14)
    ],
    dependencies: [
        .package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.70.0"))
        // .package(url: "https://github.com/apple/swift-nio.git", branch: "main")
    ],
    targets: [
        .executableTarget(
            name: "Demo",
            dependencies: [
                .product(name: "NIOPosix", package: "swift-nio")
            ],
            swiftSettings: swiftSettings
        ),
    ],
    swiftLanguageModes: [
        .v6
    ]
)

// MARK: - Swift Settings

var swiftSettings: [SwiftSetting] {
    return [
        .enableUpcomingFeature("ExistentialAny")
    ]
}

SwiftNIO version/commit hash

main and 2.72.0

System & version information

Sonoma 14.6.1

*****
***** Swift Toolchain
*****   Name: swift-6.0-DEVELOPMENT-SNAPSHOT-2024-09-17-a
*****   Path: /Library/Developer/Toolchains/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-09-17-a.xctoolchain
*****     ID: org.swift.600202409171a
*****    SDK: aarch64-swift-linux-musl
*****    SPM: Swift Package Manager - Swift 6.0.0-dev
*****  Xcode: /Applications/Xcode15.4.0.app/Contents/Developer
*****
Lukasa commented 2 hours ago

Thanks for this! The main issues were introduced by #2891, so @rnro should probably take a look at that.

For the others, those issues are a bit weird. conflicting arguments to generic parameter 'T' ('Optional<UnsafeRawPointer>.AtomicRepresentation' vs. 'Optional<UnsafeRawPointer>.AtomicRepresentation') appears to be complaining about two identical types. The other error is also odd.

@al45tair, do you have any ideas what's going on there?

rnro commented 1 hour ago

Thanks for letting us know about this. I've put up a PR which should fixup the linux/udp.h issue. https://github.com/apple/swift-nio/pull/2894

al45tair commented 36 minutes ago

@Lukasa I'm not sure about the AtomicRepresentation error; that likely means that we've got two modules defining some type or other, but normally that happens with C types rather than Swift ones.

As for <linux/udp.h>, if NIO has started requiring that then we may need to work out what it's using and add that to the Static SDK. Note that the Static SDK does not include the Linux headers, because those are GPL'd; to make things work for NIO and a couple of other things, it does include some shims that declare just the things that are being used.