Skip to content

Commit 80eb454

Browse files
committed
build: remove the PreviewServer on Windows
This is the critical change to enable Windows support in DocC. The dependency on NIO is restricted to the PreviewServer and as NIO is incapable of supporting non-POSIX models (or emulation of POSIX models), we cannot use this dependency on Windows. As a temporary solution, remove the NIO dependency on Windows by removing the PreviewServer.
1 parent 8981c51 commit 80eb454

File tree

2 files changed

+61
-25
lines changed

2 files changed

+61
-25
lines changed

Package.swift

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,6 @@ let package = Package(
6363
swiftSettings: swiftSettings
6464
),
6565

66-
// Command-line tool library
67-
.target(
68-
name: "SwiftDocCUtilities",
69-
dependencies: [
70-
.target(name: "SwiftDocC"),
71-
.product(name: "NIOHTTP1", package: "swift-nio"),
72-
.product(name: "ArgumentParser", package: "swift-argument-parser")
73-
],
74-
swiftSettings: swiftSettings
75-
),
76-
.testTarget(
77-
name: "SwiftDocCUtilitiesTests",
78-
dependencies: [
79-
.target(name: "SwiftDocCUtilities"),
80-
.target(name: "SwiftDocC"),
81-
.target(name: "SwiftDocCTestUtilities"),
82-
],
83-
resources: [
84-
.copy("Test Resources"),
85-
.copy("Test Bundles"),
86-
],
87-
swiftSettings: swiftSettings
88-
),
8966
// Test utility library
9067
.target(
9168
name: "SwiftDocCTestUtilities",
@@ -126,20 +103,74 @@ let package = Package(
126103
]
127104
)
128105

106+
// Command-line tool library
107+
#if os(Windows)
108+
package.targets.append(
109+
.target(
110+
name: "SwiftDocCUtilities",
111+
dependencies: [
112+
.target(name: "SwiftDocC"),
113+
.product(name: "ArgumentParser", package: "swift-argument-parser")
114+
],
115+
exclude: [
116+
// PreviewServer requires NIO which cannot support non-POSIX platforms.
117+
"PreviewServer",
118+
"Action/Actions/PreviewAction.swift",
119+
"ArgumentParsing/ActionExtensions/PreviewAction+CommandInitialization.swift",
120+
"ArgumentParsing/Subcommands/Preview.swift",
121+
],
122+
swiftSettings: swiftSettings
123+
)
124+
)
125+
#else
126+
package.targets.append(
127+
.target(
128+
name: "SwiftDocCUtilities",
129+
dependencies: [
130+
.target(name: "SwiftDocC"),
131+
.product(name: "NIOHTTP1", package: "swift-nio"),
132+
.product(name: "ArgumentParser", package: "swift-argument-parser")
133+
],
134+
swiftSettings: swiftSettings
135+
)
136+
)
137+
#endif
138+
139+
package.targets.append(
140+
.testTarget(
141+
name: "SwiftDocCUtilitiesTests",
142+
dependencies: [
143+
.target(name: "SwiftDocCUtilities"),
144+
.target(name: "SwiftDocC"),
145+
.target(name: "SwiftDocCTestUtilities"),
146+
],
147+
resources: [
148+
.copy("Test Resources"),
149+
.copy("Test Bundles"),
150+
],
151+
swiftSettings: swiftSettings
152+
)
153+
)
154+
129155
// If the `SWIFTCI_USE_LOCAL_DEPS` environment variable is set,
130156
// we're building in the Swift.org CI system alongside other projects in the Swift toolchain and
131157
// we can depend on local versions of our dependencies instead of fetching them remotely.
132158
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
133159
// Building standalone, so fetch all dependencies remotely.
134160
package.dependencies += [
135-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.53.0"),
136161
.package(url: "https://github.com/apple/swift-markdown.git", branch: "main"),
137162
.package(url: "https://github.com/apple/swift-lmdb.git", branch: "main"),
138163
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.2"),
139164
.package(url: "https://github.com/apple/swift-docc-symbolkit", branch: "main"),
140165
.package(url: "https://github.com/apple/swift-crypto.git", from: "2.5.0"),
141166
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
142167
]
168+
169+
#if !os(Windows)
170+
package.dependencies += [
171+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.53.0"),
172+
]
173+
#endif
143174
} else {
144175
// Building in the Swift.org CI system, so rely on local versions of dependencies.
145176
package.dependencies += [

Sources/SwiftDocCUtilities/Docc.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ import ArgumentParser
1212

1313
/// The default, command-line interface you use to compile and preview documentation.
1414
public struct Docc: ParsableCommand {
15+
#if canImport(NIOHTTP)
16+
let subcommands: [ParsableCommand.Type] = [Convert.self, Index.self, Preview.self, ProcessArchive.self]
17+
#else
18+
let subcommands: [ParsableCommand.Type] = [Convert.self, Index.self, ProcessArchive.self]
19+
#endif
1520

1621
public static var configuration = CommandConfiguration(
1722
abstract: "Documentation Compiler: compile, analyze, and preview documentation.",
18-
subcommands: [Convert.self, Index.self, Preview.self, ProcessArchive.self])
23+
subcommands: subcommands)
1924

2025
public init() {}
2126
}

0 commit comments

Comments
 (0)