Skip to content

Add executorFactory option to package manifest. #8443

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

Closed
wants to merge 2 commits into from
Closed
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
17 changes: 17 additions & 0 deletions Sources/PackageDescription/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,23 @@ public struct SwiftSetting: Sendable {
return SwiftSetting(
name: "defaultIsolation", value: [isolationString], condition: condition)
}

/// Defines an `-executor-factory` to pass to the
/// corresponding build tool.
///
/// - Since: First available in PackageDescription 6.2
///
/// - Parameters:
/// - factory: The type name of the executor factory that should be used.
/// - condition: A condition that restricts the application of the build setting.
@available(_PackageDescription, introduced: 6.2)
public static func executorFactory(
_ factory: String,
_ condition: BuildSettingCondition? = nil
) -> SwiftSetting {
return SwiftSetting(
name: "executorFactory", value: [factory], condition: condition)
}
}

/// A linker build setting.
Expand Down
5 changes: 5 additions & 0 deletions Sources/PackageLoading/ManifestJSONParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,11 @@ extension TargetBuildSettingDescription.Kind {
}

return .defaultIsolation(isolation)
case "executorFactory":
guard let value = values.first else {
throw InternalError("invalid (empty) build settings value")
}
return .executorFactory(value)
default:
throw InternalError("invalid build setting \(name)")
}
Expand Down
11 changes: 11 additions & 0 deletions Sources/PackageLoading/PackageBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,17 @@ public final class PackageBuilder {
}

values = ["-default-isolation", isolation.rawValue]

case .executorFactory(let factory):
switch setting.tool {
case .c, .cxx, .linker:
throw InternalError("only Swift supports executor factory")

case .swift:
decl = .OTHER_SWIFT_FLAGS
}

values = ["-executor-factory ", factory]
}

// Create an assignment for this setting.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ public enum TargetBuildSettingDescription {

case defaultIsolation(DefaultIsolation)

case executorFactory(String)

public var isUnsafeFlags: Bool {
switch self {
case .unsafeFlags(let flags):
// If `.unsafeFlags` is used, but doesn't specify any flags, we treat it the same way as not specifying it.
return !flags.isEmpty
case .headerSearchPath, .define, .linkedLibrary, .linkedFramework, .interoperabilityMode,
.enableUpcomingFeature, .enableExperimentalFeature, .strictMemorySafety, .swiftLanguageMode,
.defaultIsolation:
.defaultIsolation, .executorFactory:
return false
}
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/PackageModel/ManifestSourceGeneration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ fileprivate extension SourceCodeFragment {
params.append(SourceCodeFragment(from: condition))
}
self.init(enum: setting.kind.name, subnodes: params)
case .executorFactory(let factory):
params.append(SourceCodeFragment(string: factory))
self.init(enum: setting.kind.name, subnodes: params)
}
}

Expand Down Expand Up @@ -1023,6 +1026,8 @@ extension TargetBuildSettingDescription.Kind {
return "swiftLanguageMode"
case .defaultIsolation:
return "defaultIsolation"
case .executorFactory:
return "executorFactory"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4308,6 +4308,7 @@ class BuildPlanTestCase: BuildSystemProviderTestCase {
),
.init(tool: .swift, kind: .strictMemorySafety),
.init(tool: .swift, kind: .defaultIsolation(.MainActor)),
.init(tool: .swift, kind: .executorFactory("Foo.Bar")),
]
),
TargetDescription(
Expand Down
70 changes: 70 additions & 0 deletions Tests/PackageLoadingTests/PackageBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3257,6 +3257,76 @@ final class PackageBuilderTests: XCTestCase {
}
}
}

func testExecutorFactoryPerTarget() throws {
let fs = InMemoryFileSystem(emptyFiles:
"/Sources/A/a.swift",
"/Sources/B/b.swift"
)

let manifest = Manifest.createRootManifest(
displayName: "pkg",
toolsVersion: .v6_2,
targets: [
try TargetDescription(
name: "A",
settings: [
.init(tool: .swift, kind: .executorFactory("Foo.Bar"))
]
),
try TargetDescription(
name: "B",
settings: [
.init(tool: .swift, kind: .executorFactory("Foo.Bar"), condition: .init(platformNames: ["linux"])),
.init(tool: .swift, kind: .executorFactory("Foo.Bar"), condition: .init(platformNames: ["macos"], config: "debug"))
]
),
]
)

PackageBuilderTester(manifest, in: fs) { package, _ in
package.checkModule("A") { package in
let macosDebugScope = BuildSettings.Scope(
package.target.buildSettings,
environment: BuildEnvironment(platform: .macOS, configuration: .debug)
)
XCTAssertMatch(macosDebugScope.evaluate(.OTHER_SWIFT_FLAGS),
[.anySequence, "-executor-factory", "Foo.Bar", .anySequence])

let macosReleaseScope = BuildSettings.Scope(
package.target.buildSettings,
environment: BuildEnvironment(platform: .macOS, configuration: .release)
)
XCTAssertMatch(macosReleaseScope.evaluate(.OTHER_SWIFT_FLAGS),
[.anySequence, "-executor-factory", "Foo.Bar", .anySequence])

}

package.checkModule("B") { package in
let linuxDebugScope = BuildSettings.Scope(
package.target.buildSettings,
environment: BuildEnvironment(platform: .linux, configuration: .debug)
)
XCTAssertMatch(linuxDebugScope.evaluate(.OTHER_SWIFT_FLAGS),
[.anySequence, "-executor-factory", "Foo.Bar", .anySequence])

let macosDebugScope = BuildSettings.Scope(
package.target.buildSettings,
environment: BuildEnvironment(platform: .macOS, configuration: .debug)
)
XCTAssertMatch(macosDebugScope.evaluate(.OTHER_SWIFT_FLAGS),
[.anySequence, "-executor-factory", "Foo.Bar", .anySequence])

let macosReleaseScope = BuildSettings.Scope(
package.target.buildSettings,
environment: BuildEnvironment(platform: .macOS, configuration: .release)
)
XCTAssertNoMatch(macosReleaseScope.evaluate(.OTHER_SWIFT_FLAGS),
[.anySequence, "-executor-factory", "Foo.Bar", .anySequence])

}
}
}
}

