Эх сурвалжийг харах

Various Swift framework optimizations (#6551)

* Disable memory-exclusivity checks in Vapor, SwiftNIO and Hummingbird

* Upgrade vapor dockerfiles to swift 5.3

* Add .gitignore for all swift projects

* Upgrade hummingbird to v0.11.0

* Move .gitignore from swift root folder to hummingbird
Adam Fowler 4 жил өмнө
parent
commit
eaa7ace6db

+ 7 - 0
frameworks/Swift/hummingbird/.gitignore

@@ -0,0 +1,7 @@
+.DS_Store
+.build/
+/*.xcodeproj
+xcuserdata/
+.swiftpm/
+DerivedData/
+Package.resolved

+ 2 - 1
frameworks/Swift/hummingbird/hummingbird-postgres.dockerfile

@@ -10,7 +10,8 @@ COPY ./src-postgres .
 # Compile with optimizations
 RUN swift build \
 	--enable-test-discovery \
-	-c release
+	-c release \
+	-Xswiftc -enforce-exclusivity=unchecked
 
 # ================================
 # Run image

+ 2 - 1
frameworks/Swift/hummingbird/hummingbird.dockerfile

@@ -10,7 +10,8 @@ COPY ./src .
 # Compile with optimizations
 RUN swift build \
 	--enable-test-discovery \
-	-c release
+	-c release \
+	-Xswiftc -enforce-exclusivity=unchecked
 
 # ================================
 # Run image

+ 2 - 2
frameworks/Swift/hummingbird/src-postgres/Package.swift

@@ -10,8 +10,8 @@ let package = Package(
         .executable(name: "server", targets: ["server"])
     ],
     dependencies: [
-        .package(url: "https://github.com/hummingbird-project/hummingbird.git", .upToNextMinor(from: "0.7.0")),
-        .package(url: "https://github.com/hummingbird-project/hummingbird-mustache.git", .upToNextMinor(from: "0.1.0")),
+        .package(url: "https://github.com/hummingbird-project/hummingbird.git", .upToNextMinor(from: "0.11.0")),
+        .package(url: "https://github.com/hummingbird-project/hummingbird-mustache.git", .upToNextMinor(from: "0.5.0")),
         .package(url: "https://github.com/vapor/postgres-kit.git", from: "2.0.0"),
     ],
     targets: [

+ 1 - 12
frameworks/Swift/hummingbird/src-postgres/Sources/server/Controllers/FortunesController.swift

@@ -15,18 +15,7 @@ class FortunesController {
 
     init() {
         self.template = try! HBMustacheTemplate(string: """
-        <!DOCTYPE html>
-        <html>
-        <head><title>Fortunes</title></head>
-        <body>
-        <table>
-        <tr><th>id</th><th>message</th></tr>
-        {{#.}}
-        <tr><td>{{id}}</td><td>{{message}}</td></tr>
-        {{/.}}
-        </table>
-        </body>
-        </html>
+        <!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>{{#.}}<tr><td>{{id}}</td><td>{{message}}</td></tr>{{/.}}</table></body></html>
         """)
     }
 

+ 4 - 4
frameworks/Swift/hummingbird/src-postgres/Sources/server/main.swift

@@ -8,7 +8,7 @@ extension Int {
     }
 }
 
-func runApp() {
+func runApp() throws {
     let env = HBEnvironment()
     let serverHostName = env.get("SERVER_HOSTNAME") ?? "127.0.0.1"
     let serverPort = env.get("SERVER_PORT", as: Int.self) ?? 8080
@@ -20,12 +20,12 @@ func runApp() {
     let app = HBApplication(configuration: configuration)
     app.encoder = JSONEncoder()
     app.initConnectionPool()
-    
+
     WorldController().add(to: app.router)
     FortunesController().add(to: app.router)
 
-    app.start()
+    try app.start()
     app.wait()
 }
 
-runApp()
+try runApp()

+ 1 - 1
frameworks/Swift/hummingbird/src/Package.swift

@@ -9,7 +9,7 @@ let package = Package(
         .executable(name: "server", targets: ["server"])
     ],
     dependencies: [
-        .package(url: "https://github.com/hummingbird-project/hummingbird.git", .upToNextMinor(from: "0.7.0")),
+        .package(url: "https://github.com/hummingbird-project/hummingbird.git", .upToNextMinor(from: "0.11.0")),
     ],
     targets: [
         .target(name: "server",

+ 4 - 4
frameworks/Swift/hummingbird/src/Sources/server/main.swift

@@ -5,7 +5,7 @@ struct Object: HBResponseEncodable {
     let message: String
 }
 
-func runApp() {
+func runApp() throws {
     let env = HBEnvironment()
     let serverHostName = env.get("SERVER_HOSTNAME") ?? "127.0.0.1"
     let serverPort = env.get("SERVER_PORT", as: Int.self) ?? 8080
@@ -17,7 +17,7 @@ func runApp() {
     )
     let app = HBApplication(configuration: configuration)
     app.encoder = JSONEncoder()
-    
+
     app.router.get("plaintext") { req in
         "Hello, world!"
     }
@@ -26,8 +26,8 @@ func runApp() {
         Object(message: "Hello, world!")
     }
 
-    app.start()
+    try app.start()
     app.wait()
 }
 
-runApp()
+try runApp()

+ 2 - 1
frameworks/Swift/swift-nio/swift-nio.dockerfile

@@ -10,7 +10,8 @@ COPY ./app .
 # Compile with optimizations
 RUN swift build \
 	--enable-test-discovery \
-	-c release
+	-c release \
+	-Xswiftc -enforce-exclusivity=unchecked
 
 # ================================
 # Run image

+ 4 - 3
frameworks/Swift/vapor/vapor-fluent.dockerfile

@@ -1,7 +1,7 @@
 # ================================
 # Build image
 # ================================
-FROM vapor/swift:5.2 as build
+FROM swift:5.3 as build
 WORKDIR /build
 
 # Copy entire repo into container
@@ -10,12 +10,13 @@ COPY ./vapor-fluent .
 # Compile with optimizations
 RUN swift build \
 	--enable-test-discovery \
-	-c release
+	-c release \
+	-Xswiftc -enforce-exclusivity=unchecked
 
 # ================================
 # Run image
 # ================================
-FROM vapor/ubuntu:18.04
+FROM swift:5.3-slim
 WORKDIR /run
 
 # Copy build artifacts

+ 4 - 3
frameworks/Swift/vapor/vapor-postgres.dockerfile

@@ -1,7 +1,7 @@
 # ================================
 # Build image
 # ================================
-FROM vapor/swift:5.2 as build
+FROM swift:5.3 as build
 WORKDIR /build
 
 # Copy entire repo into container
@@ -10,12 +10,13 @@ COPY ./vapor-postgres .
 # Compile with optimizations
 RUN swift build \
 	--enable-test-discovery \
-	-c release
+	-c release \
+	-Xswiftc -enforce-exclusivity=unchecked
 
 # ================================
 # Run image
 # ================================
-FROM vapor/ubuntu:18.04
+FROM swift:5.3-slim
 WORKDIR /run
 
 # Copy build artifacts

+ 4 - 3
frameworks/Swift/vapor/vapor-sql-kit.dockerfile

@@ -1,7 +1,7 @@
 # ================================
 # Build image
 # ================================
-FROM vapor/swift:5.2 as build
+FROM swift:5.3 as build
 WORKDIR /build
 
 # Copy entire repo into container
@@ -10,12 +10,13 @@ COPY ./vapor-sql-kit .
 # Compile with optimizations
 RUN swift build \
 	--enable-test-discovery \
-	-c release
+	-c release \
+	-Xswiftc -enforce-exclusivity=unchecked
 
 # ================================
 # Run image
 # ================================
-FROM vapor/ubuntu:18.04
+FROM swift:5.3-slim
 WORKDIR /run
 
 # Copy build artifacts

+ 4 - 3
frameworks/Swift/vapor/vapor.dockerfile

@@ -1,7 +1,7 @@
 # ================================
 # Build image
 # ================================
-FROM vapor/swift:5.2 as build
+FROM swift:5.3 as build
 WORKDIR /build
 
 # Copy entire repo into container
@@ -10,12 +10,13 @@ COPY ./vapor-default .
 # Compile with optimizations
 RUN swift build \
 	--enable-test-discovery \
-	-c release
+	-c release \
+	-Xswiftc -enforce-exclusivity=unchecked
 
 # ================================
 # Run image
 # ================================
-FROM vapor/ubuntu:18.04
+FROM swift:5.3-slim
 WORKDIR /run
 
 # Copy build artifacts