From 3890fa2ab06c382a1c9e1727fbccb5bd16a06476 Mon Sep 17 00:00:00 2001 From: Mirza Garibovic Date: Wed, 9 Jul 2025 11:12:52 -0700 Subject: [PATCH 1/2] Dependencies: emit warning instead of error if the Swift toolchain can't support VALIDATE_MODULE_DEPENDENCIES to match clang --- Sources/SWBCore/Dependencies.swift | 2 +- Tests/SWBBuildSystemTests/DependencyValidationTests.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/SWBCore/Dependencies.swift b/Sources/SWBCore/Dependencies.swift index 7fa0328e..ddfb4879 100644 --- a/Sources/SWBCore/Dependencies.swift +++ b/Sources/SWBCore/Dependencies.swift @@ -138,7 +138,7 @@ public struct ModuleDependenciesContext: Sendable, SerializableCodable { guard validate != .no else { return [] } guard let imports else { return [Diagnostic( - behavior: .error, + behavior: .warning, location: .unknown, data: DiagnosticData("The current toolchain does not support \(BuiltinMacros.VALIDATE_MODULE_DEPENDENCIES.name)"))] } diff --git a/Tests/SWBBuildSystemTests/DependencyValidationTests.swift b/Tests/SWBBuildSystemTests/DependencyValidationTests.swift index 21483f31..3908042d 100644 --- a/Tests/SWBBuildSystemTests/DependencyValidationTests.swift +++ b/Tests/SWBBuildSystemTests/DependencyValidationTests.swift @@ -446,7 +446,7 @@ fileprivate struct DependencyValidationTests: CoreBasedTests { let buildRequest = BuildRequest(parameters: parameters, buildTargets: [BuildRequest.BuildTargetInfo(parameters: parameters, target: target)], continueBuildingAfterErrors: false, useParallelTargets: true, useImplicitDependencies: true, useDryRun: false) try await tester.checkBuild(runDestination: .host, buildRequest: buildRequest, persistent: true) { results in - guard !results.checkError(.prefix("The current toolchain does not support VALIDATE_MODULE_DEPENDENCIES"), failIfNotFound: false) else { return } + guard !results.checkWarning(.prefix("The current toolchain does not support VALIDATE_MODULE_DEPENDENCIES"), failIfNotFound: false) else { return } for expectedDiag in expectedDiags { _ = results.check(.contains(expectedDiag.data.description), kind: expectedDiag.behavior, failIfNotFound: true, sourceLocation: #_sourceLocation) { diag in From 65486a75487402dfcca3139a0cdaf09fcc1bf2c7 Mon Sep 17 00:00:00 2001 From: Mirza Garibovic Date: Thu, 10 Jul 2025 14:20:45 -0700 Subject: [PATCH 2/2] Dependencies: include moduleDependenciesContext in the Swift compilation requirements signature --- .../Tools/SwiftCompiler.swift | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift b/Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift index bfd6b408..0bfa6c0b 100644 --- a/Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift +++ b/Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift @@ -2381,8 +2381,25 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi dependencyData = nil } + let compilationRequirementAdditionalSignatureData: String + if let moduleDependenciesContext = cbc.producer.moduleDependenciesContext { + do { + let jsonData = try JSONEncoder(outputFormatting: [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes]).encode(moduleDependenciesContext) + guard let signature = String(data: jsonData, encoding: .utf8) else { + throw StubError.error("non-UTF-8 data") + } + compilationRequirementAdditionalSignatureData = additionalSignatureData + "|\(signature)" + } catch { + delegate.error("failed to serialize 'MODULE_DEPENDENCIES' context information: \(error)") + return + } + } + else { + compilationRequirementAdditionalSignatureData = additionalSignatureData + } + // Compilation Requirements - delegate.createTask(type: self, dependencyData: dependencyData, payload: payload, ruleInfo: ruleInfo("SwiftDriver Compilation Requirements", targetName), additionalSignatureData: additionalSignatureData, commandLine: ["builtin-Swift-Compilation-Requirements", "--"] + args, environment: environmentBindings, workingDirectory: compilerWorkingDirectory(cbc), inputs: allInputsNodes, outputs: compilationRequirementOutputs, action: delegate.taskActionCreationDelegate.createSwiftCompilationRequirementTaskAction(), execDescription: archSpecificExecutionDescription(cbc.scope.namespace.parseString("Unblock downstream dependents of $PRODUCT_NAME"), cbc, delegate), preparesForIndexing: true, enableSandboxing: enableSandboxing, additionalTaskOrderingOptions: [.compilation, .compilationRequirement, .linkingRequirement, .blockedByTargetHeaders, .compilationForIndexableSourceFile], usesExecutionInputs: true, showInLog: true) + delegate.createTask(type: self, dependencyData: dependencyData, payload: payload, ruleInfo: ruleInfo("SwiftDriver Compilation Requirements", targetName), additionalSignatureData: compilationRequirementAdditionalSignatureData, commandLine: ["builtin-Swift-Compilation-Requirements", "--"] + args, environment: environmentBindings, workingDirectory: compilerWorkingDirectory(cbc), inputs: allInputsNodes, outputs: compilationRequirementOutputs, action: delegate.taskActionCreationDelegate.createSwiftCompilationRequirementTaskAction(), execDescription: archSpecificExecutionDescription(cbc.scope.namespace.parseString("Unblock downstream dependents of $PRODUCT_NAME"), cbc, delegate), preparesForIndexing: true, enableSandboxing: enableSandboxing, additionalTaskOrderingOptions: [.compilation, .compilationRequirement, .linkingRequirement, .blockedByTargetHeaders, .compilationForIndexableSourceFile], usesExecutionInputs: true, showInLog: true) if case .compile = compilationMode { // Unblocking compilation