Commit 2d6a8f41 authored by Drew's avatar Drew

Basic support for emitting static libraries

See #6
parent 39eced64
Pipeline #663 passed with stage
......@@ -10,6 +10,7 @@ tasks:
tool: "atllbuild"
source: ["cli/src/**.swift", "parsers/yaml/**.swift"]
name: "atbuild"
outputType: "executable"
bootstrap-osx:
tool: "atllbuild"
......@@ -17,6 +18,7 @@ tasks:
name: "atbuild"
bootstrapOnly: true
llbuildyaml: "llbuild-osx.yaml"
outputType: "executable"
bootstrap-linux:
tool: "atllbuild"
......@@ -26,7 +28,14 @@ tasks:
llbuildyaml: "llbuild-linux.yaml"
linkSDK: false
compileOptions: ["-D","CORELIBS_FOUNDATION"]
outputType: "executable"
bootstrap:
tool: "nop"
dependency: ["bootstrap-osx", "bootstrap-linux"]
\ No newline at end of file
dependency: ["bootstrap-osx", "bootstrap-linux"]
yaml:
tool: "atllbuild"
source: ["parsers/yaml/**.swift"]
name: "yaml"
outputType: "static-library"
\ No newline at end of file
......@@ -12,6 +12,11 @@ import Foundation
For more information on this tool, see `docs/attllbuild.md` */
final class ATllbuild : Tool {
enum OutputType {
case Executable
case StaticLibrary
}
/**This function resolves wildcards in source descriptions to complete values
- parameter sourceDescriptions: a descriptions of sources such as ["src/**.swift"] */
- returns: A list of resolved sources such as ["src/a.swift", "src/b.swift"]
......@@ -41,7 +46,7 @@ final class ATllbuild : Tool {
- parameter workdir: A temporary working directory for `atllbuild` to use
- parameter modulename: The name of the module to be built.
- returns: The string contents for llbuild.yaml suitable for processing by swift-build-tool */
func llbuildyaml(sources: [String], workdir: String, modulename: String, linkSDK: Bool, compileOptions: [String]) -> String {
func llbuildyaml(sources: [String], workdir: String, modulename: String, linkSDK: Bool, compileOptions: [String], outputType: OutputType) -> String {
//this format is largely undocumented, but I reverse-engineered it from SwiftPM.
var yaml = "client:\n name: swift-build\n\n"
......@@ -70,7 +75,13 @@ final class ATllbuild : Tool {
var llbuild_outputs = ["<atllbuild-swiftc>"]
llbuild_outputs.appendContentsOf(objects)
yaml += " outputs: \(llbuild_outputs)\n"
switch(outputType) {
case .Executable:
break
case .StaticLibrary:
yaml += " is-library: true\n" //I have no idea what the effect of this is, but swiftPM does it, so I'm including it.
}
yaml += " module-name: \(modulename)\n"
yaml += " module-output-path: \(workdir + modulename).swiftmodule\n"
......@@ -88,18 +99,39 @@ final class ATllbuild : Tool {
//and this is the "link" command
yaml += " <atllbuild>:\n"
yaml += " tool: shell\n"
//this crazy syntax is how sbt declares a dependency
var llbuild_inputs = ["<atllbuild-swiftc>"]
llbuild_inputs.appendContentsOf(objects)
yaml += " inputs: \(llbuild_inputs)\n"
yaml += " outputs: [\"<atllbuild>\", \"\(workdir + modulename)\"]\n"
//and now we have the crazy 'args'
args = [SwiftCPath, "-o",workdir + modulename]
args.appendContentsOf(objects)
yaml += " args: \(args)\n"
yaml += " description: Linking executable \(modulename)\n"
switch(outputType) {
case .Executable:
yaml += " tool: shell\n"
//this crazy syntax is how sbt declares a dependency
var llbuild_inputs = ["<atllbuild-swiftc>"]
llbuild_inputs.appendContentsOf(objects)
yaml += " inputs: \(llbuild_inputs)\n"
yaml += " outputs: [\"<atllbuild>\", \"\(workdir + modulename)\"]\n"
//and now we have the crazy 'args'
args = [SwiftCPath, "-o",workdir + modulename]
args.appendContentsOf(objects)
yaml += " args: \(args)\n"
yaml += " description: Linking executable \(modulename)\n"
case .StaticLibrary:
yaml += " tool: shell\n"
var llbuild_inputs = ["<atllbuild-swiftc>"]
llbuild_inputs.appendContentsOf(objects)
yaml += " inputs: \(llbuild_inputs)\n"
let libPath = "\(workdir + modulename).a"
yaml += " outputs: [\"<atllbuild>\", \"\(libPath)\"]\n"
//build the crazy args, mostly consisting of an `ar` shell command
var shellCmd = "rm -rf \(libPath); ar cr '\(libPath)'"
for obj in objects {
shellCmd += " '\(obj)'"
}
let args = "[\"/bin/sh\",\"-c\",\(shellCmd)]"
yaml += " args: \(args)\n"
yaml += " description: \"Linking Library: \(libPath)\""
}
return yaml
}
......@@ -114,6 +146,17 @@ final class ATllbuild : Tool {
try manager.createDirectoryAtPath(workDirectory, withIntermediateDirectories: false, attributes: nil)
//parse arguments
let outputType: OutputType
if args["outputType"]?.string == "static-library" {
outputType = .StaticLibrary
}
else if args["outputType"]?.string == "executable" {
outputType = .Executable
}
else {
throw AnarchyBuildError.CantParseYaml("Unknown outputType \(args["outputType"])")
}
var compileOptions: [String] = []
if let opts = args["compileOptions"]?.array {
for o in opts {
......@@ -150,7 +193,7 @@ final class ATllbuild : Tool {
llbuildyamlpath = workDirectory + "llbuild.yaml"
}
try llbuildyaml(sources, workdir: workDirectory, modulename: name, linkSDK: sdk, compileOptions: compileOptions).writeToFile(llbuildyamlpath, atomically: false, encoding: NSUTF8StringEncoding)
try llbuildyaml(sources, workdir: workDirectory, modulename: name, linkSDK: sdk, compileOptions: compileOptions, outputType: outputType).writeToFile(llbuildyamlpath, atomically: false, encoding: NSUTF8StringEncoding)
if bootstrapOnly { return }
//now we try running sbt
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment