Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Sources/Commands/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public class ToolOptions {

/// Path to the compilation destination describing JSON file.
public var customCompileDestination: AbsolutePath?
/// The compilation destination’s target triple.
public var customCompileTriple: Triple?
/// Path to the compilation destination’s SDK.
public var customCompileSDK: AbsolutePath?
/// Path to the compilation destination’s toolchain.
public var customCompileToolchain: AbsolutePath?

/// If should link the Swift stdlib statically.
public var shouldLinkStaticSwiftStdlib = false
Expand Down
40 changes: 33 additions & 7 deletions Sources/Commands/SwiftTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,15 @@ public class SwiftTool<Options: ToolOptions> {
binder.bind(
option: parser.add(option: "--destination", kind: PathArgument.self),
to: { $0.customCompileDestination = $1.path })
binder.bind(
option: parser.add(option: "--triple", kind: String.self),
to: { $0.customCompileTriple = try Triple($1) })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a part of this PR but at some point, we should probably allow taking an array of triples in order to produce fat binaries.

Copy link
Contributor

@jakepetroules jakepetroules Feb 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can we call this --target? CLI frontends like clang and swiftc typically use the target terminology, whereas triple is more of an internal terminology.

"triple" is also inaccurate these days since most "triples" (Mac Catalyst, iOS/tvOS/watchOS Simulator, Linux, Android, Windows) actually have four components.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn’t --target already exist and select a target module to build as opposed to a target platform?

It’s what I started with, and then when I realized it would need to be --target-triple to disambiguate. At that point the word target seemed redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup.

$ swift build --help
[...]
   --target                Build the specified target

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m still open to alternate suggestions though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an internal flag right and the term Triple is well know so I fine with both --triple or --target-triple.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, forgot about that. Alright, let's go with --triple I guess.

binder.bind(
option: parser.add(option: "--sdk", kind: PathArgument.self),
to: { $0.customCompileSDK = $1.path })
binder.bind(
option: parser.add(option: "--toolchain", kind: PathArgument.self),
to: { $0.customCompileToolchain = $1.path })

// FIXME: We need to allow -vv type options for this.
binder.bind(
Expand Down Expand Up @@ -782,14 +791,31 @@ public class SwiftTool<Options: ToolOptions> {

/// Lazily compute the destination toolchain.
private lazy var _destinationToolchain: Result<UserToolchain, Swift.Error> = {
// Create custom toolchain if present.
if let customDestination = self.options.customCompileDestination {
return Result(catching: {
try UserToolchain(destination: Destination(fromFile: customDestination))
})
var destination: Destination
do {
// Create custom toolchain if present.
if let customDestination = self.options.customCompileDestination {
destination = try Destination(fromFile: customDestination)
} else {
// Otherwise use the host toolchain.
destination = try Destination.hostDestination(
originalWorkingDirectory: self.originalWorkingDirectory
)
}
} catch {
return .failure(error)
}
// Apply any manual overrides.
if let triple = self.options.customCompileTriple {
destination.target = triple
}
if let binDir = self.options.customCompileToolchain {
destination.binDir = binDir.appending(components: "usr", "bin")
}
if let sdk = self.options.customCompileSDK {
destination.sdk = sdk
}
// Otherwise use the host toolchain.
return self._hostToolchain
return Result(catching: { try UserToolchain(destination: destination) })
}()

/// Lazily compute the host toolchain used to compile the package description.
Expand Down
6 changes: 3 additions & 3 deletions Sources/Workspace/Destination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public struct Destination: Encodable {
/// - abi = eabi, gnu, android, macho, elf, etc.
///
/// for more information see //https://clang.llvm.org/docs/CrossCompilation.html
public let target: Triple?
public var target: Triple?

/// The SDK used to compile for the destination.
public let sdk: AbsolutePath
public var sdk: AbsolutePath

/// The binDir in the containing the compilers/linker to be used for the compilation.
public let binDir: AbsolutePath
public var binDir: AbsolutePath

/// Additional flags to be passed to the C compiler.
public let extraCCFlags: [String]
Expand Down