Skip to content

Commit 56bb6cb

Browse files
authored
Merge pull request #512 from swiftlang/automerge/merge-main-2025-05-19_09-02
Merge `main` into `release/6.2`
2 parents 51369cd + 1d66c4f commit 56bb6cb

File tree

9 files changed

+131
-41
lines changed

9 files changed

+131
-41
lines changed

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ public final class BuiltinMacros {
2424
public static let configurationCondition = BuiltinMacros.declareConditionParameter("config")
2525
public static let platformCondition = BuiltinMacros.declareConditionParameter("__platform_filter")
2626
public static let sdkBuildVersionCondition = BuiltinMacros.declareConditionParameter("_sdk_build_version")
27+
public static let targetNameCondition = BuiltinMacros.declareConditionParameter("target")
2728

28-
private static let allBuiltinConditionParameters = [archCondition, sdkCondition, variantCondition, configurationCondition, platformCondition, sdkBuildVersionCondition]
29+
private static let allBuiltinConditionParameters = [archCondition, sdkCondition, variantCondition, configurationCondition, platformCondition, sdkBuildVersionCondition, targetNameCondition]
2930

3031
// MARK: Built-in Macro Definitions
3132

Sources/SWBCore/Settings/Settings.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ private class SettingsBuilder {
15921592
if let sdk = boundProperties.sdk, settingsContext.purpose.bindToSDK {
15931593
for property in impartedBuildProperties ?? [] {
15941594
// Imparted build properties are always from packages, so force allow platform filter conditionals.
1595-
bindConditionParameters(property.buildSettings, sdk, forceAllowPlatformFilterCondition: true)
1595+
bindConditionParameters(bindTargetCondition(property.buildSettings), sdk, forceAllowPlatformFilterCondition: true)
15961596
}
15971597
}
15981598

@@ -2751,6 +2751,14 @@ private class SettingsBuilder {
27512751
}
27522752
}
27532753

2754+
func bindTargetCondition(_ table: MacroValueAssignmentTable) -> MacroValueAssignmentTable {
2755+
if let target {
2756+
return table.bindConditionParameter(BuiltinMacros.targetNameCondition, [target.name])
2757+
} else {
2758+
return table
2759+
}
2760+
}
2761+
27542762
/// Add the regular project settings.
27552763
func addProjectSettings(_ config: BuildConfiguration, _ sdk: SDK? = nil) {
27562764
guard let project else {
@@ -2781,11 +2789,11 @@ private class SettingsBuilder {
27812789
// Load and push a settings table from the file.
27822790
let info = buildRequestContext.getCachedMacroConfigFile(path, project: project, context: .baseConfiguration)
27832791
if let sdk = sdk, settingsContext.purpose.bindToSDK {
2784-
bindConditionParameters(info.table, sdk)
2792+
bindConditionParameters(bindTargetCondition(info.table), sdk)
27852793
}
27862794
else {
27872795
// No bound SDK, so push the project's build settings unmodified.
2788-
push(info.table, .exported)
2796+
push(bindTargetCondition(info.table), .exported)
27892797
}
27902798
self.diagnostics.append(contentsOf: info.diagnostics)
27912799
for path in info.dependencyPaths {
@@ -2810,11 +2818,11 @@ private class SettingsBuilder {
28102818

28112819
// Add the project's config settings.
28122820
if let sdk, settingsContext.purpose.bindToSDK {
2813-
bindConditionParameters(config.buildSettings, sdk)
2821+
bindConditionParameters(bindTargetCondition(config.buildSettings), sdk)
28142822
}
28152823
else {
28162824
// No bound SDK, so push the project's build settings unmodified.
2817-
push(config.buildSettings, .exported)
2825+
push(bindTargetCondition(config.buildSettings), .exported)
28182826
}
28192827

28202828
// Save the settings table as part of the construction components.
@@ -2996,11 +3004,11 @@ private class SettingsBuilder {
29963004
// Load and push a settings table from the file.
29973005
let info = buildRequestContext.getCachedMacroConfigFile(path, project: project, context: .baseConfiguration)
29983006
if let sdk = sdk, settingsContext.purpose.bindToSDK {
2999-
bindConditionParameters(info.table, sdk)
3007+
bindConditionParameters(bindTargetCondition(info.table), sdk)
30003008
}
30013009
else {
30023010
// No bound SDK, so push the target xcconfig's build settings unmodified.
3003-
push(info.table, .exported)
3011+
push(bindTargetCondition(info.table), .exported)
30043012
}
30053013
self.targetDiagnostics.append(contentsOf: info.diagnostics)
30063014
for path in info.dependencyPaths {
@@ -3019,11 +3027,11 @@ private class SettingsBuilder {
30193027
//
30203028
// FIXME: Cache this table, but we can only do that once we share the namespace.
30213029
if let sdk, settingsContext.purpose.bindToSDK {
3022-
bindConditionParameters(config.buildSettings, sdk)
3030+
bindConditionParameters(bindTargetCondition(config.buildSettings), sdk)
30233031
}
30243032
else {
30253033
// No bound SDK, so push the target's build settings unmodified.
3026-
push(config.buildSettings, .exported)
3034+
push(bindTargetCondition(config.buildSettings), .exported)
30273035
}
30283036

30293037
addSpecializationOverrides(sdk: sdk, usesAutomaticSDK: usesAutomaticSDK)

Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,10 +1428,6 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
14281428
delegate.warning("swift compiler caching requires explicit module build (SWIFT_ENABLE_EXPLICIT_MODULES=YES)")
14291429
return false
14301430
}
1431-
if disabledPCHCompile, !cbc.scope.evaluate(BuiltinMacros.SWIFT_OBJC_BRIDGING_HEADER).isEmpty {
1432-
delegate.warning("swift compiler caching requires precompile bridging header if caching is enabled (SWIFT_PRECOMPILE_BRIDGING_HEADER=YES)")
1433-
return false
1434-
}
14351431
if let specInfo = await (discoveredCommandLineToolSpecInfo(cbc.producer, cbc.scope, delegate) as? DiscoveredSwiftCompilerToolSpecInfo) {
14361432
if !specInfo.hasFeature(DiscoveredSwiftCompilerToolSpecInfo.FeatureFlag.compilationCaching.rawValue) {
14371433
delegate.warning("swift compiler caching is not supported by toolchain")

Sources/SWBCore/TaskGeneration.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,7 @@ public protocol TaskTypeDescription: AnyObject, ConditionallyStartable, Sendable
889889

890890
/// The command line that should be used for the change-tracking signature, i.e.
891891
/// the command line with the output-agnostic arguments removed.
892+
/// A nil return indicates that the command line should be used as is.
892893
func commandLineForSignature(for task: any ExecutableTask) -> [ByteString]?
893894

894895
/// Whether instances of this task are unsafe to interrupt.

Sources/SWBTaskExecution/TaskActions/TaskAction.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ open class TaskAction: PlannedTaskAction, PolymorphicSerializable
6969
{
7070
let md5 = InsecureHashContext()
7171
md5.add(bytes: serializedRepresentationSignature!)
72-
for arg in task.commandLine {
73-
md5.add(bytes: arg.asByteString)
72+
let commandLine = task.type.commandLineForSignature(for: task) ?? task.commandLine.map { $0.asByteString }
73+
for arg in commandLine {
74+
md5.add(bytes: arg)
7475
md5.add(number: 0)
7576
}
7677
task.environment.computeSignature(into: md5)

Sources/SWBUniversalPlatform/Specs/Swift.xcspec

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,44 @@
500500
DefaultValue = "_$(SWIFT_VERSION)";
501501
},
502502

503+
// Operator OR for a default value condition, simulates `$(X) || $(Y)` in `DefaultValue` field.
504+
{
505+
Name = "SETTING_DefaultValue_YES_YES";
506+
Type = Boolean;
507+
DefaultValue = YES;
508+
},
509+
510+
{
511+
Name = "SETTING_DefaultValue_YES_NO";
512+
Type = Boolean;
513+
DefaultValue = YES;
514+
},
515+
{
516+
Name = "SETTING_DefaultValue_NO_YES";
517+
Type = Boolean;
518+
DefaultValue = YES;
519+
},
520+
{
521+
Name = "SETTING_DefaultValue_NO_NO";
522+
Type = Boolean;
523+
DefaultValue = NO;
524+
},
525+
{
526+
Name = "SETTING_DefaultValue__";
527+
Type = Boolean;
528+
DefaultValue = NO;
529+
},
530+
531+
{
532+
Name = "SWIFT_APPROACHABLE_CONCURRENCY";
533+
Type = Boolean;
534+
DefaultValue = NO;
535+
Condition = "$(EFFECTIVE_SWIFT_VERSION) == '4' || $(EFFECTIVE_SWIFT_VERSION) == '4.2' || $(EFFECTIVE_SWIFT_VERSION) == '5'";
536+
DisplayName = "Approachable Concurrency";
537+
Category = "Concurrency";
538+
Description = "Enables upcoming features that aim to provide a more approachable path to Swift Concurrency: DisableOutwardActorInference, GlobalActorIsolatedTypesUsability, InferIsolatedConformances, InferSendableFromCaptures, and NonisolatedNonsendingByDefault.";
539+
},
540+
503541
// Upcoming Swift 6.0 features
504542
{
505543
Name = "ENABLE_SWIFT_6_UPCOMING_FEATURES_IN_SWIFT_VERSION_6_0";
@@ -566,7 +604,7 @@
566604
"<<otherwise>>" = ( "-enable-upcoming-feature", "StrictConcurrency" );
567605
};
568606
DisplayName = "Strict Concurrency Checking";
569-
Category = "Upcoming Features";
607+
Category = "Concurrency";
570608
Description = "Enables strict concurrency checking to produce warnings for possible data races. This is always 'complete' when in the Swift 6 language mode and produces errors instead of warnings.";
571609
},
572610
{
@@ -582,7 +620,7 @@
582620
MainActor = ( "-default-isolation=MainActor" );
583621
};
584622
DisplayName = "Default Actor Isolation";
585-
Category = "Language";
623+
Category = "Concurrency";
586624
Description = "Controls default actor isolation for unannotated code. When set to 'MainActor', `@MainActor` isolation will be inferred by default to mitigate false-positive data-race safety errors in sequential code.";
587625
},
588626
{
@@ -643,7 +681,7 @@
643681
{
644682
Name = "SWIFT_UPCOMING_FEATURE_DISABLE_OUTWARD_ACTOR_ISOLATION";
645683
Type = Boolean;
646-
DefaultValue = "$(SWIFT_UPCOMING_FEATURE_6_0)";
684+
DefaultValue = "$(SETTING_DefaultValue_$(SWIFT_UPCOMING_FEATURE_6_0)_$(SWIFT_APPROACHABLE_CONCURRENCY))";
647685
Condition = "$(EFFECTIVE_SWIFT_VERSION) == '4' || $(EFFECTIVE_SWIFT_VERSION) == '4.2' || $(EFFECTIVE_SWIFT_VERSION) == '5'";
648686
CommandLineArgs = {
649687
YES = ( "-enable-upcoming-feature", "DisableOutwardActorInference" );
@@ -685,7 +723,7 @@
685723
{
686724
Name = "SWIFT_UPCOMING_FEATURE_INFER_SENDABLE_FROM_CAPTURES";
687725
Type = Boolean;
688-
DefaultValue = "$(SWIFT_UPCOMING_FEATURE_6_0)";
726+
DefaultValue = "$(SETTING_DefaultValue_$(SWIFT_UPCOMING_FEATURE_6_0)_$(SWIFT_APPROACHABLE_CONCURRENCY))";
689727
Condition = "$(EFFECTIVE_SWIFT_VERSION) == '4' || $(EFFECTIVE_SWIFT_VERSION) == '4.2' || $(EFFECTIVE_SWIFT_VERSION) == '5'";
690728
CommandLineArgs = {
691729
YES = ( "-enable-upcoming-feature", "InferSendableFromCaptures" );
@@ -755,7 +793,7 @@
755793
{
756794
Name = "SWIFT_UPCOMING_FEATURE_GLOBAL_ACTOR_ISOLATED_TYPES_USABILITY";
757795
Type = Boolean;
758-
DefaultValue = "$(SWIFT_UPCOMING_FEATURE_6_0)";
796+
DefaultValue = "$(SETTING_DefaultValue_$(SWIFT_UPCOMING_FEATURE_6_0)_$(SWIFT_APPROACHABLE_CONCURRENCY))";
759797
Condition = "$(EFFECTIVE_SWIFT_VERSION) == '4' || $(EFFECTIVE_SWIFT_VERSION) == '4.2' || $(EFFECTIVE_SWIFT_VERSION) == '5'";
760798
CommandLineArgs = {
761799
YES = ( "-enable-upcoming-feature", "GlobalActorIsolatedTypesUsability" );
@@ -797,15 +835,15 @@
797835
Name = "SWIFT_UPCOMING_FEATURE_EXISTENTIAL_ANY";
798836
Type = Enumeration;
799837
Values = (
800-
Yes,
801-
Migrate,
802-
No,
838+
YES,
839+
MIGRATE,
840+
NO,
803841
);
804842
DefaultValue = No;
805843
CommandLineArgs = {
806-
Yes = ( "-enable-upcoming-feature", "ExistentialAny" );
807-
Migrate = ( "-enable-upcoming-feature", "ExistentialAny:migrate" );
808-
No = ();
844+
YES = ( "-enable-upcoming-feature", "ExistentialAny" );
845+
MIGRATE = ( "-enable-upcoming-feature", "ExistentialAny:migrate" );
846+
NO = ();
809847
};
810848
DisplayName = "Require Existential any";
811849
Category = "Upcoming Features";
@@ -815,7 +853,7 @@
815853
{
816854
Name = "SWIFT_UPCOMING_FEATURE_INFER_ISOLATED_CONFORMANCES";
817855
Type = Boolean;
818-
DefaultValue = NO;
856+
DefaultValue = "$(SWIFT_APPROACHABLE_CONCURRENCY)";
819857
CommandLineArgs = {
820858
YES = ( "-enable-upcoming-feature", "InferIsolatedConformances" );
821859
NO = ();
@@ -829,15 +867,15 @@
829867
Name = "SWIFT_UPCOMING_FEATURE_NONISOLATED_NONSENDING_BY_DEFAULT";
830868
Type = Enumeration;
831869
Values = (
832-
Yes,
833-
Migrate,
834-
No,
870+
YES,
871+
MIGRATE,
872+
NO,
835873
);
836-
DefaultValue = No;
874+
DefaultValue = "$(SWIFT_APPROACHABLE_CONCURRENCY)";
837875
CommandLineArgs = {
838-
Yes = ( "-enable-upcoming-feature", "NonisolatedNonsendingByDefault" );
839-
Migrate = ( "-enable-upcoming-feature", "NonisolatedNonsendingByDefault:migrate" );
840-
No = ();
876+
YES = ( "-enable-upcoming-feature", "NonisolatedNonsendingByDefault" );
877+
MIGRATE = ( "-enable-upcoming-feature", "NonisolatedNonsendingByDefault:migrate" );
878+
NO = ();
841879
};
842880
DisplayName = "nonisolated(nonsending) By Default";
843881
Category = "Upcoming Features";

Sources/SWBUniversalPlatform/Specs/en.lproj/Swift Compiler.strings

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,11 @@
5757

5858
"[SWIFT_ENABLE_EXPLICIT_MODULES]-value-[YES]" = "Yes";
5959
"[SWIFT_ENABLE_EXPLICIT_MODULES]-value-[NO]" = "No";
60+
61+
"[SWIFT_UPCOMING_FEATURE_NONISOLATED_NONSENDING_BY_DEFAULT]-value-[YES]" = "Yes";
62+
"[SWIFT_UPCOMING_FEATURE_NONISOLATED_NONSENDING_BY_DEFAULT]-value-[NO]" = "No";
63+
"[SWIFT_UPCOMING_FEATURE_NONISOLATED_NONSENDING_BY_DEFAULT]-value-[MIGRATE]" = "Migrate";
64+
65+
"[SWIFT_UPCOMING_FEATURE_EXISTENTIAL_ANY]-value-[YES]" = "Yes";
66+
"[SWIFT_UPCOMING_FEATURE_EXISTENTIAL_ANY]-value-[NO]" = "No";
67+
"[SWIFT_UPCOMING_FEATURE_EXISTENTIAL_ANY]-value-[MIGRATE]" = "Migrate";

Sources/SWBUtil/Xcode.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ public struct XcodeVersionInfo: Sendable {
6565
throw StubError.error("Failed to decode version plist at '\(versionPath.str)': \(error.localizedDescription)")
6666
}
6767
let (shortVersion, productBuildVersion) = try (Version(versionStrings.shortVersionString), versionStrings.productBuildVersion.map(ProductBuildVersion.init))
68-
69-
// <rdar://41211049> Guard against corrupt version info making its way into DTXcodeBuild and DTPlatformBuild
70-
if let productBuildVersion, productBuildVersion.major != shortVersion[0] {
71-
throw StubError.error("invalid content in '\(versionPath.str)' - ProductBuildVersion '\(productBuildVersion)' does not match CFBundleShortVersionString '\(shortVersion)' because their major version numbers differ (\(productBuildVersion.major) vs \(shortVersion[0])).")
72-
}
73-
7468
return XcodeVersionInfo(shortVersion: shortVersion, productBuildVersion: productBuildVersion)
7569
}
7670
}

Tests/SWBCoreTests/SettingsTests.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4837,6 +4837,49 @@ import SWBMacro
48374837
#expect(settings.globalScope.evaluate(BuiltinMacros.SUPPORTED_PLATFORMS).contains("macosx"))
48384838
}
48394839

4840+
@Test
4841+
func targetConditionals() async throws {
4842+
let testWorkspace = try await TestWorkspace(
4843+
"Workspace",
4844+
projects: [TestPackageProject(
4845+
"aProject",
4846+
groupTree: TestGroup("SomeFiles", children: []),
4847+
buildConfigurations: [
4848+
TestBuildConfiguration(
4849+
"Debug",
4850+
buildSettings: [
4851+
"SDKROOT": "macosx",
4852+
// config=Debug is added here to ensure target conditionals still compose with existing conditionals.
4853+
"OTHER_CFLAGS[target=Target][config=Debug]": "-best",
4854+
"OTHER_LDFLAGS[target=Other]": "-other",
4855+
"SUPPORTED_PLATFORMS": "$(AVAILABLE_PLATFORMS)",
4856+
"SUPPORTS_MACCATALYST": "YES",
4857+
])
4858+
],
4859+
targets: [
4860+
TestStandardTarget("Target", type: .application),
4861+
TestStandardTarget("Other", type: .application),
4862+
])
4863+
]).load(getCore())
4864+
4865+
let context = try await contextForTestData(testWorkspace)
4866+
let buildRequestContext = BuildRequestContext(workspaceContext: context)
4867+
let testProject = context.workspace.projects[0]
4868+
let parameters = BuildParameters(action: .build, configuration: "Debug", activeRunDestination: .macOS)
4869+
4870+
do {
4871+
let settings = Settings(workspaceContext: context, buildRequestContext: buildRequestContext, parameters: parameters, project: testProject, target: testProject.targets[0])
4872+
#expect(settings.globalScope.evaluate(BuiltinMacros.OTHER_CFLAGS) == ["-best"])
4873+
#expect(settings.globalScope.evaluate(BuiltinMacros.OTHER_LDFLAGS) == [])
4874+
}
4875+
4876+
do {
4877+
let settings = Settings(workspaceContext: context, buildRequestContext: buildRequestContext, parameters: parameters, project: testProject, target: testProject.targets[1])
4878+
#expect(settings.globalScope.evaluate(BuiltinMacros.OTHER_CFLAGS) == [])
4879+
#expect(settings.globalScope.evaluate(BuiltinMacros.OTHER_LDFLAGS) == ["-other"])
4880+
}
4881+
}
4882+
48404883
@Test(.requireSDKs(.macOS, .iOS))
48414884
func platformConditionals() async throws {
48424885
let testWorkspace = try await TestWorkspace(

0 commit comments

Comments
 (0)