final class PackageBuilderTester {
Expand Down
19 changes: 19 additions & 0 deletions Tests/WorkspaceTests/ManifestSourceGenerationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -898,4 +898,23 @@ final class ManifestSourceGenerationTests: XCTestCase {
let contents = try manifest.generateManifestFileContents(packageDirectory: manifest.path.parentDirectory)
try await testManifestWritingRoundTrip(manifestContents: contents, toolsVersion: .v6_2)
}

func testExecutorFactory() async throws {
let manifest = Manifest.createRootManifest(
displayName: "pkg",
path: "/pkg",
toolsVersion: .v6_2,
dependencies: [],
targets: [
try TargetDescription(
name: "A",
type: .executable,
settings: [
.init(tool: .swift, kind: .executorFactory("Foo.Bar"))
]
)
])
let contents = try manifest.generateManifestFileContents(packageDirectory: manifest.path.parentDirectory)
try await testManifestWritingRoundTrip(manifestContents: contents, toolsVersion: .v6_2)
}
}
85 changes: 85 additions & 0 deletions Tests/XCBuildSupportTests/PIFBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3123,6 +3123,91 @@ final class PIFBuilderTests: XCTestCase {
}
}
}

func testPerTargetExecutorFactory() throws {
#if !os(macOS)
try XCTSkipIf(true, "test is only supported on macOS")
#endif
let fs = InMemoryFileSystem(
emptyFiles:
"/Foo/Sources/foo/foo.swift",
"/Foo/Sources/bar/bar.swift",
"/Foo/Sources/baz/baz.swift"
)

let observability = ObservabilitySystem.makeForTesting()
let graph = try loadModulesGraph(
fileSystem: fs,
manifests: [
Manifest.createRootManifest(
displayName: "Foo",
path: "/Foo",
toolsVersion: .v6_2,
targets: [
.init(name: "foo", dependencies: [], settings: [
.init(
tool: .swift,
kind: .executorFactory("Foo.Bar")
),
]),
.init(name: "baz", dependencies: [], settings: [
.init(
tool: .swift,
kind: .executorFactory("Foo.Bar"),
condition: .init(platformNames: ["linux"])
)
])
]
),
],
shouldCreateMultipleTestProducts: true,
observabilityScope: observability.topScope
)

let builder = PIFBuilder(
graph: graph,
parameters: .mock(supportedSwiftVersions: [.v6]),
fileSystem: fs,
observabilityScope: observability.topScope
)
let pif = try builder.construct()

XCTAssertNoDiagnostics(observability.diagnostics)

try PIFTester(pif) { workspace in
try workspace.checkProject("PACKAGE:/Foo") { project in
project.checkTarget("PACKAGE-TARGET:foo") { target in
for config in ["Debug", "Release"] {
target.checkBuildConfiguration(config) { configuration in
configuration.checkBuildSettings { settings in
XCTAssertMatch(
settings[.OTHER_SWIFT_FLAGS] ?? [],
[.anySequence, "-executor-factory", "Foo.Bar", .anySequence]
)
}
}
}
}

project.checkTarget("PACKAGE-TARGET:baz") { target in
for config in ["Debug", "Release"] {
target.checkBuildConfiguration(config) { configuration in
configuration.checkBuildSettings { settings in
XCTAssertMatch(
settings[.OTHER_SWIFT_FLAGS, for: .linux] ?? [],
[.anySequence, "-executor-factory", "Foo.Bar", .anySequence]
)
XCTAssertNoMatch(
settings[.OTHER_SWIFT_FLAGS, for: .macOS] ?? [],
[.anySequence, "-executor-factory", "Foo.Bar", .anySequence]
)
}
}
}
}
}
}
}
}

extension PIFBuilderParameters {
Expand Down