@@ -4373,7 +4373,67 @@ final class SwiftDriverTests: XCTestCase {
4373
4373
}
4374
4374
#endif
4375
4375
4376
- // TODO: Windows
4376
+ for explicitUseLd in [ true , false ] {
4377
+ var args = [ " swiftc " , " -profile-generate " , " -target " , " x86_64-unknown-windows-msvc " , " test.swift " ]
4378
+ if explicitUseLd {
4379
+ // Explicitly passing '-use-ld=lld' should still result in '-lld-allow-duplicate-weak'.
4380
+ args. append ( " -use-ld=lld " )
4381
+ }
4382
+ var driver = try Driver ( args: args)
4383
+ let plannedJobs = try driver. planBuild ( )
4384
+ print ( plannedJobs [ 1 ] . commandLine)
4385
+
4386
+ XCTAssertEqual ( plannedJobs. count, 2 )
4387
+ XCTAssertEqual ( plannedJobs [ 0 ] . kind, . compile)
4388
+
4389
+ XCTAssertEqual ( plannedJobs [ 1 ] . kind, . link)
4390
+
4391
+ let linkCmds = plannedJobs [ 1 ] . commandLine
4392
+ XCTAssert ( linkCmds. contains ( . flag( " -include:__llvm_profile_runtime " ) ) )
4393
+ XCTAssert ( linkCmds. contains ( . flag( " -lclang_rt.profile " ) ) )
4394
+
4395
+ // rdar://131295678 - Make sure we force the use of lld and pass
4396
+ // '-lld-allow-duplicate-weak'.
4397
+ XCTAssert ( linkCmds. contains ( . flag( " -fuse-ld=lld " ) ) )
4398
+ XCTAssert ( linkCmds. contains ( [ . flag( " -Xlinker " ) , . flag( " -lld-allow-duplicate-weak " ) ] ) )
4399
+ }
4400
+
4401
+ do {
4402
+ // If the user passes -use-ld for a non-lld linker, respect that and
4403
+ // don't use '-lld-allow-duplicate-weak'
4404
+ var driver = try Driver ( args: [ " swiftc " , " -profile-generate " , " -use-ld=link " , " -target " , " x86_64-unknown-windows-msvc " , " test.swift " ] )
4405
+ let plannedJobs = try driver. planBuild ( )
4406
+ print ( plannedJobs [ 1 ] . commandLine)
4407
+
4408
+ XCTAssertEqual ( plannedJobs. count, 2 )
4409
+ XCTAssertEqual ( plannedJobs [ 0 ] . kind, . compile)
4410
+
4411
+ XCTAssertEqual ( plannedJobs [ 1 ] . kind, . link)
4412
+
4413
+ let linkCmds = plannedJobs [ 1 ] . commandLine
4414
+ XCTAssert ( linkCmds. contains ( . flag( " -include:__llvm_profile_runtime " ) ) )
4415
+ XCTAssert ( linkCmds. contains ( . flag( " -lclang_rt.profile " ) ) )
4416
+
4417
+ XCTAssertTrue ( linkCmds. contains ( . flag( " -fuse-ld=link " ) ) )
4418
+ XCTAssertFalse ( linkCmds. contains ( . flag( " -fuse-ld=lld " ) ) )
4419
+ XCTAssertFalse ( linkCmds. contains ( . flag( " -lld-allow-duplicate-weak " ) ) )
4420
+ }
4421
+
4422
+ do {
4423
+ // If we're not building for profiling, don't add '-lld-allow-duplicate-weak'.
4424
+ var driver = try Driver ( args: [ " swiftc " , " -use-ld=lld " , " -target " , " x86_64-unknown-windows-msvc " , " test.swift " ] )
4425
+ let plannedJobs = try driver. planBuild ( )
4426
+ print ( plannedJobs [ 1 ] . commandLine)
4427
+
4428
+ XCTAssertEqual ( plannedJobs. count, 2 )
4429
+ XCTAssertEqual ( plannedJobs [ 0 ] . kind, . compile)
4430
+
4431
+ XCTAssertEqual ( plannedJobs [ 1 ] . kind, . link)
4432
+
4433
+ let linkCmds = plannedJobs [ 1 ] . commandLine
4434
+ XCTAssertTrue ( linkCmds. contains ( . flag( " -fuse-ld=lld " ) ) )
4435
+ XCTAssertFalse ( linkCmds. contains ( . flag( " -lld-allow-duplicate-weak " ) ) )
4436
+ }
4377
4437
}
4378
4438
4379
4439
func testConditionalCompilationArgValidation( ) throws {
0 commit comments