hummingbird-project / hummingbird

Lightweight, flexible HTTP server framework written in Swift
Apache License 2.0
1.01k stars 50 forks source link

Swift 6 and static Linux cross compiling. #515

Closed zaneenders closed 2 weeks ago

zaneenders commented 1 month ago

Hi,

I know this is getting ahead of things but hoping the heads up helps.

I tried compiling hummingbird using Swift 6 and the static Linux sdx using these instructions.

I got the following errors. Though I'm not sure how to fix them just yet.

.../hummingbird/Sources/Hummingbird/Environment.swift:113:27: error: value of optional type 'UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>?' (aka 'Optional<UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>>') must be unwrapped to refer to member 'advanced' of wrapped base type 'UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>' (aka 'UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>')
111 |         var idx = 0
112 | 
113 |         while let entry = envp.advanced(by: idx).pointee {
    |                           |- error: value of optional type 'UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>?' (aka 'Optional<UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>>') must be unwrapped to refer to member 'advanced' of wrapped base type 'UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>' (aka 'UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>')
    |                           |- note: chain the optional using '?' to access member 'advanced' only for non-'nil' base values
    |                           `- note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
114 |             let entry = String(cString: entry)
115 |             if let i = entry.firstIndex(of: equalSign) {
hummingbird/Sources/Hummingbird/Environment.swift:110:20: warning: reference to var 'environ' is not concurrency-safe because it involves shared mutable state; this is an error in the Swift 6 language mode
108 |         var values: [String: String] = [:]
109 |         let equalSign = Character("=")
110 |         let envp = environ
    |                    `- warning: reference to var 'environ' is not concurrency-safe because it involves shared mutable state; this is an error in the Swift 6 language mode
111 |         var idx = 0
112 | 

posix_unistd.environ:1:12: note: var declared here
1 | public var environ: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?>!
  |            `- note: var declared here
[552/555] Compiling Hummingbird Application.swift

This is on the main branch of hummingbird a1028d2 and compiling the project using swift build --swift-sdk x86_64-swift-linux-musl -c release

Compiler and SDK swift-6.0-DEVELOPMENT-SNAPSHOT-2024-07-21-a-osx.pkg swift-6.0-DEVELOPMENT-SNAPSHOT-2024-07-02-a_static-linux-0.0.1.artifactbundle.tar

Thanks, Zane

adam-fowler commented 1 month ago

I thought I had fixed all the issues with Environment. Musl is obviously showing up some new ones.

Joannis commented 1 month ago

Unfortunately it seems I can't run the static linux SDK on the most recent macOS beta.

zaneenders commented 1 month ago

I am running macOS 14.5 (23F79).

adam-fowler commented 1 month ago

517 fixes the compile errors (although the swift 6 warning is still there. I think that'll need a change to the SDK).

But I am getting a crash, which seems associated with the SwiftService lifecycle and the merge code from AsyncAlgorithms.

AsyncAlgorithms/MergeStateMachine.swift:176: Fatal error: Internal inconsistency current state initial(base1: Swift.AsyncMapSequence<ServiceLifecycle.AsyncMapNilSequence<AsyncAlgorithms.AsyncTimerSequence<Swift.SuspendingClock>>, ServiceLifecycle.AsyncCancelOnGracefulShutdownSequence<AsyncAlgorithms.AsyncTimerSequence<Swift.SuspendingClock>>._ElementOrGracefulShutdown>(base: ServiceLifecycle.AsyncMapNilSequence<AsyncAlgorithms.AsyncTimerSequence<Swift.SuspendingClock>>(_base: AsyncAlgorithms.AsyncTimerSequence<Swift.SuspendingClock>(clock: Swift.SuspendingClock(), interval: 1.0 seconds, tolerance: nil)), transform: (Function)), base2: Swift.AsyncMapSequence<ServiceLifecycle.AsyncMapNilSequence<ServiceLifecycle.AsyncGracefulShutdownSequence>, ServiceLifecycle.AsyncCancelOnGracefulShutdownSequence<AsyncAlgorithms.AsyncTimerSequence<Swift.SuspendingClock>>._ElementOrGracefulShutdown>(base: ServiceLifecycle.AsyncMapNilSequence<ServiceLifecycle.AsyncGracefulShutdownSequence>(_base: ServiceLifecycle.AsyncGracefulShutdownSequence()), transform: (Function)), base3: nil) and received childTaskSuspended()
adam-fowler commented 1 month ago

This should fix the crash https://github.com/apple/swift-async-algorithms/pull/325

adam-fowler commented 2 weeks ago

I'm going to close this as the issue has been resolved elsewhere. Just need to wait for a 1.0.1 of swift-async-algorithms