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