9
9
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10
10
//
11
11
//===----------------------------------------------------------------------===//
12
+ import Foundation
13
+ @_spi ( Testing) import SWBCore
14
+ import SWBProtocol
15
+ import SWBTestSupport
16
+ import SWBUtil
17
+ import Testing
18
+ import SWBMacro
12
19
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: [ " x86_64:x64 " , " aarch64:arm64 " , " i386:x86 " , " thumbv7:arm " ] )
50
+
51
+ // 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
+
64
+ // link aarch64
65
+ if try await core. hasVisualStudioComponent ( . visualCppBuildTools_arm64) {
66
+ table. push ( BuiltinMacros . ARCHS, literal: [ " aarch64 " ] )
67
+ try await withSpec ( LdLinkerSpec . self, . deferred, platform: " windows " , additionalTable: table) { ( info: DiscoveredLdLinkerToolSpecInfo ) in
68
+ #expect( !info. toolPath. isEmpty)
69
+ #expect( info. toolVersion != nil )
70
+ if let toolVersion = info. toolVersion {
71
+ #expect( toolVersion > Version ( 0 , 0 , 0 ) )
72
+ }
73
+ #expect( info. linker == . linkExe)
74
+ }
75
+ }
76
+ }
77
+ }
0 commit comments