Skip to content

Basics/Commands: add experimental CC SDK paths option #5879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 10, 2022
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
23 changes: 23 additions & 0 deletions Sources/Basics/FileSystem+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,29 @@ extension FileSystem {
}
}

// MARK: - cross-compilation SDKs

private let sdksDirectoryName = "sdks"

extension FileSystem {
/// SwiftPM cross-compilation SDKs directory (if exists)
public var swiftPMCrossCompilationSDKsDirectory: AbsolutePath {
get throws {
if let path = try self.idiomaticSwiftPMDirectory {
return path.appending(component: sdksDirectoryName)
} else {
return try self.dotSwiftPMCrossCompilationSDKsDirectory
}
}
}

fileprivate var dotSwiftPMCrossCompilationSDKsDirectory: AbsolutePath {
get throws {
return try self.dotSwiftPM.appending(component: sdksDirectoryName)
}
}
}

// MARK: - Utilities

extension FileSystem {
Expand Down
3 changes: 3 additions & 0 deletions Sources/CoreCommands/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public struct LocationOptions: ParsableArguments {
/// Path to the compilation destination describing JSON file.
@Option(name: .customLong("destination"), help: .hidden, completion: .directory)
public var customCompileDestination: AbsolutePath?

@Option(name: .customLong("experimental-cross-compilation-sdks-path"), help: .hidden, completion: .directory)
var ccSDKsDirectory: AbsolutePath?
}

public struct CachingOptions: ParsableArguments {
Expand Down
31 changes: 25 additions & 6 deletions Sources/CoreCommands/SwiftTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ public class SwiftTool {
/// Path to the shared configuration directory
public let sharedConfigurationDirectory: AbsolutePath?

/// Path to the cross-compilation SDK directory.
let sharedCCSDKDirectory: AbsolutePath?

/// Cancellator to handle cancellation of outstanding work when handling SIGINT
public let cancellator: Cancellator

Expand Down Expand Up @@ -304,9 +307,10 @@ public class SwiftTool {
(packageRoot ?? cwd).appending(component: ".build")

// make sure common directories are created
self.sharedSecurityDirectory = try getSharedSecurityDirectory(options: self.options, fileSystem: fileSystem, observabilityScope: self.observabilityScope)
self.sharedConfigurationDirectory = try getSharedConfigurationDirectory(options: self.options, fileSystem: fileSystem, observabilityScope: self.observabilityScope)
self.sharedCacheDirectory = try getSharedCacheDirectory(options: self.options, fileSystem: fileSystem, observabilityScope: self.observabilityScope)
self.sharedSecurityDirectory = try getSharedSecurityDirectory(options: self.options, fileSystem: fileSystem)
self.sharedConfigurationDirectory = try getSharedConfigurationDirectory(options: self.options, fileSystem: fileSystem)
self.sharedCacheDirectory = try getSharedCacheDirectory(options: self.options, fileSystem: fileSystem)
self.sharedCCSDKDirectory = try getSharedCCSDKsDirectory(options: self.options, fileSystem: fileSystem)

// set global process logging handler
Process.loggingHandler = { self.observabilityScope.emit(debug: $0) }
Expand Down Expand Up @@ -738,7 +742,7 @@ private func getEnvBuildPath(workingDir: AbsolutePath) throws -> AbsolutePath? {
}


private func getSharedSecurityDirectory(options: GlobalOptions, fileSystem: FileSystem, observabilityScope: ObservabilityScope) throws -> AbsolutePath? {
private func getSharedSecurityDirectory(options: GlobalOptions, fileSystem: FileSystem) throws -> AbsolutePath? {
if let explicitSecurityDirectory = options.locations.securityDirectory {
// Create the explicit security path if necessary
if !fileSystem.exists(explicitSecurityDirectory) {
Expand All @@ -751,7 +755,7 @@ private func getSharedSecurityDirectory(options: GlobalOptions, fileSystem: File
}
}

private func getSharedConfigurationDirectory(options: GlobalOptions, fileSystem: FileSystem, observabilityScope: ObservabilityScope) throws -> AbsolutePath? {
private func getSharedConfigurationDirectory(options: GlobalOptions, fileSystem: FileSystem) throws -> AbsolutePath? {
if let explicitConfigurationDirectory = options.locations.configurationDirectory {
// Create the explicit config path if necessary
if !fileSystem.exists(explicitConfigurationDirectory) {
Expand All @@ -764,7 +768,7 @@ private func getSharedConfigurationDirectory(options: GlobalOptions, fileSystem:
}
}

private func getSharedCacheDirectory(options: GlobalOptions, fileSystem: FileSystem, observabilityScope: ObservabilityScope) throws -> AbsolutePath? {
private func getSharedCacheDirectory(options: GlobalOptions, fileSystem: FileSystem) throws -> AbsolutePath? {
if let explicitCacheDirectory = options.locations.cacheDirectory {
// Create the explicit cache path if necessary
if !fileSystem.exists(explicitCacheDirectory) {
Expand All @@ -777,6 +781,21 @@ private func getSharedCacheDirectory(options: GlobalOptions, fileSystem: FileSys
}
}

private func getSharedCCSDKsDirectory(
options: GlobalOptions,
fileSystem: FileSystem
) throws -> AbsolutePath? {
if let explicitCCSDKsDirectory = options.locations.ccSDKsDirectory {
// Create the explicit SDKs path if necessary
if !fileSystem.exists(explicitCCSDKsDirectory) {
try fileSystem.createDirectory(explicitCCSDKsDirectory, recursive: true)
}
return explicitCCSDKsDirectory
} else {
return try fileSystem.swiftPMCrossCompilationSDKsDirectory
}
}

extension Basics.Diagnostic {
static func unsupportedFlag(_ flag: String) -> Self {
.warning("\(flag) is an *unsupported* option which can be removed at any time; do not rely on it")
Expand Down