99// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010//
1111//===----------------------------------------------------------------------===//
12+ import Foundation
13+ @_spi ( Testing) import SWBCore
14+ import SWBProtocol
15+ import SWBTestSupport
16+ import SWBUtil
17+ import Testing
18+ import SWBMacro
1219
20+ @Suite fileprivate struct CommandLineToolSpecDiscoveredInfoTests : CoreBasedTests {
21+ // Linker tool discovery is a bit more complex as it afffected by the ALTERNATE_LINKER build setting.
22+ func ldMacroTable( ) async throws -> MacroValueAssignmentTable {
23+ let core = try await getCore ( )
24+ return MacroValueAssignmentTable ( namespace: core. specRegistry. internalMacroNamespace)
25+ }
26+
27+ @Test ( . requireSDKs( . windows) )
28+ func discoveredLdLinkerSpecInfo_Windows( ) async throws {
29+ var table = try await ldMacroTable ( )
30+ let core = try await getCore ( )
31+ table. push ( BuiltinMacros . _LD_MULTIARCH, literal: true )
32+ try await withSpec ( LdLinkerSpec . self, . deferred, platform: " windows " , additionalTable: table) { ( info: DiscoveredLdLinkerToolSpecInfo ) in
33+ #expect( !info. toolPath. isEmpty)
34+ #expect( info. toolVersion != nil )
35+ if let toolVersion = info. toolVersion {
36+ #expect( toolVersion > Version ( 0 , 0 , 0 ) )
37+ }
38+ #expect( info. linker == . lld)
39+ }
40+ try await withSpec ( LdLinkerSpec . self, . result( status: . exit( 0 ) , stdout: Data ( " Microsoft (R) Incremental Linker Version 14.41.34120.0 \n " . utf8) , stderr: Data ( ) ) , platform: " windows " , additionalTable: table) { ( info: DiscoveredLdLinkerToolSpecInfo ) in
41+ #expect( !info. toolPath. isEmpty)
42+ #expect( info. toolVersion == Version ( 14 , 41 , 34120 ) )
43+ #expect( info. architectures == Set ( ) )
44+ }
45+
46+ // link.exe cannot be used for multipler architectures and requires a distinct link.exe for each target architecture
47+ table. push ( BuiltinMacros . ALTERNATE_LINKER, literal: " link " )
48+ table. push ( BuiltinMacros . _LD_MULTIARCH, literal: false )
49+ table. push ( BuiltinMacros . _LD_MULTIARCH_PREFIX_MAP, literal: [ " aarch64:arm64 " , " arm64ec:arm64 " , " armv7:arm " , " x86_64:x64 " , " i686:x86 " ] )
50+
51+ // link x86_64
52+ if try await core. hasVisualStudioComponent ( . visualCppBuildTools_x86_x64) {
53+ table. push ( BuiltinMacros . ARCHS, literal: [ " x86_64 " ] )
54+ try await withSpec ( LdLinkerSpec . self, . deferred, platform: " windows " , additionalTable: table) { ( info: DiscoveredLdLinkerToolSpecInfo ) in
55+ #expect( !info. toolPath. isEmpty)
56+ #expect( info. toolVersion != nil )
57+ if let toolVersion = info. toolVersion {
58+ #expect( toolVersion > Version ( 0 , 0 , 0 ) )
59+ }
60+ #expect( info. linker == . linkExe)
61+ }
62+ }
63+ // link i686
64+ if try await core. hasVisualStudioComponent ( . visualCppBuildTools_x86_x64) {
65+ table. push ( BuiltinMacros . ARCHS, literal: [ " i686 " ] )
66+ try await withSpec ( LdLinkerSpec . self, . deferred, platform: " windows " , additionalTable: table) { ( info: DiscoveredLdLinkerToolSpecInfo ) in
67+ #expect( !info. toolPath. isEmpty)
68+ #expect( info. toolVersion != nil )
69+ if let toolVersion = info. toolVersion {
70+ #expect( toolVersion > Version ( 0 , 0 , 0 ) )
71+ }
72+ #expect( info. linker == . linkExe)
73+ }
74+ }
75+ // link aarch64
76+ if try await core. hasVisualStudioComponent ( . visualCppBuildTools_arm64) {
77+ table. push ( BuiltinMacros . ARCHS, literal: [ " aarch64 " ] )
78+ try await withSpec ( LdLinkerSpec . self, . deferred, platform: " windows " , additionalTable: table) { ( info: DiscoveredLdLinkerToolSpecInfo ) in
79+ #expect( !info. toolPath. isEmpty)
80+ #expect( info. toolVersion != nil )
81+ if let toolVersion = info. toolVersion {
82+ #expect( toolVersion > Version ( 0 , 0 , 0 ) )
83+ }
84+ #expect( info. linker == . linkExe)
85+ }
86+ }
87+ // link armv7
88+ if try await core. hasVisualStudioComponent ( . visualCppBuildTools_arm) {
89+ table. push ( BuiltinMacros . ARCHS, literal: [ " armv7 " ] )
90+ try await withSpec ( LdLinkerSpec . self, . deferred, platform: " windows " , additionalTable: table) { ( info: DiscoveredLdLinkerToolSpecInfo ) in
91+ #expect( !info. toolPath. isEmpty)
92+ #expect( info. toolVersion != nil )
93+ if let toolVersion = info. toolVersion {
94+ #expect( toolVersion > Version ( 0 , 0 , 0 ) )
95+ }
96+ #expect( info. linker == . linkExe)
97+ }
98+ }
99+ // link arm64ec
100+ if try await core. hasVisualStudioComponent ( . visualCppBuildTools_arm64ec) {
101+ table. push ( BuiltinMacros . ARCHS, literal: [ " arm64ec " ] )
102+ try await withSpec ( LdLinkerSpec . self, . deferred, platform: " windows " , additionalTable: table) { ( info: DiscoveredLdLinkerToolSpecInfo ) in
103+ #expect( !info. toolPath. isEmpty)
104+ #expect( info. toolVersion != nil )
105+ if let toolVersion = info. toolVersion {
106+ #expect( toolVersion > Version ( 0 , 0 , 0 ) )
107+ }
108+ #expect( info. linker == . linkExe)
109+ }
110+ }
111+ }
112+ }
0 commit comments