Add Swift Package Manager support
Add Package.swift with three products: GCDWebServer (core), GCDWebUploader, and GCDWebDAVServer. Public headers live across Core/Requests/Responses subdirectories, which SPM cannot expose directly. To support SPM without moving any files (keeping the Xcode project and CocoaPods builds intact), public headers are surfaced through symlinks in include/ directories with a hand-written umbrella-directory module map; the private GCDWebServerPrivate.h is left unlinked so it stays out of the public module. GCDWebUploader.bundle is shipped as a .copy resource and located at runtime via SWIFTPM_MODULE_BUNDLE under a #if SWIFT_PACKAGE branch. Verified: swift build (all targets), Swift module imports, Xcode framework build, and the XCTest suite all pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ xcuserdata
|
|||||||
project.xcworkspace
|
project.xcworkspace
|
||||||
/build
|
/build
|
||||||
/Carthage/Build
|
/Carthage/Build
|
||||||
|
/.build
|
||||||
18
CLAUDE.md
18
CLAUDE.md
@ -10,7 +10,12 @@ Not supported by design: keep-alive connections and HTTPS.
|
|||||||
|
|
||||||
## Build & Test
|
## Build & Test
|
||||||
|
|
||||||
There is no Swift Package Manager `Package.swift`; the build is driven entirely by `GCDWebServer.xcodeproj` (and CocoaPods for consumers).
|
The library can be built three ways: the Xcode project (`GCDWebServer.xcodeproj`), CocoaPods (`GCDWebServer.podspec`), and Swift Package Manager (`Package.swift`). All three compile the same source files in place — see "Swift Package Manager layout" below for how the SPM `include/` directories relate to the real sources.
|
||||||
|
|
||||||
|
Build via SPM:
|
||||||
|
```sh
|
||||||
|
swift build # builds GCDWebServer, GCDWebUploader, GCDWebDAVServer
|
||||||
|
```
|
||||||
|
|
||||||
Schemes (`xcodebuild -list -project GCDWebServer.xcodeproj`):
|
Schemes (`xcodebuild -list -project GCDWebServer.xcodeproj`):
|
||||||
- `GCDWebServer (Mac|iOS|tvOS)` — the static library / framework per platform.
|
- `GCDWebServer (Mac|iOS|tvOS)` — the static library / framework per platform.
|
||||||
@ -71,6 +76,17 @@ Handlers run on **arbitrary GCD threads**, so handler code must be thread-safe a
|
|||||||
- `iOS/`, `tvOS/` — Swift example apps (`AppDelegate.swift`, `ViewController.swift`).
|
- `iOS/`, `tvOS/` — Swift example apps (`AppDelegate.swift`, `ViewController.swift`).
|
||||||
- `Frameworks/` — umbrella header (`GCDWebServers.h`), module map, and the XCTest target source (`Tests.m`).
|
- `Frameworks/` — umbrella header (`GCDWebServers.h`), module map, and the XCTest target source (`Tests.m`).
|
||||||
|
|
||||||
|
## Swift Package Manager layout
|
||||||
|
|
||||||
|
SPM needs each target's public headers in a single directory, but the real headers live spread across `GCDWebServer/Core`, `GCDWebServer/Requests`, and `GCDWebServer/Responses`. To support SPM **without moving any files** (keeping the Xcode project and CocoaPods working), the public headers are surfaced through symlinks:
|
||||||
|
|
||||||
|
- `GCDWebServer/include/*.h` are **symlinks** to the real public headers (everything except the private `GCDWebServerPrivate.h`, which is deliberately not linked so it stays out of the public module). `GCDWebUploader/include/GCDWebUploader.h` works the same way.
|
||||||
|
- `GCDWebServer/include/module.modulemap` is hand-written with `umbrella "."`. This is required: if SPM auto-generated the module map it would pick `include/GCDWebServer.h` as an umbrella *header* (name matches the module) and only export what that one header imports, hiding the request/response subclasses. The umbrella *directory* exports them all.
|
||||||
|
- All cross-header imports inside the library (including the framework umbrella `Frameworks/GCDWebServers.h`) use quoted form (`#import "GCDWebServerRequest.h"`), not framework-style (`#import <GCDWebServers/...>`); the quoted form is what lets the flat `include/` symlink directory resolve them. Keep new imports quoted.
|
||||||
|
- `GCDWebUploader.bundle` is a `.copy` resource. Because SPM nests it inside a generated module bundle, `GCDWebUploader.m` has a `#if SWIFT_PACKAGE` branch that finds it via `SWIFTPM_MODULE_BUNDLE` instead of `bundleForClass:`.
|
||||||
|
|
||||||
|
When adding or renaming a public header, add/remove the matching symlink in the relevant `include/` directory or it won't be visible to SPM consumers. `libxml2` (for WebDAV) needs no special SPM include flag — the macOS/iOS SDK ships a module map that resolves `<libxml/parser.h>` automatically.
|
||||||
|
|
||||||
## Consumer linking requirements
|
## Consumer linking requirements
|
||||||
|
|
||||||
When integrated manually (not via CocoaPods), consuming apps must link `libz`, and WebDAV additionally needs `libxml2` with `$(SDKROOT)/usr/include/libxml2` on the header search path. The `GCDWebServer.podspec` defines three subspecs: `Core` (default), `WebDAV`, and `WebUploader`.
|
When integrated manually (not via CocoaPods), consuming apps must link `libz`, and WebDAV additionally needs `libxml2` with `$(SDKROOT)/usr/include/libxml2` on the header search path. The `GCDWebServer.podspec` defines three subspecs: `Core` (default), `WebDAV`, and `WebUploader`.
|
||||||
|
|||||||
1
GCDWebServer/include/GCDWebServer.h
Symbolic link
1
GCDWebServer/include/GCDWebServer.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../Core/GCDWebServer.h
|
||||||
1
GCDWebServer/include/GCDWebServerConnection.h
Symbolic link
1
GCDWebServer/include/GCDWebServerConnection.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../Core/GCDWebServerConnection.h
|
||||||
1
GCDWebServer/include/GCDWebServerDataRequest.h
Symbolic link
1
GCDWebServer/include/GCDWebServerDataRequest.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../Requests/GCDWebServerDataRequest.h
|
||||||
1
GCDWebServer/include/GCDWebServerDataResponse.h
Symbolic link
1
GCDWebServer/include/GCDWebServerDataResponse.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../Responses/GCDWebServerDataResponse.h
|
||||||
1
GCDWebServer/include/GCDWebServerErrorResponse.h
Symbolic link
1
GCDWebServer/include/GCDWebServerErrorResponse.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../Responses/GCDWebServerErrorResponse.h
|
||||||
1
GCDWebServer/include/GCDWebServerFileRequest.h
Symbolic link
1
GCDWebServer/include/GCDWebServerFileRequest.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../Requests/GCDWebServerFileRequest.h
|
||||||
1
GCDWebServer/include/GCDWebServerFileResponse.h
Symbolic link
1
GCDWebServer/include/GCDWebServerFileResponse.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../Responses/GCDWebServerFileResponse.h
|
||||||
1
GCDWebServer/include/GCDWebServerFunctions.h
Symbolic link
1
GCDWebServer/include/GCDWebServerFunctions.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../Core/GCDWebServerFunctions.h
|
||||||
1
GCDWebServer/include/GCDWebServerHTTPStatusCodes.h
Symbolic link
1
GCDWebServer/include/GCDWebServerHTTPStatusCodes.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../Core/GCDWebServerHTTPStatusCodes.h
|
||||||
1
GCDWebServer/include/GCDWebServerMultiPartFormRequest.h
Symbolic link
1
GCDWebServer/include/GCDWebServerMultiPartFormRequest.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../Requests/GCDWebServerMultiPartFormRequest.h
|
||||||
1
GCDWebServer/include/GCDWebServerRequest.h
Symbolic link
1
GCDWebServer/include/GCDWebServerRequest.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../Core/GCDWebServerRequest.h
|
||||||
1
GCDWebServer/include/GCDWebServerResponse.h
Symbolic link
1
GCDWebServer/include/GCDWebServerResponse.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../Core/GCDWebServerResponse.h
|
||||||
1
GCDWebServer/include/GCDWebServerStreamedResponse.h
Symbolic link
1
GCDWebServer/include/GCDWebServerStreamedResponse.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../Responses/GCDWebServerStreamedResponse.h
|
||||||
1
GCDWebServer/include/GCDWebServerURLEncodedFormRequest.h
Symbolic link
1
GCDWebServer/include/GCDWebServerURLEncodedFormRequest.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../Requests/GCDWebServerURLEncodedFormRequest.h
|
||||||
4
GCDWebServer/include/module.modulemap
Normal file
4
GCDWebServer/include/module.modulemap
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
module GCDWebServer {
|
||||||
|
umbrella "."
|
||||||
|
export *
|
||||||
|
}
|
||||||
@ -66,7 +66,12 @@ NS_ASSUME_NONNULL_END
|
|||||||
|
|
||||||
- (instancetype)initWithUploadDirectory:(NSString*)path {
|
- (instancetype)initWithUploadDirectory:(NSString*)path {
|
||||||
if ((self = [super init])) {
|
if ((self = [super init])) {
|
||||||
|
#if SWIFT_PACKAGE
|
||||||
|
// When built with Swift Package Manager, resources live inside the auto-generated module bundle
|
||||||
|
NSString* bundlePath = [SWIFTPM_MODULE_BUNDLE pathForResource:@"GCDWebUploader" ofType:@"bundle"];
|
||||||
|
#else
|
||||||
NSString* bundlePath = [[NSBundle bundleForClass:[GCDWebUploader class]] pathForResource:@"GCDWebUploader" ofType:@"bundle"];
|
NSString* bundlePath = [[NSBundle bundleForClass:[GCDWebUploader class]] pathForResource:@"GCDWebUploader" ofType:@"bundle"];
|
||||||
|
#endif
|
||||||
if (bundlePath == nil) {
|
if (bundlePath == nil) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|||||||
1
GCDWebUploader/include/GCDWebUploader.h
Symbolic link
1
GCDWebUploader/include/GCDWebUploader.h
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../GCDWebUploader.h
|
||||||
55
Package.swift
Normal file
55
Package.swift
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// swift-tools-version:5.9
|
||||||
|
import PackageDescription
|
||||||
|
|
||||||
|
let package = Package(
|
||||||
|
name: "GCDWebServer",
|
||||||
|
platforms: [
|
||||||
|
.iOS(.v16),
|
||||||
|
.tvOS(.v16),
|
||||||
|
.macOS(.v12),
|
||||||
|
],
|
||||||
|
products: [
|
||||||
|
.library(name: "GCDWebServer", targets: ["GCDWebServer"]),
|
||||||
|
.library(name: "GCDWebUploader", targets: ["GCDWebUploader"]),
|
||||||
|
.library(name: "GCDWebDAVServer", targets: ["GCDWebDAVServer"]),
|
||||||
|
],
|
||||||
|
targets: [
|
||||||
|
.target(
|
||||||
|
name: "GCDWebServer",
|
||||||
|
path: "GCDWebServer",
|
||||||
|
// Public headers are exposed via symlinks in include/ so that GCDWebServerPrivate.h stays private.
|
||||||
|
publicHeadersPath: "include",
|
||||||
|
cSettings: [
|
||||||
|
// Source files import sibling headers across these subdirectories with quoted #imports.
|
||||||
|
.headerSearchPath("Core"),
|
||||||
|
.headerSearchPath("Requests"),
|
||||||
|
.headerSearchPath("Responses"),
|
||||||
|
],
|
||||||
|
linkerSettings: [
|
||||||
|
.linkedLibrary("z"),
|
||||||
|
.linkedFramework("CoreServices", .when(platforms: [.iOS, .tvOS])),
|
||||||
|
.linkedFramework("CFNetwork", .when(platforms: [.iOS, .tvOS])),
|
||||||
|
.linkedFramework("SystemConfiguration", .when(platforms: [.macOS])),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
.target(
|
||||||
|
name: "GCDWebUploader",
|
||||||
|
dependencies: ["GCDWebServer"],
|
||||||
|
path: "GCDWebUploader",
|
||||||
|
exclude: [".DS_Store"],
|
||||||
|
resources: [
|
||||||
|
.copy("GCDWebUploader.bundle"),
|
||||||
|
],
|
||||||
|
publicHeadersPath: "include"
|
||||||
|
),
|
||||||
|
.target(
|
||||||
|
name: "GCDWebDAVServer",
|
||||||
|
dependencies: ["GCDWebServer"],
|
||||||
|
path: "GCDWebDAVServer",
|
||||||
|
publicHeadersPath: ".",
|
||||||
|
linkerSettings: [
|
||||||
|
.linkedLibrary("xml2"),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
@ -67,6 +67,12 @@ github "swisspol/GCDWebServer" ~> 3.2.5
|
|||||||
|
|
||||||
Then run `$ carthage update` and add the generated frameworks to your Xcode projects (see [Carthage instructions](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application)).
|
Then run `$ carthage update` and add the generated frameworks to your Xcode projects (see [Carthage instructions](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application)).
|
||||||
|
|
||||||
|
You can also use [Swift Package Manager](https://www.swift.org/package-manager/). Add GCDWebServer as a dependency in your `Package.swift`:
|
||||||
|
```swift
|
||||||
|
.package(url: "https://github.com/swisspol/GCDWebServer.git", from: "3.5.4")
|
||||||
|
```
|
||||||
|
Then add the product(s) you need to your target's dependencies: `"GCDWebServer"` for the core server, `"GCDWebUploader"` for the web uploader, and/or `"GCDWebDAVServer"` for the WebDAV server. In Xcode, use File > Add Package Dependencies and enter the repository URL.
|
||||||
|
|
||||||
Help & Support
|
Help & Support
|
||||||
==============
|
==============
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user