From e5dacbd6d390e2f0ff7627752ce42f2429e91eec Mon Sep 17 00:00:00 2001 From: saroar Date: Thu, 2 Nov 2023 15:30:08 +0000 Subject: [PATCH] remove main folder Remove old style --- Dockerfile | 2 +- Package.swift | 7 +----- Sources/App/entrypoint.swift | 44 ++++++++++++++++++++++++++++++++++++ Sources/Main/Main.swift | 15 ------------ 4 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 Sources/App/entrypoint.swift delete mode 100644 Sources/Main/Main.swift diff --git a/Dockerfile b/Dockerfile index b69ff69..01b73c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,7 +33,7 @@ RUN swift build -c release --static-swift-stdlib \ WORKDIR /staging # Copy main executable to staging area -RUN cp "$(swift build --package-path /build -c release --show-bin-path)/Main" ./ +RUN cp "$(swift build --package-path /build -c release --show-bin-path)/App" ./ # Copy resources bundled by SPM to staging area RUN find -L "$(swift build --package-path /build -c release --show-bin-path)/" -regex '.*\.resources$' -exec cp -Ra {} ./ \; diff --git a/Package.swift b/Package.swift index 478e55c..4ac858e 100644 --- a/Package.swift +++ b/Package.swift @@ -27,7 +27,7 @@ let package = Package( .package(url: "https://github.com/vapor-community/mailgun.git", from: "5.0.0"), ], targets: [ - .target( + .executableTarget( name: "App", dependencies: [ .product(name: "Vapor", package: "vapor"), @@ -42,13 +42,8 @@ let package = Package( .product(name: "QueuesRedisDriver", package: "queues-redis-driver"), .product(name: "Mailgun", package: "mailgun"), .product(name: "VaporRouting", package: "vapor-routing") - ], - swiftSettings: [ - .unsafeFlags(["-cross-module-optimization"], .when(configuration: .release)) ] ), - - .executableTarget(name: "Main", dependencies: [.target(name: "App")]), .testTarget(name: "AppTests", dependencies: [ .target(name: "App"), .product(name: "XCTVapor", package: "vapor"), diff --git a/Sources/App/entrypoint.swift b/Sources/App/entrypoint.swift new file mode 100644 index 0000000..c21d382 --- /dev/null +++ b/Sources/App/entrypoint.swift @@ -0,0 +1,44 @@ +import Vapor +import Dispatch +import Logging +import MongoQueue + +/// This extension is temporary and can be removed once Vapor gets this support. +private extension Vapor.Application { + static let baseExecutionQueue = DispatchQueue(label: "vapor.codes.entrypoint") + + func runFromAsyncMainEntrypoint() async throws { + try await withCheckedThrowingContinuation { continuation in + Vapor.Application.baseExecutionQueue.async { [self] in + do { + try self.run() + continuation.resume() + } catch { + continuation.resume(throwing: error) + } + } + } + } +} + +@main +enum Entrypoint { + static func main() async throws { + var env = try Environment.detect() + try LoggingSystem.bootstrap(from: &env) + + let app = Application(env) + defer { app.shutdown() } + + do { + try await configure(app) + } catch { + app.logger.report(error: error) + throw error + } + + try await app.runFromAsyncMainEntrypoint() + } +} + + diff --git a/Sources/Main/Main.swift b/Sources/Main/Main.swift deleted file mode 100644 index 72263b1..0000000 --- a/Sources/Main/Main.swift +++ /dev/null @@ -1,15 +0,0 @@ -import App -import Vapor - -@main -struct Main { - static func main() async throws { - var env = try Environment.detect() - try LoggingSystem.bootstrap(from: &env) - let app = Application(env) - defer { app.shutdown() } - - try await configure(app) - try await app.customRun() - } -}