@@ -75,4 +75,63 @@ class PackageModelTests: XCTestCase {
7575 " -sdk " , sdkDir. pathString,
7676 ] )
7777 }
78+
79+ func testWindowsLibrarianSelection( ) throws {
80+ // tiny PE binary from: https://archive.is/w01DO
81+ let contents : [ UInt8 ] = [
82+ 0x4d , 0x5a , 0x00 , 0x00 , 0x50 , 0x45 , 0x00 , 0x00 , 0x4c , 0x01 , 0x01 , 0x00 ,
83+ 0x6a , 0x2a , 0x58 , 0xc3 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
84+ 0x04 , 0x00 , 0x03 , 0x01 , 0x0b , 0x01 , 0x08 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 ,
85+ 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 , 0x0c , 0x00 , 0x00 , 0x00 ,
86+ 0x04 , 0x00 , 0x00 , 0x00 , 0x0c , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x40 , 0x00 ,
87+ 0x04 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 ,
88+ 0x00 , 0x00 , 0x00 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
89+ 0x68 , 0x00 , 0x00 , 0x00 , 0x64 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
90+ 0x02 ,
91+ ]
92+
93+ #if os(Windows)
94+ let suffix : String = " .exe "
95+ #else
96+ let suffix : String = " "
97+ #endif
98+
99+ let triple = try Triple ( " x86_64-unknown-windows-msvc " )
100+ let fs = TSCBasic . localFileSystem
101+
102+ try withTemporaryFile { [ contents] vfsPath in
103+ try withTemporaryDirectory ( removeTreeOnDeinit: true ) { [ contents] tmp in
104+ let bin = tmp. appending ( component: " bin " )
105+ try fs. createDirectory ( bin)
106+
107+ let lld = bin. appending ( component: " lld-link \( suffix) " )
108+ try fs. writeFileContents ( lld, bytes: ByteString ( contents) )
109+
110+ let not = bin. appending ( component: " not-a-linker \( suffix) " )
111+ try fs. writeFileContents ( not, bytes: ByteString ( contents) )
112+
113+ #if !os(Windows)
114+ try fs. chmod ( . executable, path: lld, options: [ ] )
115+ #endif
116+
117+ try XCTAssertEqual (
118+ UserToolchain . determineLibrarian (
119+ triple: triple, binDir: bin, useXcrun: false , environment: [ : ] , searchPaths: [ ] ,
120+ extraSwiftFlags: [ " -Xswiftc " , " -use-ld=lld " ] ) ,
121+ lld)
122+
123+ try XCTAssertEqual (
124+ UserToolchain . determineLibrarian (
125+ triple: triple, binDir: bin, useXcrun: false , environment: [ : ] , searchPaths: [ ] ,
126+ extraSwiftFlags: [ " -Xswiftc " , " -use-ld=not-a-link \( suffix) " ] ) ,
127+ not)
128+
129+ try XCTAssertEqual (
130+ UserToolchain . determineLibrarian (
131+ triple: triple, binDir: bin, useXcrun: false , environment: [ : ] , searchPaths: [ ] ,
132+ extraSwiftFlags: [ " -Xswiftc " , " -use-ld=not-a-link \( suffix) " ] ) ,
133+ AbsolutePath ( " link " ) )
134+ }
135+ }
136+ }
78137}
0 commit comments