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
7 changes: 6 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ let package = Package(
swiftSettings: swiftSettings(languageMode: .v6)),
.target(
name: "SWBTaskConstruction",
dependencies: ["SWBCore", "SWBUtil"],
dependencies: [
"SWBCore",
"SWBUtil",
.product(name: "SwiftDriver", package: "swift-driver")
],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v5)),
.target(
Expand All @@ -206,6 +210,7 @@ let package = Package(
"SWBCSupport",
"SWBLibc",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "SwiftDriver", package: "swift-driver"),
.product(name: "SystemPackage", package: "swift-system", condition: .when(platforms: [.linux, .openbsd, .android, .windows, .custom("freebsd")])),
],
exclude: ["CMakeLists.txt"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ final public class AppIntentsMetadataCompilerSpec: GenericCommandLineToolSpec, S
for variant in buildVariants {
let scope = cbc.scope.subscope(binding: BuiltinMacros.variantCondition, to: variant)
for arch in archs {
let scope = scope.subscope(binding: BuiltinMacros.archCondition, to: arch)
let scope = scope.subscopeBindingArchAndTriple(arch: arch)
let dependencyInfoFile = scope.evaluate(BuiltinMacros.LD_DEPENDENCY_INFO_FILE)
let libtoolDependencyInfo = scope.evaluate(BuiltinMacros.LIBTOOL_DEPENDENCY_INFO_FILE)
if !isStaticLibrary && !dependencyInfoFile.isEmpty {
Expand Down
86 changes: 86 additions & 0 deletions Sources/SWBCore/ArtifactBundleMetadata.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

package import SWBUtil
import Foundation

package struct ArtifactBundleInfo: Hashable {
package let bundlePath: Path
package let metadata: ArtifactBundleMetadata

package init(bundlePath: Path, metadata: ArtifactBundleMetadata) {
self.bundlePath = bundlePath
self.metadata = metadata
}
}

package struct ArtifactBundleMetadata: Sendable, Hashable, Decodable {
package let schemaVersion: String
package let artifacts: [String: ArtifactMetadata]

package struct ArtifactMetadata: Sendable, Hashable, Decodable {
package let type: ArtifactType
package let version: String
package let variants: [VariantMetadata]
}

package enum ArtifactType: String, Sendable, Decodable {
case executable
case staticLibrary
case swiftSDK
case crossCompilationDestination
}

package struct VariantMetadata: Sendable, Hashable, Decodable {
package let path: Path
package let supportedTriples: [String]?
package let staticLibraryMetadata: StaticLibraryMetadata?
}

package struct StaticLibraryMetadata: Sendable, Hashable, Decodable {
package let headerPaths: [Path]
package let moduleMapPath: Path?
}

package static func parse(
at bundlePath: Path,
fileSystem: any FSProxy
) throws -> ArtifactBundleMetadata {
let infoPath = bundlePath.join("info.json")

guard fileSystem.exists(infoPath) else {
throw StubError.error("artifact bundle info.json not found at '\(infoPath.str)'")
}

do {
let bytes = try fileSystem.read(infoPath)
let data = Data(bytes.bytes)
let decoder = JSONDecoder()
let metadata = try decoder.decode(ArtifactBundleMetadata.self, from: data)

guard let version = try? Version(metadata.schemaVersion) else {
throw StubError.error("invalid schema version '\(metadata.schemaVersion)' in '\(infoPath.str)'")
}

switch version {
case Version(1, 2), Version(1, 1), Version(1, 0):
break
default:
throw StubError.error("invalid `schemaVersion` of bundle manifest at '\(infoPath)': \(version)")
}

return metadata
} catch {
throw StubError.error("failed to parse ArtifactBundle info.json at '\(infoPath.str)': \(error.localizedDescription)")
}
}
}
14 changes: 7 additions & 7 deletions Sources/SWBCore/BuildRequestContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@ public final class BuildRequestContext: Sendable {
}

/// Get the cached settings for the given parameters, without considering the context of any project/target.
public func getCachedSettings(_ parameters: BuildParameters) -> Settings {
package func getCachedSettings(_ parameters: BuildParameters) -> Settings {
workspaceContext.workspaceSettingsCache.getCachedSettings(parameters, buildRequestContext: self, purpose: .build, filesSignature: filesSignature(for:))
}

/// Get the cached settings for the given parameters and project.
public func getCachedSettings(_ parameters: BuildParameters, project: Project, purpose: SettingsPurpose = .build, provisioningTaskInputs: ProvisioningTaskInputs? = nil, impartedBuildProperties: [ImpartedBuildProperties]? = nil) -> Settings {
getCachedSettings(parameters, project: project, target: nil, purpose: purpose, provisioningTaskInputs: provisioningTaskInputs, impartedBuildProperties: impartedBuildProperties)
package func getCachedSettings(_ parameters: BuildParameters, project: Project, purpose: SettingsPurpose = .build, provisioningTaskInputs: ProvisioningTaskInputs? = nil) -> Settings {
getCachedSettings(parameters, project: project, target: nil, purpose: purpose, provisioningTaskInputs: provisioningTaskInputs, impartedBuildProperties: nil, artifactBundleInfo: nil)
}

/// Get the cached settings for the given parameters and target.
public func getCachedSettings(_ parameters: BuildParameters, target: Target, purpose: SettingsPurpose = .build, provisioningTaskInputs: ProvisioningTaskInputs? = nil, impartedBuildProperties: [ImpartedBuildProperties]? = nil) -> Settings {
getCachedSettings(parameters, project: workspaceContext.workspace.project(for: target), target: target, purpose: purpose, provisioningTaskInputs: provisioningTaskInputs, impartedBuildProperties: impartedBuildProperties)
package func getCachedSettings(_ parameters: BuildParameters, target: Target, purpose: SettingsPurpose = .build, provisioningTaskInputs: ProvisioningTaskInputs? = nil, impartedBuildProperties: [ImpartedBuildProperties]? = nil, artifactBundleInfo: [ArtifactBundleInfo]? = nil) -> Settings {
getCachedSettings(parameters, project: workspaceContext.workspace.project(for: target), target: target, purpose: purpose, provisioningTaskInputs: provisioningTaskInputs, impartedBuildProperties: impartedBuildProperties, artifactBundleInfo: artifactBundleInfo)
}

/// Private method to get the cached settings for the given parameters, project, and target.
///
/// - remark: This is private so that clients don't somehow call this with a project which doesn't match the target. There are public methods covering this one.
private func getCachedSettings(_ parameters: BuildParameters, project: Project, target: Target?, purpose: SettingsPurpose = .build, provisioningTaskInputs: ProvisioningTaskInputs?, impartedBuildProperties: [ImpartedBuildProperties]?) -> Settings {
workspaceContext.workspaceSettingsCache.getCachedSettings(parameters, project: project, target: target, purpose: purpose, provisioningTaskInputs: provisioningTaskInputs, impartedBuildProperties: impartedBuildProperties, buildRequestContext: self, filesSignature: filesSignature(for:))
private func getCachedSettings(_ parameters: BuildParameters, project: Project, target: Target?, purpose: SettingsPurpose = .build, provisioningTaskInputs: ProvisioningTaskInputs?, impartedBuildProperties: [ImpartedBuildProperties]?, artifactBundleInfo: [ArtifactBundleInfo]?) -> Settings {
workspaceContext.workspaceSettingsCache.getCachedSettings(parameters, project: project, target: target, purpose: purpose, provisioningTaskInputs: provisioningTaskInputs, impartedBuildProperties: impartedBuildProperties, artifactBundleInfo: artifactBundleInfo, buildRequestContext: self, filesSignature: filesSignature(for:))
}

@_spi(Testing) public func getCachedMacroConfigFile(_ path: Path, project: Project? = nil, context: MacroConfigLoadContext) -> MacroConfigInfo {
Expand Down
1 change: 1 addition & 0 deletions Sources/SWBCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ add_library(SWBCore
ActivityReporting.swift
Apple/DeviceFamily.swift
Apple/InterfaceBuilderShared.swift
ArtifactBundleMetadata.swift
BuildDependencyInfo.swift
BuildFileFilteringContext.swift
BuildFileResolution.swift
Expand Down
6 changes: 6 additions & 0 deletions Sources/SWBCore/MacroEvaluationExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,10 @@ extension MacroEvaluationScope {
return ($0 == BuiltinMacros.TARGET_BUILD_SUBPATH) ? self.table.namespace.parseLiteralString("") : nil
})
}

public func subscopeBindingArchAndTriple(arch: String) -> MacroEvaluationScope {
let archScope = subscope(binding: BuiltinMacros.archCondition, to: arch)
let swiftTargetTriple = archScope.evaluate(BuiltinMacros.SWIFT_TARGET_TRIPLE)
return archScope.subscope(binding: BuiltinMacros.normalizedUnversionedTripleCondition, to: swiftTargetTriple)
}
}
3 changes: 2 additions & 1 deletion Sources/SWBCore/Settings/BuiltinMacros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public final class BuiltinMacros {
public static let platformCondition = BuiltinMacros.declareConditionParameter("__platform_filter")
public static let sdkBuildVersionCondition = BuiltinMacros.declareConditionParameter("_sdk_build_version")
public static let targetNameCondition = BuiltinMacros.declareConditionParameter("target")
public static let normalizedUnversionedTripleCondition = BuiltinMacros.declareConditionParameter("__normalized_unversioned_triple")

private static let allBuiltinConditionParameters = [archCondition, sdkCondition, variantCondition, configurationCondition, platformCondition, sdkBuildVersionCondition, targetNameCondition]
private static let allBuiltinConditionParameters = [archCondition, sdkCondition, variantCondition, configurationCondition, platformCondition, sdkBuildVersionCondition, targetNameCondition, normalizedUnversionedTripleCondition]

// MARK: Built-in Macro Definitions

Expand Down
Loading
Loading