Skip to content
Permalink
Browse files
Add -Xswiftc for passing args to swiftc
Like our -Xcc and -Xlinker flags, -Xswiftc is only allowed on the command line and not part of Package.swift in an effort to prevent CMake/Autotools like developer hells.

Strictly we add these flags so developers can work around issues, but they also should report a bug so that we can provide a proper solution for their needs.
  • Loading branch information
mxcl committed Feb 20, 2016
1 parent 6b8ec91 commit d04ca88
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
@@ -16,7 +16,7 @@ import Utility
/**
- Returns: path to generated YAML for consumption by the llbuild based swift-build-tool
*/
public func describe(prefix: String, _ conf: Configuration, _ modules: [Module], _ products: [Product], Xcc: [String], Xld: [String]) throws -> String {
public func describe(prefix: String, _ conf: Configuration, _ modules: [Module], _ products: [Product], Xcc: [String], Xld: [String], Xswiftc: [String]) throws -> String {

guard modules.count > 0 else {
fatalError("No modules input") //TODO throw
@@ -41,9 +41,12 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],

var mkdirs = Set<String>()


let swiftcArgs = Xcc + Xswiftc

for case let module as SwiftModule in modules {

let otherArgs = Xcc + module.Xcc + platformArgs() + [conf.define]
let otherArgs = swiftcArgs + module.Xcc + platformArgs() + [conf.define]

switch conf {
case .Debug:
@@ -83,7 +86,7 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],

case .Release:
let inputs = module.dependencies.map{ $0.targetName } + module.sources.paths
var args = ["-c", "-emit-module", "-D", "SWIFT_PACKAGE", "-O", "-whole-module-optimization", "-I", prefix]
var args = ["-c", "-emit-module", "-D", "SWIFT_PACKAGE", "-O", "-whole-module-optimization", "-I", prefix] + swiftcArgs
let productPath = Path.join(prefix, "\(module.c99name).o")

if module.isLibrary {
@@ -117,7 +120,7 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],
objects = product.buildables.flatMap{ return IncrementalNode(module: $0, prefix: prefix).objectPaths }
}

var args = [Resources.path.swiftc]
var args = [Resources.path.swiftc] + swiftcArgs

switch product.type {
case .Library(.Static):
@@ -145,7 +148,6 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],
let hack2 = hack1.sources.root.parentDirectory
let hack3 = Path.join(hack2, "LinuxMain.swift")
args.append(hack3)
args += Xcc

args.append("-emit-executable")
args += ["-I", prefix]
@@ -45,7 +45,7 @@ do {
let dirs = try directories()
let packages = try fetch(dirs.root)
let (modules, products) = try transmute(packages)
let yaml = try describe(dirs.build, conf, modules, products, Xcc: opts.Xcc, Xld: opts.Xlinker)
let yaml = try describe(dirs.build, conf, modules, products, Xcc: opts.Xcc, Xld: opts.Xld, Xswiftc: opts.Xswiftc)
try build(YAMLPath: yaml, target: "default")

case .Init:
@@ -12,27 +12,23 @@ import enum Build.Configuration
import Multitool

func usage(print: (String) -> Void = { print($0) }) {
//.........10.........20.........30.........40.........50.........60.........70..
//.........10.........20.........30.........40.........50.........60.........70..
print("OVERVIEW: Build sources into binary products")
print("")
print("USAGE: swift build [options]")
print("")
print("MODES:")
print(" --configuration <value> Build with configuration (debug|release) [-c]")
print(" --clean[=<mode>] Delete all build intermediaries and products [-k]")
print(" <mode> is one of:")
print(" build - Build intermediaries and products")
print(" dist - All of 'build' plus downloaded packages")
print(" If no mode is given, 'build' is the default.")
print(" --clean[=<mode>] Delete artefacts (build|dist) [-k]")
print(" --init Creates a new Swift project")
print(" --fetch Fetch package dependencies")
print("")
print("OPTIONS:")
print(" --chdir <value> Change working directory before any other operation [-C]")
print(" -v[v] Increase verbosity of informational output")
print(" -Xcc <flag> Pass flag through to all compiler instantiations")
print(" -Xcc <flag> Pass flag through to all C compiler instantiations")
print(" -Xlinker <flag> Pass flag through to all linker instantiations")
print(" --get Only pull down dependencies without building binaries")
print(" -Xswiftc <flag> Pass flag through to all Swift compiler instantiations")
}

enum CleanMode: String {
@@ -53,7 +49,8 @@ struct Options {
var chdir: String? = nil
var verbosity: Int = 0
var Xcc: [String] = []
var Xlinker: [String] = []
var Xld: [String] = []
var Xswiftc: [String] = []
}

func parse(commandLineArguments args: [String]) throws -> (Mode, Options) {
@@ -69,7 +66,7 @@ func parse(commandLineArguments args: [String]) throws -> (Mode, Options) {
return [arg]
}

if arg == "-Xcc" || arg == "-Xlinker" {
if "-Xcc" == arg || "-Xlinker" == arg || "-Xswiftc" == arg {
skipNext = true
return [arg]
}
@@ -158,7 +155,10 @@ func parse(commandLineArguments args: [String]) throws -> (Mode, Options) {
opts.Xcc.append(try cruncher.rawPop())

case .Switch(.Xlinker):
opts.Xlinker.append(try cruncher.rawPop())
opts.Xld.append(try cruncher.rawPop())

case .Switch(.Xswiftc):
opts.Xswiftc.append(try cruncher.rawPop())
}
}

@@ -219,6 +219,7 @@ private struct Cruncher {
case Verbose = "--verbose"
case Xcc = "-Xcc"
case Xlinker = "-Xlinker"
case Xswiftc = "-Xswiftc"

init?(rawValue: String) {
switch rawValue {
@@ -230,6 +231,8 @@ private struct Cruncher {
self = .Xcc
case Xlinker.rawValue:
self = .Xlinker
case Xswiftc.rawValue:
self = .Xswiftc
default:
return nil
}
@@ -14,9 +14,9 @@ import Build
import POSIX

#if os(Linux)
public func describe(prefix: String, _ conf: Configuration, _ modules: [Module], _ products: [Product], Xcc: [String], Xld: [String]) throws -> String {
public func describe(prefix: String, _ conf: Configuration, _ modules: [Module], _ products: [Product], Xcc: [String], Xld: [String], Xswiftc: [String]) throws -> String {
do {
return try Build.describe(prefix, conf, modules, products, Xcc: Xcc, Xld: Xld)
return try Build.describe(prefix, conf, modules, products, Xcc: Xcc, Xld: Xld, Xswftc: Xswiftc)
} catch {

// it is a common error on Linux for clang++ to not be installed, but

0 comments on commit d04ca88

Please sign in to comment.