Skip to content

Commit 45eea90

Browse files
authored
Merge pull request #23 from BennyFranciscus/add-hummingbird
Add Hummingbird: Swift HTTP framework on SwiftNIO (first Swift entry!)
2 parents b37c191 + a0d2619 commit 45eea90

7 files changed

Lines changed: 443 additions & 0 deletions

File tree

frameworks/hummingbird/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM swift:6.2-jammy AS build
2+
RUN apt-get update && apt-get install -y --no-install-recommends libsqlite3-dev && rm -rf /var/lib/apt/lists/*
3+
WORKDIR /app
4+
COPY Package.swift .
5+
COPY Sources ./Sources
6+
RUN mkdir -p src && echo 'import CSQLite\nprint("stub")' > src/main.swift && \
7+
swift build -c release 2>/dev/null || true && \
8+
rm -rf src/
9+
COPY src ./src
10+
RUN swift build -c release -Xswiftc -O -Xswiftc -cross-module-optimization
11+
12+
FROM ubuntu:22.04
13+
RUN apt-get update && apt-get install -y --no-install-recommends \
14+
libsqlite3-0 libcurl4 libxml2 && \
15+
rm -rf /var/lib/apt/lists/*
16+
COPY --from=build /usr/lib/swift/linux/lib*.so /usr/lib/swift/linux/
17+
COPY --from=build /app/.build/release/Server /server
18+
EXPOSE 8080
19+
CMD ["/server"]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// swift-tools-version:6.0
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "httparena-hummingbird",
6+
platforms: [.macOS(.v14)],
7+
dependencies: [
8+
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0"),
9+
.package(url: "https://github.com/hummingbird-project/hummingbird-compression.git", from: "2.0.0"),
10+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.65.0"),
11+
],
12+
targets: [
13+
.systemLibrary(
14+
name: "CSQLite",
15+
path: "Sources/CSQLite",
16+
pkgConfig: "sqlite3",
17+
providers: [
18+
.apt(["libsqlite3-dev"]),
19+
]
20+
),
21+
.executableTarget(
22+
name: "Server",
23+
dependencies: [
24+
"CSQLite",
25+
.product(name: "Hummingbird", package: "hummingbird"),
26+
.product(name: "HummingbirdCompression", package: "hummingbird-compression"),
27+
.product(name: "NIOCore", package: "swift-nio"),
28+
.product(name: "NIOPosix", package: "swift-nio"),
29+
],
30+
path: "src"
31+
),
32+
]
33+
)

frameworks/hummingbird/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Hummingbird — Swift HTTP Framework
2+
3+
[Hummingbird](https://github.com/hummingbird-project/hummingbird) is a lightweight, flexible HTTP server framework written in Swift, built on top of [SwiftNIO](https://github.com/apple/swift-nio).
4+
5+
## Why Hummingbird?
6+
7+
- **SwiftNIO-based**: Non-blocking I/O with Swift's structured concurrency
8+
- **Minimal dependencies**: Designed to be lightweight with opt-in extensions
9+
- **Modern Swift**: Uses async/await throughout
10+
- **SSWG incubated**: Part of the Swift Server Work Group ecosystem
11+
12+
## Implementation Notes
13+
14+
- Uses Swift 5.10 with whole-module optimization
15+
- SQLite via [SQLite.swift](https://github.com/stephencelis/SQLite.swift) for the `/db` endpoint
16+
- Pre-cached JSON responses for `/json` and `/compression` endpoints
17+
- Static files loaded into memory at startup
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module CSQLite [system] {
2+
header "shim.h"
3+
link "sqlite3"
4+
export *
5+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#pragma once
2+
#include <sqlite3.h>

frameworks/hummingbird/meta.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"display_name": "hummingbird",
3+
"language": "Swift",
4+
"type": "framework",
5+
"engine": "Hummingbird",
6+
"description": "Lightweight, flexible HTTP server framework written in Swift, built on SwiftNIO with minimal dependencies.",
7+
"repo": "https://github.com/hummingbird-project/hummingbird",
8+
"enabled": true,
9+
"tests": [
10+
"baseline",
11+
"noisy",
12+
"pipelined",
13+
"limited-conn",
14+
"json",
15+
"upload",
16+
"compression",
17+
"mixed"
18+
]
19+
}

0 commit comments

Comments
 (0)