@@ -195,6 +195,11 @@ public final class ClangTargetBuildDescription {
195
195
public var clangTarget : ClangTarget {
196
196
return target. underlyingTarget as! ClangTarget
197
197
}
198
+
199
+ /// The tools version of the package that declared the target. This can
200
+ /// can be used to conditionalize semantically significant changes in how
201
+ /// a target is built.
202
+ public let toolsVersion : ToolsVersion
198
203
199
204
/// The build parameters.
200
205
let buildParameters : BuildParameters
@@ -249,11 +254,12 @@ public final class ClangTargetBuildDescription {
249
254
}
250
255
251
256
/// Create a new target description with target and build parameters.
252
- init ( target: ResolvedTarget , buildParameters: BuildParameters , fileSystem: FileSystem = localFileSystem, diagnostics: DiagnosticsEngine ) throws {
257
+ init ( target: ResolvedTarget , toolsVersion : ToolsVersion , buildParameters: BuildParameters , fileSystem: FileSystem = localFileSystem, diagnostics: DiagnosticsEngine ) throws {
253
258
assert ( target. underlyingTarget is ClangTarget , " underlying target type mismatch \( target) " )
254
259
self . fileSystem = fileSystem
255
260
self . diagnostics = diagnostics
256
261
self . target = target
262
+ self . toolsVersion = toolsVersion
257
263
self . buildParameters = buildParameters
258
264
self . tempsPath = buildParameters. buildPath. appending ( component: target. c99name + " .build " )
259
265
self . derivedSources = Sources ( paths: [ ] , root: tempsPath. appending ( component: " DerivedSources " ) )
@@ -472,6 +478,11 @@ public final class SwiftTargetBuildDescription {
472
478
/// The target described by this target.
473
479
public let target : ResolvedTarget
474
480
481
+ /// The tools version of the package that declared the target. This can
482
+ /// can be used to conditionalize semantically significant changes in how
483
+ /// a target is built.
484
+ public let toolsVersion : ToolsVersion
485
+
475
486
/// The build parameters.
476
487
let buildParameters : BuildParameters
477
488
@@ -555,6 +566,7 @@ public final class SwiftTargetBuildDescription {
555
566
/// Create a new target description with target and build parameters.
556
567
init (
557
568
target: ResolvedTarget ,
569
+ toolsVersion: ToolsVersion ,
558
570
buildParameters: BuildParameters ,
559
571
pluginInvocationResults: [ PluginInvocationResult ] = [ ] ,
560
572
prebuildCommandResults: [ PrebuildCommandResult ] = [ ] ,
@@ -564,6 +576,7 @@ public final class SwiftTargetBuildDescription {
564
576
) throws {
565
577
assert ( target. underlyingTarget is SwiftTarget , " underlying target type mismatch \( target) " )
566
578
self . target = target
579
+ self . toolsVersion = toolsVersion
567
580
self . buildParameters = buildParameters
568
581
// Unless mentioned explicitly, use the target type to determine if this is a test target.
569
582
self . isTestTarget = isTestTarget ?? ( target. type == . test)
@@ -1018,6 +1031,11 @@ public final class ProductBuildDescription {
1018
1031
/// The reference to the product.
1019
1032
public let product : ResolvedProduct
1020
1033
1034
+ /// The tools version of the package that declared the product. This can
1035
+ /// can be used to conditionalize semantically significant changes in how
1036
+ /// a target is built.
1037
+ public let toolsVersion : ToolsVersion
1038
+
1021
1039
/// The build parameters.
1022
1040
let buildParameters : BuildParameters
1023
1041
@@ -1067,9 +1085,10 @@ public final class ProductBuildDescription {
1067
1085
let diagnostics : DiagnosticsEngine
1068
1086
1069
1087
/// Create a build description for a product.
1070
- init ( product: ResolvedProduct , buildParameters: BuildParameters , fs: FileSystem , diagnostics: DiagnosticsEngine ) {
1088
+ init ( product: ResolvedProduct , toolsVersion : ToolsVersion , buildParameters: BuildParameters , fs: FileSystem , diagnostics: DiagnosticsEngine ) {
1071
1089
assert ( product. type != . library( . automatic) , " Automatic type libraries should not be described. " )
1072
1090
self . product = product
1091
+ self . toolsVersion = toolsVersion
1073
1092
self . buildParameters = buildParameters
1074
1093
self . fs = fs
1075
1094
self . diagnostics = diagnostics
@@ -1327,9 +1346,11 @@ public class BuildPlan {
1327
1346
// if test manifest exists, prefer that over test detection,
1328
1347
// this is designed as an escape hatch when test discovery is not appropriate
1329
1348
// and for backwards compatibility for projects that have existing test manifests (LinuxMain.swift)
1349
+ let toolsVersion = graph. package ( for: testProduct) ? . manifest. toolsVersion ?? . vNext
1330
1350
if let testManifestTarget = testProduct. testManifestTarget, !generate {
1331
1351
let desc = try SwiftTargetBuildDescription (
1332
1352
target: testManifestTarget,
1353
+ toolsVersion: toolsVersion,
1333
1354
buildParameters: buildParameters,
1334
1355
isTestTarget: true
1335
1356
)
@@ -1361,6 +1382,7 @@ public class BuildPlan {
1361
1382
1362
1383
let target = try SwiftTargetBuildDescription (
1363
1384
target: testManifestTarget,
1385
+ toolsVersion: toolsVersion,
1364
1386
buildParameters: buildParameters,
1365
1387
isTestTarget: true ,
1366
1388
testDiscoveryTarget: true
@@ -1403,18 +1425,24 @@ public class BuildPlan {
1403
1425
}
1404
1426
}
1405
1427
}
1428
+
1429
+ // Determine the appropriate tools version to use for the target.
1430
+ // This can affect what flags to pass and other semantics.
1431
+ let toolsVersion = graph. package ( for: target) ? . manifest. toolsVersion ?? . vNext
1406
1432
1407
1433
switch target. underlyingTarget {
1408
1434
case is SwiftTarget :
1409
1435
targetMap [ target] = try . swift( SwiftTargetBuildDescription (
1410
1436
target: target,
1437
+ toolsVersion: toolsVersion,
1411
1438
buildParameters: buildParameters,
1412
1439
pluginInvocationResults: pluginInvocationResults [ target] ?? [ ] ,
1413
1440
prebuildCommandResults: prebuildCommandResults [ target] ?? [ ] ,
1414
1441
fs: fileSystem) )
1415
1442
case is ClangTarget :
1416
1443
targetMap [ target] = try . clang( ClangTargetBuildDescription (
1417
1444
target: target,
1445
+ toolsVersion: toolsVersion,
1418
1446
buildParameters: buildParameters,
1419
1447
fileSystem: fileSystem,
1420
1448
diagnostics: diagnostics) )
@@ -1448,8 +1476,14 @@ public class BuildPlan {
1448
1476
// Create product description for each product we have in the package graph except
1449
1477
// for automatic libraries and plugins, because they don't produce any output.
1450
1478
for product in graph. allProducts where product. type != . library( . automatic) && product. type != . plugin {
1479
+
1480
+ // Determine the appropriate tools version to use for the product.
1481
+ // This can affect what flags to pass and other semantics.
1482
+ let toolsVersion = graph. package ( for: product) ? . manifest. toolsVersion ?? . vNext
1451
1483
productMap [ product] = ProductBuildDescription (
1452
- product: product, buildParameters: buildParameters,
1484
+ product: product,
1485
+ toolsVersion: toolsVersion,
1486
+ buildParameters: buildParameters,
1453
1487
fs: fileSystem,
1454
1488
diagnostics: diagnostics
1455
1489
)
0 commit comments