@@ -449,16 +449,42 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
449
449
}
450
450
}
451
451
452
- func makeBuildParameters( ) throws -> SwiftBuild . SWBBuildParameters {
453
- // Generate the run destination parameters.
454
- let runDestination = SwiftBuild . SWBRunDestinationInfo (
455
- platform: self . buildParameters. triple. osNameUnversioned,
456
- sdk: self . buildParameters. triple. osNameUnversioned,
457
- sdkVariant: nil ,
452
+ func makeRunDestination( ) -> SwiftBuild . SWBRunDestinationInfo {
453
+ let platformName : String
454
+ let sdkName : String
455
+ if self . buildParameters. triple. isAndroid ( ) {
456
+ // Android triples are identified by the environment part of the triple
457
+ platformName = " android "
458
+ sdkName = platformName
459
+ } else if self . buildParameters. triple. isWasm {
460
+ // Swift Build uses webassembly instead of wasi as the platform name
461
+ platformName = " webassembly "
462
+ sdkName = platformName
463
+ } else {
464
+ platformName = self . buildParameters. triple. darwinPlatform? . platformName ?? self . buildParameters. triple. osNameUnversioned
465
+ sdkName = platformName
466
+ }
467
+
468
+ let sdkVariant : String ?
469
+ if self . buildParameters. triple. environment == . macabi {
470
+ sdkVariant = " iosmac "
471
+ } else {
472
+ sdkVariant = nil
473
+ }
474
+
475
+ return SwiftBuild . SWBRunDestinationInfo (
476
+ platform: platformName,
477
+ sdk: sdkName,
478
+ sdkVariant: sdkVariant,
458
479
targetArchitecture: buildParameters. triple. archName,
459
480
supportedArchitectures: [ ] ,
460
481
disableOnlyActiveArch: false
461
482
)
483
+ }
484
+
485
+ func makeBuildParameters( ) throws -> SwiftBuild . SWBBuildParameters {
486
+ // Generate the run destination parameters.
487
+ let runDestination = makeRunDestination ( )
462
488
463
489
var verboseFlag : [ String ] = [ ]
464
490
if self . logLevel == . debug {
@@ -475,6 +501,18 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
475
501
// FIXME: workaround for old Xcode installations such as what is in CI
476
502
settings [ " LM_SKIP_METADATA_EXTRACTION " ] = " YES "
477
503
504
+ let normalizedTriple = Triple ( buildParameters. triple. triple, normalizing: true )
505
+ if let deploymentTargetSettingName = normalizedTriple. deploymentTargetSettingName {
506
+ let value = normalizedTriple. deploymentTargetVersion
507
+
508
+ // Only override the deployment target if a version is explicitly specified;
509
+ // for Apple platforms this normally comes from the package manifest and may
510
+ // not be set to the same value for all packages in the package graph.
511
+ if value != . zero {
512
+ settings [ deploymentTargetSettingName] = value. description
513
+ }
514
+ }
515
+
478
516
settings [ " LIBRARY_SEARCH_PATHS " ] = try " $(inherited) \( buildParameters. toolchain. toolchainLibDir. pathString) "
479
517
settings [ " OTHER_CFLAGS " ] = (
480
518
[ " $(inherited) " ]
@@ -593,3 +631,41 @@ fileprivate extension SwiftBuild.SwiftBuildMessage.DiagnosticInfo.Location {
593
631
}
594
632
}
595
633
}
634
+
635
+ fileprivate extension Triple {
636
+ var deploymentTargetSettingName : String ? {
637
+ switch ( self . os, self . environment) {
638
+ case ( . macosx, _) :
639
+ return " MACOSX_DEPLOYMENT_TARGET "
640
+ case ( . ios, _) :
641
+ return " IPHONEOS_DEPLOYMENT_TARGET "
642
+ case ( . tvos, _) :
643
+ return " TVOS_DEPLOYMENT_TARGET "
644
+ case ( . watchos, _) :
645
+ return " WATCHOS_DEPLOYMENT_TARGET "
646
+ case ( _, . android) :
647
+ return " ANDROID_DEPLOYMENT_TARGET "
648
+ default :
649
+ return nil
650
+ }
651
+ }
652
+
653
+ var deploymentTargetVersion : Version {
654
+ if isAndroid ( ) {
655
+ // Android triples store the version in the environment
656
+ var environmentName = self . environmentName [ ... ]
657
+ if environment != nil {
658
+ let prefixes = [ " androideabi " , " android " ]
659
+ for prefix in prefixes {
660
+ if environmentName. hasPrefix ( prefix) {
661
+ environmentName = environmentName. dropFirst ( prefix. count)
662
+ break
663
+ }
664
+ }
665
+ }
666
+
667
+ return Version ( parse: environmentName)
668
+ }
669
+ return osVersion
670
+ }
671
+ }
0 commit comments