Skip to content

Commit 287b954

Browse files
committed
Allow static library products
1 parent 53faa91 commit 287b954

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

Sources/Build/Command.link().swift

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import func POSIX.mkdir
1212
import PackageType
1313
import Utility
1414

15+
16+
//FIXME messy :/
17+
18+
1519
extension Command {
1620
static func link(product: Product, configuration conf: Configuration, prefix: String, otherArgs: [String]) throws -> Command {
1721

@@ -25,11 +29,38 @@ extension Command {
2529

2630
let outpath = Path.join(prefix, product.outname)
2731

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+
}
2960

3061
switch product.type {
3162
case .Library(.Static):
32-
fatalError("Unimplemented")
63+
args.append(outpath)
3364
case .Test:
3465
#if os(OSX)
3566
args += ["-Xlinker", "-bundle"]
@@ -70,15 +101,14 @@ extension Command {
70101
}
71102
}
72103

73-
if conf == .Debug {
74-
args += ["-g"]
75-
}
76-
77-
args += ["-L\(prefix)"]
78-
args += ["-o", outpath]
79104
args += objects
80105

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+
}
82112

83113
let shell = ShellTool(
84114
description: "Linking \(outpath.prettyPath)",

Sources/Build/ToolProtocol.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,21 @@ struct ShellTool: ToolProtocol {
2525
}
2626

2727
var YAMLDescription: String {
28+
let args: String
29+
if self.args.count == 1 {
30+
// if one argument is specified we assume pre-escaped and have
31+
// llbuild execute it passed through to the shell
32+
args = self.args.first!
33+
} else {
34+
args = self.args.YAML
35+
}
36+
2837
var yaml = ""
2938
yaml += " tool: " + name.YAML + "\n"
3039
yaml += " description: " + description.YAML + "\n"
3140
yaml += " inputs: " + inputs.YAML + "\n"
3241
yaml += " outputs: " + outputs.YAML + "\n"
33-
yaml += " args: " + args.YAML + "\n"
42+
yaml += " args: " + args + "\n"
3443
return yaml
3544
}
3645

0 commit comments

Comments
 (0)