Commit 94047266 authored by Drew's avatar Drew

(sorta) self-hosting

parent 330cc621
//
// PlatformPaths.swift
// AnarchyToolsXcode
//
// Created by Drew Crawford on 1/13/16.
// Copyright © 2016 Drew Crawford. All rights reserved.
//
import Foundation
//todo, support multiple toolchains
#if os(OSX)
let SDKPath = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk"
let SwiftCPath = "/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swiftc"
let SwiftBuildToolpath = "/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swift-build-tool"
#endif
\ No newline at end of file
......@@ -33,17 +33,17 @@ final class ATllbuild : Tool {
yaml += " \"\": [<atllbuild>]\n"
yaml += " atllbuild: [<atllbuild>]\n"
//this is the "compile" command
yaml += "commands:\n"
yaml += " <atllbuild-swiftc>:\n"
yaml += " tool: swift-compiler\n"
#if os(OSX)
yaml += " executable: \"/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swiftc\"\n"
yaml += " executable: \"\(SwiftCPath)\"\n"
#else
Unsupported!
#endif
yaml += " inputs: \(sources)\n"
yaml += " outputs: [<atllbuild>]\n"
yaml += " sources: \(sources)\n"
//swiftPM wants "objects" which is just a list of %.swift.o files. We have to put them in a temp directory though.
......@@ -51,17 +51,38 @@ final class ATllbuild : Tool {
workdir + (source as NSString).lastPathComponent + ".o"
}
yaml += " objects: \(objects)\n"
//this crazy syntax is how llbuild specifies outputs
var llbuild_outputs = ["<atllbuild-swiftc>"]
llbuild_outputs.appendContentsOf(objects)
yaml += " outputs: \(llbuild_outputs)\n"
yaml += " module-name: \(modulename)\n"
yaml += " module-output-path: \(workdir + modulename).swiftmodule\n"
yaml += " temps-path: \(workdir)/llbuildtmp\n"
var args : [String] = []
#if os(OSX)
args.appendContentsOf(["-j8","-sdk","/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk"])
args.appendContentsOf(["-j8","-sdk",SDKPath])
#endif
yaml += " other-args: \(args)\n"
//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"
return yaml
}
......@@ -84,14 +105,11 @@ final class ATllbuild : Tool {
try llbuildyaml(sources, workdir: workDirectory, modulename: name).writeToFile(llbuildyamlpath, atomically: false, encoding: NSUTF8StringEncoding)
//now we try running sbt
//todo: don't hardcode this
let sbtpath : String
#if os(OSX)
sbtpath = "/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swift-build-tool"
#else
Unsupported!
#endif
let sbt = NSTask.launchedTaskWithLaunchPath(sbtpath, arguments: ["-f",llbuildyamlpath])
let args = ["-f",llbuildyamlpath]
let sbt = NSTask.launchedTaskWithLaunchPath(SwiftBuildToolpath, arguments: args)
sbt.waitUntilExit()
if sbt.terminationStatus != 0 {
throw AnarchyBuildError.ExternalToolFailed("\(SwiftBuildToolpath) " + args.joinWithSeparator(" "))
}
}
}
\ No newline at end of file
......@@ -2,4 +2,5 @@ import Foundation
enum AnarchyBuildError : ErrorType {
case CantParseYaml(String)
case ExternalToolFailed(String)
}
\ No newline at end of file
......@@ -19,6 +19,7 @@
3AED49951C467C2300AC56A8 /* Tools.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AED49941C467C2300AC56A8 /* Tools.swift */; };
3AED49971C467C4400AC56A8 /* Shell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AED49961C467C4400AC56A8 /* Shell.swift */; };
3AED49991C4681F600AC56A8 /* atllbuild.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AED49981C4681F600AC56A8 /* atllbuild.swift */; };
3AED499B1C46923A00AC56A8 /* PlatformPaths.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AED499A1C46923A00AC56A8 /* PlatformPaths.swift */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
......@@ -47,6 +48,7 @@
3AED49941C467C2300AC56A8 /* Tools.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Tools.swift; path = ../src/Tools.swift; sourceTree = SOURCE_ROOT; };
3AED49961C467C4400AC56A8 /* Shell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Shell.swift; path = ../src/Shell.swift; sourceTree = SOURCE_ROOT; };
3AED49981C4681F600AC56A8 /* atllbuild.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = atllbuild.swift; path = ../src/atllbuild.swift; sourceTree = SOURCE_ROOT; };
3AED499A1C46923A00AC56A8 /* PlatformPaths.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PlatformPaths.swift; path = ../src/PlatformPaths.swift; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -86,6 +88,7 @@
3AED49941C467C2300AC56A8 /* Tools.swift */,
3AED49961C467C4400AC56A8 /* Shell.swift */,
3AED49981C4681F600AC56A8 /* atllbuild.swift */,
3AED499A1C46923A00AC56A8 /* PlatformPaths.swift */,
);
path = AnarchyToolsXcode;
sourceTree = "<group>";
......@@ -162,6 +165,7 @@
buildActionMask = 2147483647;
files = (
3AE6852B1C466DC400444852 /* main.swift in Sources */,
3AED499B1C46923A00AC56A8 /* PlatformPaths.swift in Sources */,
3AED498C1C466DFD00AC56A8 /* Tokenizer.swift in Sources */,
3AED49951C467C2300AC56A8 /* Tools.swift in Sources */,
3AED498B1C466DFD00AC56A8 /* Result.swift in Sources */,
......
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