@@ -236,43 +236,61 @@ public struct ExplicitModuleBuildHandler {
236
236
commandLine. appendFlags ( " -disable-implicit-swift-modules " , " -Xcc " , " -Xclang " , " -Xcc " ,
237
237
" -fno-implicit-modules " )
238
238
var swiftDependencyArtifacts : [ SwiftModuleArtifactInfo ] = [ ]
239
- try addModuleDependencies ( moduleId: moduleId, pcmArgs: pcmArgs, inputs: & inputs,
240
- commandLine: & commandLine,
239
+ var clangDependencyArtifacts : [ ClangModuleArtifactInfo ] = [ ]
240
+ try addModuleDependencies ( moduleId: moduleId, pcmArgs: pcmArgs,
241
+ clangDependencyArtifacts: & clangDependencyArtifacts,
241
242
swiftDependencyArtifacts: & swiftDependencyArtifacts)
242
243
244
+ // Swift Module dependencies are passed encoded in a JSON file as described by
245
+ // SwiftModuleArtifactInfo
243
246
if !swiftDependencyArtifacts. isEmpty {
244
- let dependencyFile = try serializeModuleDependencies ( for : moduleId ,
245
- dependencyArtifacts: swiftDependencyArtifacts)
247
+ let dependencyFile =
248
+ try serializeModuleDependencies ( for : moduleId , dependencyArtifacts: swiftDependencyArtifacts)
246
249
commandLine. appendFlag ( " -explicit-swift-module-map-file " )
247
250
commandLine. appendPath ( dependencyFile)
248
251
inputs. append ( TypedVirtualPath ( file: try VirtualPath ( path: dependencyFile. pathString) ,
249
252
type: . jsonSwiftArtifacts) )
250
- // Each individual moduel binary is still an "input" to ensure the build system gets the
253
+ // Each individual module binary is still an "input" to ensure the build system gets the
251
254
// order correctly.
252
255
for dependencyModule in swiftDependencyArtifacts {
253
256
inputs. append ( TypedVirtualPath ( file: try VirtualPath ( path: dependencyModule. modulePath) ,
254
257
type: . swiftModule) )
255
258
}
256
259
}
260
+ // Clang module depenencies are specified on the command line eplicitly
261
+ for moduleArtifactInfo in clangDependencyArtifacts {
262
+ let clangModulePath =
263
+ TypedVirtualPath ( file: try VirtualPath ( path: moduleArtifactInfo. modulePath) ,
264
+ type: . pcm)
265
+ let clangModuleMapPath =
266
+ TypedVirtualPath ( file: try VirtualPath ( path: moduleArtifactInfo. moduleMapPath) ,
267
+ type: . clangModuleMap)
268
+ commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
269
+ " -fmodule-file= \( clangModulePath. file. description) " )
270
+ commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
271
+ " -fmodule-map-file= \( clangModuleMapPath. file. description) " )
272
+ inputs. append ( clangModulePath)
273
+ inputs. append ( clangModuleMapPath)
274
+ }
257
275
}
258
276
259
277
/// Add a specific module dependency as an input and a corresponding command
260
278
/// line flag. Dispatches to clang and swift-specific variants.
261
- mutating private func addModuleDependencies( moduleId: ModuleDependencyId ,
262
- pcmArgs: [ String ] ,
263
- inputs: inout [ TypedVirtualPath ] ,
264
- commandLine: inout [ Job . ArgTemplate ] ,
279
+ mutating private func addModuleDependencies( moduleId: ModuleDependencyId , pcmArgs: [ String ] ,
280
+ clangDependencyArtifacts: inout [ ClangModuleArtifactInfo ] ,
265
281
swiftDependencyArtifacts: inout [ SwiftModuleArtifactInfo ]
266
282
) throws {
267
283
for dependencyId in try dependencyGraph. moduleInfo ( of: moduleId) . directDependencies {
268
284
switch dependencyId {
269
285
case . swift:
270
286
try addSwiftModuleDependency ( moduleId: moduleId, dependencyId: dependencyId,
271
- pcmArgs: pcmArgs, inputs: & inputs, commandLine: & commandLine,
287
+ pcmArgs: pcmArgs,
288
+ clangDependencyArtifacts: & clangDependencyArtifacts,
272
289
swiftDependencyArtifacts: & swiftDependencyArtifacts)
273
290
case . clang:
274
291
try addClangModuleDependency ( moduleId: moduleId, dependencyId: dependencyId,
275
- pcmArgs: pcmArgs, inputs: & inputs, commandLine: & commandLine,
292
+ pcmArgs: pcmArgs,
293
+ clangDependencyArtifacts: & clangDependencyArtifacts,
276
294
swiftDependencyArtifacts: & swiftDependencyArtifacts)
277
295
}
278
296
}
@@ -285,8 +303,7 @@ public struct ExplicitModuleBuildHandler {
285
303
mutating private func addSwiftModuleDependency( moduleId: ModuleDependencyId ,
286
304
dependencyId: ModuleDependencyId ,
287
305
pcmArgs: [ String ] ,
288
- inputs: inout [ TypedVirtualPath ] ,
289
- commandLine: inout [ Job . ArgTemplate ] ,
306
+ clangDependencyArtifacts: inout [ ClangModuleArtifactInfo ] ,
290
307
swiftDependencyArtifacts: inout [ SwiftModuleArtifactInfo ]
291
308
) throws {
292
309
// Generate a build job for the dependency module, if not already generated
@@ -308,7 +325,7 @@ public struct ExplicitModuleBuildHandler {
308
325
309
326
// Process all transitive dependencies as direct
310
327
try addModuleDependencies ( moduleId: dependencyId, pcmArgs: pcmArgs,
311
- inputs : & inputs , commandLine : & commandLine ,
328
+ clangDependencyArtifacts : & clangDependencyArtifacts ,
312
329
swiftDependencyArtifacts: & swiftDependencyArtifacts)
313
330
}
314
331
@@ -319,8 +336,7 @@ public struct ExplicitModuleBuildHandler {
319
336
mutating private func addClangModuleDependency( moduleId: ModuleDependencyId ,
320
337
dependencyId: ModuleDependencyId ,
321
338
pcmArgs: [ String ] ,
322
- inputs: inout [ TypedVirtualPath ] ,
323
- commandLine: inout [ Job . ArgTemplate ] ,
339
+ clangDependencyArtifacts: inout [ ClangModuleArtifactInfo ] ,
324
340
swiftDependencyArtifacts: inout [ SwiftModuleArtifactInfo ]
325
341
) throws {
326
342
// Generate a build job for the dependency module at the given target, if not already generated
@@ -333,21 +349,17 @@ public struct ExplicitModuleBuildHandler {
333
349
let dependencyInfo = try dependencyGraph. moduleInfo ( of: dependencyId)
334
350
let dependencyClangModuleDetails = try dependencyGraph. clangModuleDetails ( of: dependencyId)
335
351
let clangModulePath =
336
- TypedVirtualPath ( file: try ExplicitModuleBuildHandler . targetEncodedClangModuleFilePath (
337
- for: dependencyInfo, pcmArgs: pcmArgs) , type: . pcm)
338
- let clangModuleMapPath =
339
- TypedVirtualPath ( file: try VirtualPath ( path: dependencyClangModuleDetails. moduleMapPath) ,
340
- type: . clangModuleMap)
341
- commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
342
- " -fmodule-map-file= \( clangModuleMapPath. file. description) " )
343
- commandLine. appendFlags ( " -Xcc " , " -Xclang " , " -Xcc " ,
344
- " -fmodule-file= \( clangModulePath. file. description) " )
345
- inputs. append ( clangModulePath)
346
- inputs. append ( clangModuleMapPath)
352
+ try ExplicitModuleBuildHandler . targetEncodedClangModuleFilePath ( for: dependencyInfo,
353
+ pcmArgs: pcmArgs)
354
+
355
+ // Collect the requried information about this module
356
+ clangDependencyArtifacts. append (
357
+ ClangModuleArtifactInfo ( name: dependencyId. moduleName, modulePath: clangModulePath. description,
358
+ moduleMapPath: dependencyClangModuleDetails. moduleMapPath) )
347
359
348
360
// Process all transitive dependencies as direct
349
361
try addModuleDependencies ( moduleId: dependencyId, pcmArgs: pcmArgs,
350
- inputs : & inputs , commandLine : & commandLine ,
362
+ clangDependencyArtifacts : & clangDependencyArtifacts ,
351
363
swiftDependencyArtifacts: & swiftDependencyArtifacts)
352
364
}
353
365
}
0 commit comments