@@ -12,6 +12,10 @@ import func POSIX.mkdir
12
12
import PackageType
13
13
import Utility
14
14
15
+
16
+ //FIXME messy :/
17
+
18
+
15
19
extension Command {
16
20
static func link( product: Product , configuration conf: Configuration , prefix: String , otherArgs: [ String ] ) throws -> Command {
17
21
@@ -25,11 +29,38 @@ extension Command {
25
29
26
30
let outpath = Path . join ( prefix, product. outname)
27
31
28
- var args = [ Toolchain . swiftc] + otherArgs
32
+ var args : [ String ]
33
+ switch product. type {
34
+ case . Library( . Dynamic) , . Executable, . Test:
35
+ args = [ Toolchain . swiftc] + otherArgs
36
+
37
+ if conf == . Debug {
38
+ args += [ " -g " ]
39
+ }
40
+ args += [ " -L \( prefix) " ]
41
+ args += [ " -o " , outpath]
42
+
43
+ case . Library( . Static) :
44
+ //FIXME proper static archive llbuild tool
45
+ //NOTE HACK this works because llbuild runs it with via a shell
46
+ //FIXME this is coincidental, do properly
47
+ args = [ " rm " , " -f " , outpath, " && " , " ar " , " cr " ]
48
+ }
49
+
50
+ let inputs = product. modules. flatMap { module -> [ String ] in
51
+ switch conf {
52
+ case . Debug:
53
+ let tool = SwiftcTool ( module: module, prefix: prefix, otherArgs: [ ] )
54
+ // must return tool’s outputs and inputs as shell nodes don't calculate more than that
55
+ return tool. inputs + tool. outputs
56
+ case . Release:
57
+ return objects
58
+ }
59
+ }
29
60
30
61
switch product. type {
31
62
case . Library( . Static) :
32
- fatalError ( " Unimplemented " )
63
+ args . append ( outpath )
33
64
case . Test:
34
65
#if os(OSX)
35
66
args += [ " -Xlinker " , " -bundle " ]
@@ -70,15 +101,14 @@ extension Command {
70
101
}
71
102
}
72
103
73
- if conf == . Debug {
74
- args += [ " -g " ]
75
- }
76
-
77
- args += [ " -L \( prefix) " ]
78
- args += [ " -o " , outpath]
79
104
args += objects
80
105
81
- let inputs = product. modules. flatMap { [ $0. targetName] + SwiftcTool( module: $0, prefix: prefix, otherArgs: [ ] ) . inputs }
106
+ if case . Library( . Static) = product. type {
107
+ //HACK we need to be executed passed-through to the shell
108
+ // otherwise we cannot do the rm -f first
109
+ //FIXME make a proper static archive tool for llbuild
110
+ args = [ args. joined ( separator: " " ) ] //TODO escape!
111
+ }
82
112
83
113
let shell = ShellTool (
84
114
description: " Linking \( outpath. prettyPath) " ,
0 commit comments