@@ -418,16 +418,42 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
418
418
}
419
419
}
420
420
421
- func makeBuildParameters( ) throws -> SwiftBuild . SWBBuildParameters {
422
- // Generate the run destination parameters.
423
- let runDestination = SwiftBuild . SWBRunDestinationInfo (
424
- platform: self . buildParameters. triple. osNameUnversioned,
425
- sdk: self . buildParameters. triple. osNameUnversioned,
426
- sdkVariant: nil ,
421
+ func makeRunDestination( ) -> SwiftBuild . SWBRunDestinationInfo {
422
+ let platformName : String
423
+ let sdkName : String
424
+ if self . buildParameters. triple. isAndroid ( ) {
425
+ // Android triples are identified by the environment part of the triple
426
+ platformName = " android "
427
+ sdkName = platformName
428
+ } else if self . buildParameters. triple. isWasm {
429
+ // Swift Build uses webassembly instead of wasi as the platform name
430
+ platformName = " webassembly "
431
+ sdkName = platformName
432
+ } else {
433
+ platformName = self . buildParameters. triple. darwinPlatform? . platformName ?? self . buildParameters. triple. osNameUnversioned
434
+ sdkName = platformName
435
+ }
436
+
437
+ let sdkVariant : String ?
438
+ if self . buildParameters. triple. environment == . macabi {
439
+ sdkVariant = " iosmac "
440
+ } else {
441
+ sdkVariant = nil
442
+ }
443
+
444
+ return SwiftBuild . SWBRunDestinationInfo (
445
+ platform: platformName,
446
+ sdk: sdkName,
447
+ sdkVariant: sdkVariant,
427
448
targetArchitecture: buildParameters. triple. archName,
428
449
supportedArchitectures: [ ] ,
429
450
disableOnlyActiveArch: false
430
451
)
452
+ }
453
+
454
+ func makeBuildParameters( ) throws -> SwiftBuild . SWBBuildParameters {
455
+ // Generate the run destination parameters.
456
+ let runDestination = makeRunDestination ( )
431
457
432
458
var verboseFlag : [ String ] = [ ]
433
459
if self . logLevel == . debug {
@@ -444,6 +470,18 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
444
470
// FIXME: workaround for old Xcode installations such as what is in CI
445
471
settings [ " LM_SKIP_METADATA_EXTRACTION " ] = " YES "
446
472
473
+ let normalizedTriple = Triple ( buildParameters. triple. triple, normalizing: true )
474
+ if let deploymentTargetSettingName = normalizedTriple. deploymentTargetSettingName {
475
+ let value = normalizedTriple. deploymentTargetVersion
476
+
477
+ // Only override the deployment target if a version is explicitly specified;
478
+ // for Apple platforms this normally comes from the package manifest and may
479
+ // not be set to the same value for all packages in the package graph.
480
+ if value != . zero {
481
+ settings [ deploymentTargetSettingName] = value. description
482
+ }
483
+ }
484
+
447
485
settings [ " LIBRARY_SEARCH_PATHS " ] = try " $(inherited) \( buildParameters. toolchain. toolchainLibDir. pathString) "
448
486
settings [ " OTHER_CFLAGS " ] = (
449
487
[ " $(inherited) " ]
@@ -562,3 +600,41 @@ fileprivate extension SwiftBuild.SwiftBuildMessage.DiagnosticInfo.Location {
562
600
}
563
601
}
564
602
}
603
+
604
+ fileprivate extension Triple {
605
+ var deploymentTargetSettingName : String ? {
606
+ switch ( self . os, self . environment) {
607
+ case ( . macosx, _) :
608
+ return " MACOSX_DEPLOYMENT_TARGET "
609
+ case ( . ios, _) :
610
+ return " IPHONEOS_DEPLOYMENT_TARGET "
611
+ case ( . tvos, _) :
612
+ return " TVOS_DEPLOYMENT_TARGET "
613
+ case ( . watchos, _) :
614
+ return " WATCHOS_DEPLOYMENT_TARGET "
615
+ case ( _, . android) :
616
+ return " ANDROID_DEPLOYMENT_TARGET "
617
+ default :
618
+ return nil
619
+ }
620
+ }
621
+
622
+ var deploymentTargetVersion : Version {
623
+ if isAndroid ( ) {
624
+ // Android triples store the version in the environment
625
+ var environmentName = self . environmentName [ ... ]
626
+ if environment != nil {
627
+ let prefixes = [ " androideabi " , " android " ]
628
+ for prefix in prefixes {
629
+ if environmentName. hasPrefix ( prefix) {
630
+ environmentName = environmentName. dropFirst ( prefix. count)
631
+ break
632
+ }
633
+ }
634
+ }
635
+
636
+ return Version ( parse: environmentName)
637
+ }
638
+ return osVersion
639
+ }
640
+ }
0 commit comments