Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for service lifecycle on Windows #196

Open
xtremekforever opened this issue Jan 12, 2025 · 0 comments
Open

Support for service lifecycle on Windows #196

xtremekforever opened this issue Jan 12, 2025 · 0 comments

Comments

@xtremekforever
Copy link

I know that this is primarily a package for Swift on Server applications on Linux or macOS. But, I feel like Windows applications coded in Swift could also benefit from this package. Right now, of course it does not compile because it depends on UnixSignals:

C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignalsSequence.swift:34:32: error: cannot find 'DispatchQueue' in scope
 32 | /// for the same signal.
 33 | public struct UnixSignalsSequence: AsyncSequence, Sendable {
 34 |     private static let queue = DispatchQueue(label: "com.service-lifecycle.unix-signals")
    |                                `- error: cannot find 'DispatchQueue' in scope
 35 | 
 36 |     public typealias Element = UnixSignal

C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignalsSequence.swift:39:29: error: cannot find type 'DispatchSource' in scope
 37 | 
 38 |     fileprivate struct Source: Sendable {
 39 |         var dispatchSource: DispatchSource
    |                             `- error: cannot find type 'DispatchSource' in scope
 40 |         var signal: UnixSignal
 41 |     }

C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignalsSequence.swift:34:32: error: cannot find 'DispatchQueue' in scope
 32 | /// for the same signal.
 33 | public struct UnixSignalsSequence: AsyncSequence, Sendable {
 34 |     private static let queue = DispatchQueue(label: "com.service-lifecycle.unix-signals")
    |                                `- error: cannot find 'DispatchQueue' in scope
 35 |
 36 |     public typealias Element = UnixSignal


C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignalsSequence.swift:39:29: error: cannot find type 'DispatchSource' in scope
 37 |
 38 |     fileprivate struct Source: Sendable {
 39 |         var dispatchSource: DispatchSource
    |                             `- error: cannot find type 'DispatchSource' in scope
 40 |         var signal: UnixSignal
 41 |     }


C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignalsSequence.swift:88:37: error: cannot find 'DispatchSource' in scope
 86 |                 return .init(
 87 |                     // This force-unwrap is safe since Dispatch always returns a `DispatchSource`
 88 |                     dispatchSource: DispatchSource.makeSignalSource(
    |                                     `- error: cannot find 'DispatchSource' in scope
 89 |                         signal: sig.rawValue,
 90 |                         queue: UnixSignalsSequence.queue


C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignalsSequence.swift:91:27: error: cannot find type 'DispatchSource' in scope
 89 |                         signal: sig.rawValue,
 90 |                         queue: UnixSignalsSequence.queue
 91 |                     ) as! DispatchSource,
    |                           `- error: cannot find type 'DispatchSource' in scope
 92 |                     signal: sig
 93 |                 )

C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignal.swift:116:20: error: cannot find 'SIGABRT' in scope
114 |         switch self {
115 |         case .sigabrt:
116 |             return SIGABRT
    |                    `- error: cannot find 'SIGABRT' in scope
117 |         case .sighup:
118 |             return SIGHUP

C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignal.swift:118:20: error: cannot find 'SIGHUP' in scope
116 |             return SIGABRT
117 |         case .sighup:
118 |             return SIGHUP
    |                    `- error: cannot find 'SIGHUP' in scope
119 |         case .sigill:
120 |             return SIGILL

C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignal.swift:120:20: error: cannot find 'SIGILL' in scope
118 |             return SIGHUP
119 |         case .sigill:
120 |             return SIGILL
    |                    `- error: cannot find 'SIGILL' in scope
121 |         case .sigint:
122 |             return SIGINT

C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignal.swift:122:20: error: cannot find 'SIGINT' in scope
120 |             return SIGILL
121 |         case .sigint:
122 |             return SIGINT
    |                    `- error: cannot find 'SIGINT' in scope
123 |         case .sigquit:
124 |             return SIGQUIT

C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignal.swift:124:20: error: cannot find 'SIGQUIT' in scope
122 |             return SIGINT
123 |         case .sigquit:
124 |             return SIGQUIT
    |                    `- error: cannot find 'SIGQUIT' in scope
125 |         case .sigsegv:
126 |             return SIGSEGV

C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignal.swift:126:20: error: cannot find 'SIGSEGV' in scope
124 |             return SIGQUIT
125 |         case .sigsegv:
126 |             return SIGSEGV
    |                    `- error: cannot find 'SIGSEGV' in scope
127 |         case .sigterm:
128 |             return SIGTERM

C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignal.swift:128:20: error: cannot find 'SIGTERM' in scope
126 |             return SIGSEGV
127 |         case .sigterm:
128 |             return SIGTERM
    |                    `- error: cannot find 'SIGTERM' in scope
129 |         case .sigusr1:
130 |             return SIGUSR1

C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignal.swift:130:20: error: cannot find 'SIGUSR1' in scope
128 |             return SIGTERM
129 |         case .sigusr1:
130 |             return SIGUSR1
    |                    `- error: cannot find 'SIGUSR1' in scope
131 |         case .sigusr2:
132 |             return SIGUSR2

C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignal.swift:132:20: error: cannot find 'SIGUSR2' in scope
130 |             return SIGUSR1
131 |         case .sigusr2:
132 |             return SIGUSR2
    |                    `- error: cannot find 'SIGUSR2' in scope
133 |         case .sigalrm:
134 |             return SIGALRM

C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignal.swift:134:20: error: cannot find 'SIGALRM' in scope
132 |             return SIGUSR2
133 |         case .sigalrm:
134 |             return SIGALRM
    |                    `- error: cannot find 'SIGALRM' in scope
135 |         case .sigwinch:
136 |             return SIGWINCH

C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignal.swift:136:20: error: cannot find 'SIGWINCH' in scope
134 |             return SIGALRM
135 |         case .sigwinch:
136 |             return SIGWINCH
    |                    `- error: cannot find 'SIGWINCH' in scope
137 |         case .sigcont:
138 |             return SIGCONT

C:\tmp\swift-service-lifecycle\Sources\UnixSignals\UnixSignal.swift:138:20: error: cannot find 'SIGCONT' in scope
136 |             return SIGWINCH
137 |         case .sigcont:
138 |             return SIGCONT
    |                    `- error: cannot find 'SIGCONT' in scope
139 |         }
140 |     }

[4/40] Compiling UnixSignals UnixSignal.swift

I wonder if perhaps there could be a way provide compatibility for Windows, perhaps by using something like the TerminateProcess API, and map the unix signals to a similar equivalent. Or, provide a different termination event for Windows vs. Unix. But, it still feels like this could be very useful in the future!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant