Skip to content

Commit 3c82e60

Browse files
authored
Merge pull request #210 from tayloraswift/ssgc-macos
build stdlib on macOS
2 parents ce87f24 + f097b98 commit 3c82e60

File tree

6 files changed

+117
-57
lines changed

6 files changed

+117
-57
lines changed

.github/workflows/ci.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ jobs:
5151
- name: Checkout repository
5252
uses: actions/checkout@v3
5353

54-
- name: Build only
54+
- name: Build debug
5555
run: |
5656
swift --version
5757
swift build
58+
59+
- name: Build release
60+
run: |
61+
swift build -c release
62+
63+
- name: Test SymbolGraphBuilder
64+
run: |
65+
swift run -c release SymbolGraphBuilderTests

Sources/SymbolGraphBuilder/Builds/SSGC.SpecialBuild.swift

+82-44
Original file line numberDiff line numberDiff line change
@@ -24,54 +24,92 @@ extension SSGC.SpecialBuild:SSGC.DocumentationBuild
2424
with swift:SSGC.Toolchain) throws -> (SymbolGraphMetadata, SSGC.PackageSources)
2525
{
2626
// https://forums.swift.org/t/dependency-graph-of-the-standard-library-modules/59267
27-
let sources:[SSGC.NominalSources] =
28-
[
29-
// 0:
30-
.toolchain(module: "Swift"),
31-
// 1:
32-
.toolchain(module: "_Concurrency",
33-
dependencies: 0),
34-
// 2:
35-
.toolchain(module: "Distributed",
36-
dependencies: 0, 1),
27+
let sources:[SSGC.NominalSources]
28+
switch try swift.platform()
29+
{
30+
case .macOS:
31+
sources =
32+
[
33+
// 0:
34+
.toolchain(module: "Swift"),
35+
// 1:
36+
.toolchain(module: "_Concurrency",
37+
dependencies: 0),
38+
// 2:
39+
.toolchain(module: "Distributed",
40+
dependencies: 0, 1),
41+
42+
// 3:
43+
.toolchain(module: "_StringProcessing",
44+
dependencies: 0),
45+
// 4:
46+
.toolchain(module: "RegexBuilder",
47+
dependencies: 0, 3),
48+
49+
// 5:
50+
.toolchain(module: "Dispatch",
51+
dependencies: 0),
52+
// 6:
53+
.toolchain(module: "DispatchIntrospection",
54+
dependencies: 0),
55+
// 7:
56+
.toolchain(module: "Foundation",
57+
dependencies: 0, 5),
58+
]
3759

38-
// 3:
39-
.toolchain(module: "_Differentiation",
40-
dependencies: 0),
60+
case .linux:
61+
fallthrough
4162

42-
// 4:
43-
.toolchain(module: "_RegexParser",
44-
dependencies: 0),
45-
// 5:
46-
.toolchain(module: "_StringProcessing",
47-
dependencies: 0, 4),
48-
// 6:
49-
.toolchain(module: "RegexBuilder",
50-
dependencies: 0, 4, 5),
63+
default:
64+
sources =
65+
[
66+
// 0:
67+
.toolchain(module: "Swift"),
68+
// 1:
69+
.toolchain(module: "_Concurrency",
70+
dependencies: 0),
71+
// 2:
72+
.toolchain(module: "Distributed",
73+
dependencies: 0, 1),
74+
75+
// 3:
76+
.toolchain(module: "_Differentiation",
77+
dependencies: 0),
5178

52-
// 7:
53-
.toolchain(module: "Cxx",
54-
dependencies: 0),
79+
// 4:
80+
.toolchain(module: "_RegexParser",
81+
dependencies: 0),
82+
// 5:
83+
.toolchain(module: "_StringProcessing",
84+
dependencies: 0, 4),
85+
// 6:
86+
.toolchain(module: "RegexBuilder",
87+
dependencies: 0, 4, 5),
5588

56-
// 8:
57-
.toolchain(module: "Dispatch",
58-
dependencies: 0),
59-
// 9:
60-
.toolchain(module: "DispatchIntrospection",
61-
dependencies: 0),
62-
// 10:
63-
.toolchain(module: "Foundation",
64-
dependencies: 0, 8),
65-
// 11:
66-
.toolchain(module: "FoundationNetworking",
67-
dependencies: 0, 8, 10),
68-
// 12:
69-
.toolchain(module: "FoundationXML",
70-
dependencies: 0, 8, 10),
71-
// 12:
72-
.toolchain(module: "XCTest",
73-
dependencies: 0),
74-
]
89+
// 7:
90+
.toolchain(module: "Cxx",
91+
dependencies: 0),
92+
93+
// 8:
94+
.toolchain(module: "Dispatch",
95+
dependencies: 0),
96+
// 9:
97+
.toolchain(module: "DispatchIntrospection",
98+
dependencies: 0),
99+
// 10:
100+
.toolchain(module: "Foundation",
101+
dependencies: 0, 8),
102+
// 11:
103+
.toolchain(module: "FoundationNetworking",
104+
dependencies: 0, 8, 10),
105+
// 12:
106+
.toolchain(module: "FoundationXML",
107+
dependencies: 0, 8, 10),
108+
// 12:
109+
.toolchain(module: "XCTest",
110+
dependencies: 0),
111+
]
112+
}
75113

76114
let metadata:SymbolGraphMetadata = .swift(swift.version,
77115
commit: swift.commit,

Sources/SymbolGraphBuilder/Toolchains/SSGC.Toolchain.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,15 @@ extension SSGC.Toolchain
355355
"-skip-inherited-docs",
356356
]
357357

358-
if let swiftSDK:SSGC.AppleSDK = self.swiftSDK
358+
#if os(macOS)
359+
// On macOS, dumping symbols without specifying the SDK will always fail.
360+
// Therefore, we always provide a default SDK.
361+
let swiftSDK:SSGC.AppleSDK? = self.swiftSDK ?? .macOS
362+
#else
363+
let swiftSDK:SSGC.AppleSDK? = self.swiftSDK
364+
#endif
365+
366+
if let swiftSDK:SSGC.AppleSDK
359367
{
360368
arguments.append("-sdk")
361369
arguments.append(swiftSDK.path)

Sources/SymbolGraphBuilderTests/Main.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,15 @@ enum Main:TestMain, TestBattery
8080
docs.roundtrip(for: tests, in: workspace.artifacts)
8181
}
8282

83+
// https://github.com/tayloraswift/swift-unidoc/issues/211
84+
#if !os(macOS)
8385
if let tests:TestGroup = tests / "swift-nio",
8486
let docs:SymbolGraphObject<Void> = (tests.do
8587
{
8688
try workspace.build(package: try .remote(
8789
package: "swift-nio",
8890
from: "https://github.com/apple/swift-nio.git",
89-
at: "2.63.0",
91+
at: "2.65.0",
9092
in: workspace),
9193
with: toolchain)
9294
})
@@ -101,8 +103,8 @@ enum Main:TestMain, TestBattery
101103
])
102104

