diff --git a/Package.swift b/Package.swift index 9ad6fa6d7a..3ceb324be8 100644 --- a/Package.swift +++ b/Package.swift @@ -43,6 +43,7 @@ let package = Package( .target( name: "SwiftDocC", dependencies: [ + .target(name: "DocCCommon"), .product(name: "Markdown", package: "swift-markdown"), .product(name: "SymbolKit", package: "swift-docc-symbolkit"), .product(name: "CLMDB", package: "swift-lmdb"), @@ -55,6 +56,7 @@ let package = Package( name: "SwiftDocCTests", dependencies: [ .target(name: "SwiftDocC"), + .target(name: "DocCCommon"), .target(name: "SwiftDocCTestUtilities"), ], resources: [ @@ -70,6 +72,7 @@ let package = Package( name: "SwiftDocCUtilities", dependencies: [ .target(name: "SwiftDocC"), + .target(name: "DocCCommon"), .product(name: "NIOHTTP1", package: "swift-nio", condition: .when(platforms: [.macOS, .iOS, .linux, .android])), .product(name: "ArgumentParser", package: "swift-argument-parser") ], @@ -81,6 +84,7 @@ let package = Package( dependencies: [ .target(name: "SwiftDocCUtilities"), .target(name: "SwiftDocC"), + .target(name: "DocCCommon"), .target(name: "SwiftDocCTestUtilities"), ], resources: [ @@ -95,6 +99,7 @@ let package = Package( name: "SwiftDocCTestUtilities", dependencies: [ .target(name: "SwiftDocC"), + .target(name: "DocCCommon"), .product(name: "SymbolKit", package: "swift-docc-symbolkit"), ], swiftSettings: swiftSettings @@ -109,6 +114,25 @@ let package = Package( exclude: ["CMakeLists.txt"], swiftSettings: swiftSettings ), + + // A few common types and core functionality that's useable by all other targets. + .target( + name: "DocCCommon", + dependencies: [ + // This target shouldn't have any local dependencies so that all other targets can depend on it. + // We can add dependencies on SymbolKit and Markdown here but they're not needed yet. + ], + swiftSettings: [.swiftLanguageMode(.v6)] + ), + + .testTarget( + name: "DocCCommonTests", + dependencies: [ + .target(name: "DocCCommon"), + .target(name: "SwiftDocCTestUtilities"), + ], + swiftSettings: [.swiftLanguageMode(.v6)] + ), // Test app for SwiftDocCUtilities .executableTarget( diff --git a/Sources/SwiftDocCUtilities/CMakeLists.txt b/Sources/CommandLine/CMakeLists.txt similarity index 100% rename from Sources/SwiftDocCUtilities/CMakeLists.txt rename to Sources/CommandLine/CMakeLists.txt diff --git a/Sources/SwiftDocC/Model/SourceLanguage.swift b/Sources/DocCCommon/SourceLanguage.swift similarity index 95% rename from Sources/SwiftDocC/Model/SourceLanguage.swift rename to Sources/DocCCommon/SourceLanguage.swift index 2866213456..4483219757 100644 --- a/Sources/SwiftDocC/Model/SourceLanguage.swift +++ b/Sources/DocCCommon/SourceLanguage.swift @@ -1,7 +1,7 @@ /* This source file is part of the Swift.org open source project - Copyright (c) 2021-2023 Apple Inc. and the Swift project authors + Copyright (c) 2021-2025 Apple Inc. and the Swift project authors Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information @@ -9,7 +9,7 @@ */ /// A programming language. -public struct SourceLanguage: Hashable, Codable, Comparable { +public struct SourceLanguage: Hashable, Codable, Comparable, Sendable { /// The display name of the programming language. public var name: String /// A globally unique identifier for the language. @@ -132,7 +132,7 @@ public struct SourceLanguage: Hashable, Codable, Comparable { public static let metal = SourceLanguage(name: "Metal", id: "metal") /// The list of programming languages that are known to DocC. - public static var knownLanguages: [SourceLanguage] = [.swift, .objectiveC, .javaScript, .data, .metal] + public static let knownLanguages: [SourceLanguage] = [.swift, .objectiveC, .javaScript, .data, .metal] enum CodingKeys: CodingKey { case name @@ -157,7 +157,9 @@ public struct SourceLanguage: Hashable, Codable, Comparable { try container.encode(self.name, forKey: SourceLanguage.CodingKeys.name) try container.encode(self.id, forKey: SourceLanguage.CodingKeys.id) - try container.encodeIfNotEmpty(self.idAliases, forKey: SourceLanguage.CodingKeys.idAliases) + if !self.idAliases.isEmpty { + try container.encode(self.idAliases, forKey: SourceLanguage.CodingKeys.idAliases) + } try container.encode(self.linkDisambiguationID, forKey: SourceLanguage.CodingKeys.linkDisambiguationID) } diff --git a/Sources/SwiftDocC/Utility/CommonTypeExports.swift b/Sources/SwiftDocC/Utility/CommonTypeExports.swift new file mode 100644 index 0000000000..7194a5c125 --- /dev/null +++ b/Sources/SwiftDocC/Utility/CommonTypeExports.swift @@ -0,0 +1,13 @@ +/* + This source file is part of the Swift.org open source project + + Copyright (c) 2025 Apple Inc. and the Swift project authors + Licensed under Apache License v2.0 with Runtime Library Exception + + See https://swift.org/LICENSE.txt for license information + See https://swift.org/CONTRIBUTORS.txt for Swift project authors +*/ + +public import DocCCommon + +public typealias SourceLanguage = DocCCommon.SourceLanguage diff --git a/Tests/SwiftDocCTests/Model/SourceLanguageTests.swift b/Tests/DocCCommonTests/SourceLanguageTests.swift similarity index 96% rename from Tests/SwiftDocCTests/Model/SourceLanguageTests.swift rename to Tests/DocCCommonTests/SourceLanguageTests.swift index 734c5c7a1d..d63b6dcaac 100644 --- a/Tests/SwiftDocCTests/Model/SourceLanguageTests.swift +++ b/Tests/DocCCommonTests/SourceLanguageTests.swift @@ -8,7 +8,7 @@ See https://swift.org/CONTRIBUTORS.txt for Swift project authors */ -@testable import SwiftDocC +import DocCCommon import XCTest class SourceLanguageTests: XCTestCase {