@@ -4401,7 +4401,67 @@ final class SwiftDriverTests: XCTestCase {
4401
4401
}
4402
4402
#endif
4403
4403
4404
- // TODO: Windows
4404
+ for explicitUseLd in [ true , false ] {
4405
+ var args = [ " swiftc " , " -profile-generate " , " -target " , " x86_64-unknown-windows-msvc " , " test.swift " ]
4406
+ if explicitUseLd {
4407
+ // Explicitly passing '-use-ld=lld' should still result in '-lld-allow-duplicate-weak'.
4408
+ args. append ( " -use-ld=lld " )
4409
+ }
4410
+ var driver = try Driver ( args: args)
4411
+ let plannedJobs = try driver. planBuild ( )
4412
+ print ( plannedJobs [ 1 ] . commandLine)
4413
+
4414
+ XCTAssertEqual ( plannedJobs. count, 2 )
4415
+ XCTAssertEqual ( plannedJobs [ 0 ] . kind, . compile)
4416
+
4417
+ XCTAssertEqual ( plannedJobs [ 1 ] . kind, . link)
4418
+
4419
+ let linkCmds = plannedJobs [ 1 ] . commandLine
4420
+ XCTAssert ( linkCmds. contains ( . flag( " -include:__llvm_profile_runtime " ) ) )
4421
+ XCTAssert ( linkCmds. contains ( . flag( " -lclang_rt.profile " ) ) )
4422
+
4423
+ // rdar://131295678 - Make sure we force the use of lld and pass
4424
+ // '-lld-allow-duplicate-weak'.
4425
+ XCTAssert ( linkCmds. contains ( . flag( " -fuse-ld=lld " ) ) )
4426
+ XCTAssert ( linkCmds. contains ( [ . flag( " -Xlinker " ) , . flag( " -lld-allow-duplicate-weak " ) ] ) )
4427
+ }
4428
+
4429
+ do {
4430
+ // If the user passes -use-ld for a non-lld linker, respect that and
4431
+ // don't use '-lld-allow-duplicate-weak'
4432
+ var driver = try Driver ( args: [ " swiftc " , " -profile-generate " , " -use-ld=link " , " -target " , " x86_64-unknown-windows-msvc " , " test.swift " ] )
4433
+ let plannedJobs = try driver. planBuild ( )
4434
+ print ( plannedJobs [ 1 ] . commandLine)
4435
+
4436
+ XCTAssertEqual ( plannedJobs. count, 2 )
4437
+ XCTAssertEqual ( plannedJobs [ 0 ] . kind, . compile)
4438
+
4439
+ XCTAssertEqual ( plannedJobs [ 1 ] . kind, . link)
4440
+
4441
+ let linkCmds = plannedJobs [ 1 ] . commandLine
4442
+ XCTAssert ( linkCmds. contains ( . flag( " -include:__llvm_profile_runtime " ) ) )
4443
+ XCTAssert ( linkCmds. contains ( . flag( " -lclang_rt.profile " ) ) )
4444
+
4445
+ XCTAssertTrue ( linkCmds. contains ( . flag( " -fuse-ld=link " ) ) )
4446
+ XCTAssertFalse ( linkCmds. contains ( . flag( " -fuse-ld=lld " ) ) )
4447
+ XCTAssertFalse ( linkCmds. contains ( . flag( " -lld-allow-duplicate-weak " ) ) )
4448
+ }
4449
+
4450
+ do {
4451
+ // If we're not building for profiling, don't add '-lld-allow-duplicate-weak'.
4452
+ var driver = try Driver ( args: [ " swiftc " , " -use-ld=lld " , " -target " , " x86_64-unknown-windows-msvc " , " test.swift " ] )
4453
+ let plannedJobs = try driver. planBuild ( )
4454
+ print ( plannedJobs [ 1 ] . commandLine)
4455
+
4456
+ XCTAssertEqual ( plannedJobs. count, 2 )
4457
+ XCTAssertEqual ( plannedJobs [ 0 ] . kind, . compile)
4458
+
4459
+ XCTAssertEqual ( plannedJobs [ 1 ] . kind, . link)
4460
+
4461
+ let linkCmds = plannedJobs [ 1 ] . commandLine
4462
+ XCTAssertTrue ( linkCmds. contains ( . flag( " -fuse-ld=lld " ) ) )
4463
+ XCTAssertFalse ( linkCmds. contains ( . flag( " -lld-allow-duplicate-weak " ) ) )
4464
+ }
4405
4465
}
4406
4466
4407
4467
func testConditionalCompilationArgValidation( ) throws {
0 commit comments