@@ -268,6 +268,32 @@ public struct BinaryArtifact {
268268 }
269269}
270270
271+ /// A structure representing a prebuilt library to be used instead of a source dependency
272+ public struct PrebuiltLibrary {
273+ /// The package reference.
274+ public let packageRef : PackageReference
275+
276+ /// The name of the binary target the artifact corresponds to.
277+ public let libraryName : String
278+
279+ /// The path to the extracted prebuilt artifacts
280+ public let path : AbsolutePath
281+
282+ /// The products in the library
283+ public let products : [ String ]
284+
285+ /// The C modules that need their includes directory added to the include path
286+ public let cModules : [ String ]
287+
288+ public init ( packageRef: PackageReference , libraryName: String , path: AbsolutePath , products: [ String ] , cModules: [ String ] ) {
289+ self . packageRef = packageRef
290+ self . libraryName = libraryName
291+ self . path = path
292+ self . products = products
293+ self . cModules = cModules
294+ }
295+ }
296+
271297/// Helper for constructing a package following the convention system.
272298///
273299/// The 'builder' here refers to the builder pattern and not any build system
@@ -295,6 +321,9 @@ public final class PackageBuilder {
295321 /// Information concerning the different downloaded or local (archived) binary target artifacts.
296322 private let binaryArtifacts : [ String : BinaryArtifact ]
297323
324+ /// Prebuilts that may referenced from this package's targets
325+ private let prebuilts : [ PackageIdentity : [ Product . ID : PrebuiltLibrary ] ]
326+
298327 /// Create multiple test products.
299328 ///
300329 /// If set to true, one test product will be created for each test target.
@@ -351,6 +380,7 @@ public final class PackageBuilder {
351380 path: AbsolutePath ,
352381 additionalFileRules: [ FileRuleDescription ] ,
353382 binaryArtifacts: [ String : BinaryArtifact ] ,
383+ prebuilts: [ PackageIdentity : [ String : PrebuiltLibrary ] ] ,
354384 shouldCreateMultipleTestProducts: Bool = false ,
355385 testEntryPointPath: AbsolutePath ? = nil ,
356386 warnAboutImplicitExecutableTargets: Bool = true ,
@@ -365,6 +395,7 @@ public final class PackageBuilder {
365395 self . packagePath = path
366396 self . additionalFileRules = additionalFileRules
367397 self . binaryArtifacts = binaryArtifacts
398+ self . prebuilts = prebuilts
368399 self . shouldCreateMultipleTestProducts = shouldCreateMultipleTestProducts
369400 self . testEntryPointPath = testEntryPointPath
370401 self . createREPLProduct = createREPLProduct
@@ -1211,6 +1242,33 @@ public final class PackageBuilder {
12111242 table. add ( assignment, for: . SWIFT_ACTIVE_COMPILATION_CONDITIONS)
12121243 }
12131244
1245+ // Add in flags for prebuilts
1246+ let prebuiltLibraries : [ String : PrebuiltLibrary ] = target. dependencies. reduce ( into: . init( ) ) {
1247+ guard case let . product( name: name, package : package , moduleAliases: _, condition: _) = $1,
1248+ let package = package ,
1249+ let prebuilt = prebuilts [ . plain( package ) ] ? [ name]
1250+ else {
1251+ return
1252+ }
1253+
1254+ $0 [ prebuilt. libraryName] = prebuilt
1255+ }
1256+
1257+ for prebuilt in prebuiltLibraries. values {
1258+ let lib = prebuilt. path. appending ( components: [ " lib " , " lib \( prebuilt. libraryName) .a " ] ) . pathString
1259+ var ldFlagsAssignment = BuildSettings . Assignment ( )
1260+ ldFlagsAssignment. values = [ lib]
1261+ table. add ( ldFlagsAssignment, for: . OTHER_LDFLAGS)
1262+
1263+ var includeDirs : [ AbsolutePath ] = [ prebuilt. path. appending ( component: " Modules " ) ]
1264+ for cModule in prebuilt. cModules {
1265+ includeDirs. append ( prebuilt. path. appending ( components: " include " , cModule) )
1266+ }
1267+ var includeAssignment = BuildSettings . Assignment ( )
1268+ includeAssignment. values = includeDirs. map ( { " -I \( $0. pathString) " } )
1269+ table. add ( includeAssignment, for: . OTHER_SWIFT_FLAGS)
1270+ }
1271+
12141272 return table
12151273 }
12161274
0 commit comments