103105
docs.roundtrip(for: tests, in: workspace.artifacts)
104-
105106
}
107+
#endif
106108

107109
// SwiftNIO has lots of dependencies. If we can handle SwiftNIO,
108110
// we can handle anything!

Sources/SymbolGraphCompiler/Declarations/SSGC.DeclObject.swift

+12-8
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ extension SSGC
1818

1919
/// The type of the superforms tracked by ``\.value.superforms``.
2020
var superforms:(any SuperformRelationship.Type)?
21-
/// The symbol this scalar is lexically-nested in. This may
22-
/// be an extension block symbol.
23-
var scope:Symbol.USR?
21+
/// The symbols this scalar is lexically-nested in. This may include an extension block
22+
/// symbol.
23+
///
24+
/// Remarkably, it is possible for certain (Objective C) declarations to have more than
25+
/// one lexical parent. For example, base class methods can be shared by multiple
26+
/// subclasses in addition to the base class.
27+
var scopes:Set<Symbol.USR>
2428

2529
private(set)
2630
var value:Decl
@@ -35,7 +39,7 @@ extension SSGC
3539
self.culture = culture
3640

3741
self.superforms = nil
38-
self.scope = nil
42+
self.scopes = []
3943

4044
self.value = value
4145
}
@@ -77,16 +81,16 @@ extension SSGC.DeclObject
7781
throw SSGC.SemanticError.cannot(have: .scope, as: self.value.phylum)
7882
}
7983

80-
// It is okay to restate the exact same nesting relationship multiple times. This
81-
// sometimes happens when compiling C modules.
82-
if let scope:Symbol.USR = self.scope,
84+
// Only (Objective) C declarations can have multiple lexical scopes.
85+
if case .s = self.id.language,
86+
let scope:Symbol.USR = self.scopes.first,
8387
scope != relationship.scope
8488
{
8589
throw SSGC.SemanticError.already(has: .scope(scope))
8690
}
8791
else
8892
{
89-
self.scope = relationship.scope
93+
self.scopes.insert(relationship.scope)
9094
self.kinks += relationship.kinks
9195
}
9296

Sources/SymbolGraphCompiler/SSGC.TypeChecker.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ extension SSGC.TypeChecker
194194
// implementations that implement requirements from protocols in the current module.
195195
for decl:SSGC.DeclObject in others
196196
{
197-
guard case nil = decl.scope,
197+
guard decl.scopes.isEmpty,
198198
let parent:UnqualifiedPath = .init(decl.value.path.prefix),
199199
let parent:Symbol.Decl = protocols[parent]
200200
else

0 commit comments

Comments
 (0)