@@ -1132,6 +1132,8 @@ final class SwiftDriverTests: XCTestCase {
1132
1132
1133
1133
do {
1134
1134
// static linking
1135
+ // Locating relevant libraries is dependent on being a macOS host
1136
+ #if os(macOS)
1135
1137
var driver = try Driver ( args: commonArgs + [ " -emit-library " , " -static " , " -L " , " /tmp " , " -Xlinker " , " -w " , " -target " , " x86_64-apple-macosx10.9 " , " -lto=llvm-full " ] , env: env)
1136
1138
let plannedJobs = try driver. planBuild ( )
1137
1139
@@ -1161,6 +1163,7 @@ final class SwiftDriverTests: XCTestCase {
1161
1163
XCTAssertFalse ( cmd. contains ( " -lto_library " ) )
1162
1164
XCTAssertFalse ( cmd. contains ( " -syslibroot " ) )
1163
1165
XCTAssertFalse ( cmd. contains ( " -no_objc_category_merging " ) )
1166
+ #endif
1164
1167
}
1165
1168
1166
1169
do {
@@ -1186,12 +1189,15 @@ final class SwiftDriverTests: XCTestCase {
1186
1189
1187
1190
do {
1188
1191
// lto linking
1192
+ // Locating relevant libraries is dependent on being a macOS host
1193
+ #if os(macOS)
1189
1194
var driver1 = try Driver ( args: commonArgs + [ " -emit-executable " , " -target " , " x86_64-apple-macosx10.15 " , " -lto=llvm-thin " ] , env: env)
1190
1195
let plannedJobs1 = try driver1. planBuild ( )
1191
1196
XCTAssertFalse ( plannedJobs1. contains ( where: { $0. kind == . autolinkExtract } ) )
1192
1197
let linkJob1 = plannedJobs1. first ( where: { $0. kind == . link } )
1193
1198
XCTAssertTrue ( linkJob1? . tool. name. contains ( " ld " ) )
1194
1199
XCTAssertTrue ( linkJob1? . commandLine. contains ( . flag( " -lto_library " ) ) )
1200
+ #endif
1195
1201
1196
1202
var driver2 = try Driver ( args: commonArgs + [ " -emit-executable " , " -target " , " x86_64-unknown-linux " , " -lto=llvm-thin " ] , env: env)
1197
1203
let plannedJobs2 = try driver2. planBuild ( )
@@ -1436,6 +1442,18 @@ final class SwiftDriverTests: XCTestCase {
1436
1442
}
1437
1443
}
1438
1444
1445
+ private func clangPathInActiveXcode( ) throws -> AbsolutePath ? {
1446
+ #if !os(macOS)
1447
+ return nil
1448
+ #endif
1449
+ let process = Process ( arguments: [ " xcrun " , " -toolchain " , " default " , " -f " , " clang " ] )
1450
+ try process. launch ( )
1451
+ let result = try process. waitUntilExit ( )
1452
+ guard result. exitStatus == . terminated( code: EXIT_SUCCESS) else { return nil }
1453
+ guard let path = String ( bytes: try result. output. get ( ) , encoding: . utf8) else { return nil }
1454
+ return path. isEmpty ? nil : AbsolutePath ( path. spm_chomp ( ) )
1455
+ }
1456
+
1439
1457
func testCompatibilityLibs( ) throws {
1440
1458
var env = ProcessEnv . vars
1441
1459
env [ " SWIFT_DRIVER_TESTS_ENABLE_EXEC_PATH_FALLBACK " ] = " 1 "
@@ -1537,6 +1555,30 @@ final class SwiftDriverTests: XCTestCase {
1537
1555
XCTAssertTrue ( cmd. contains ( subsequence: [ . flag( " -force_load " ) , . path( . absolute( path5_1iOS) ) ] ) )
1538
1556
XCTAssertTrue ( cmd. contains ( subsequence: [ . flag( " -force_load " ) , . path( . absolute( pathDynamicReplacementsiOS) ) ] ) )
1539
1557
}
1558
+
1559
+ // libarclite is only relevant on darwin
1560
+ #if os(macOS)
1561
+ do {
1562
+ // Override executive paths and make sure this does not affect the location of the found
1563
+ // libarclite
1564
+ env [ " SWIFT_DRIVER_SWIFTC_EXEC " ] = " /some/path/swiftc "
1565
+ env [ " SWIFT_DRIVER_CLANG_EXEC " ] = " /some/path/clang "
1566
+ guard let clangPathInXcode = try ? clangPathInActiveXcode ( ) else {
1567
+ throw XCTSkip ( )
1568
+ }
1569
+ let clangRelativeArcLite = clangPathInXcode. parentDirectory. parentDirectory
1570
+ . appending ( components: " lib " , " arc " , " libarclite_macosx.a " )
1571
+
1572
+ var driver = try Driver ( args: commonArgs + [ " -target " , " x86_64-apple-macosx10.9 " ] , env: env)
1573
+ let plannedJobs = try driver. planBuild ( )
1574
+
1575
+ XCTAssertEqual ( 3 , plannedJobs. count)
1576
+ let linkJob = plannedJobs [ 2 ]
1577
+ XCTAssertEqual ( linkJob. kind, . link)
1578
+ let cmd = linkJob. commandLine
1579
+ XCTAssertTrue ( cmd. contains ( subsequence: [ . flag( " -force_load " ) , . path( . absolute( clangRelativeArcLite) ) ] ) )
1580
+ }
1581
+ #endif
1540
1582
}
1541
1583
}
1542
1584
@@ -2341,7 +2383,10 @@ final class SwiftDriverTests: XCTestCase {
2341
2383
return
2342
2384
}
2343
2385
}
2386
+ // On non-darwin hosts, libArcLite won't be found and a warning will be emitted
2387
+ #if os(macOS)
2344
2388
try assertNoDriverDiagnostics ( args: " swiftc " , " -c " , " -target " , " x86_64-apple-macosx10.14 " , " -link-objc-runtime " , " foo.swift " )
2389
+ #endif
2345
2390
}
2346
2391
2347
2392
func testProfileArgValidation( ) throws {
@@ -3445,6 +3490,7 @@ final class SwiftDriverTests: XCTestCase {
3445
3490
}
3446
3491
3447
3492
func testLTOLibraryArg( ) throws {
3493
+ #if os(macOS)
3448
3494
do {
3449
3495
var driver = try Driver ( args: [ " swiftc " , " foo.swift " , " -lto=llvm-thin " , " -target " , " x86_64-apple-macos11.0 " ] )
3450
3496
let plannedJobs = try driver. planBuild ( )
@@ -3463,6 +3509,7 @@ final class SwiftDriverTests: XCTestCase {
3463
3509
XCTAssertEqual ( plannedJobs. map ( \. kind) , [ . compile, . link] )
3464
3510
XCTAssertFalse ( plannedJobs [ 1 ] . commandLine. contains ( " -lto_library " ) )
3465
3511
}
3512
+ #endif
3466
3513
}
3467
3514
3468
3515
func testBCasTopLevelOutput( ) throws {
0 commit comments