Skip to content

Commit f974e0d

Browse files
committed
[Specs] Introduce COMPILATION_CACHE_ENABLE_CACHING for controlling all the compiler-specific caching settings
Also make the new setting, along with `COMPILATION_CACHE_ENABLE_DIAGNOSTIC_REMARKS` show up in settings UI.
1 parent 33cbda0 commit f974e0d

File tree

9 files changed

+38
-20
lines changed

9 files changed

+38
-20
lines changed

Sources/SWBCore/Settings/BuiltinMacros.swift

+2-11
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public final class BuiltinMacros {
507507
public static let CLANG_EXPLICIT_MODULES_IGNORE_LIBCLANG_VERSION_MISMATCH = BuiltinMacros.declareBooleanMacro("CLANG_EXPLICIT_MODULES_IGNORE_LIBCLANG_VERSION_MISMATCH")
508508
public static let CLANG_EXPLICIT_MODULES_OUTPUT_PATH = BuiltinMacros.declareStringMacro("CLANG_EXPLICIT_MODULES_OUTPUT_PATH")
509509
public static let SWIFT_EXPLICIT_MODULES_OUTPUT_PATH = BuiltinMacros.declareStringMacro("SWIFT_EXPLICIT_MODULES_OUTPUT_PATH")
510-
public static let CLANG_ENABLE_COMPILE_CACHE = BuiltinMacros.declareEnumMacro("CLANG_ENABLE_COMPILE_CACHE") as EnumMacroDeclaration<CompilationCachingSetting>
510+
public static let CLANG_ENABLE_COMPILE_CACHE = BuiltinMacros.declareBooleanMacro("CLANG_ENABLE_COMPILE_CACHE")
511511
public static let CLANG_CACHE_FINE_GRAINED_OUTPUTS = BuiltinMacros.declareEnumMacro("CLANG_CACHE_FINE_GRAINED_OUTPUTS") as EnumMacroDeclaration<FineGrainedCachingSetting>
512512
public static let CLANG_CACHE_FINE_GRAINED_OUTPUTS_VERIFICATION = BuiltinMacros.declareEnumMacro("CLANG_CACHE_FINE_GRAINED_OUTPUTS_VERIFICATION") as EnumMacroDeclaration<FineGrainedCachingVerificationSetting>
513513
public static let CLANG_DISABLE_DEPENDENCY_INFO_FILE = BuiltinMacros.declareBooleanMacro("CLANG_DISABLE_DEPENDENCY_INFO_FILE")
@@ -1066,7 +1066,7 @@ public final class BuiltinMacros {
10661066
public static let SWIFT_VERSION = BuiltinMacros.declareStringMacro("SWIFT_VERSION")
10671067
public static let EFFECTIVE_SWIFT_VERSION = BuiltinMacros.declareStringMacro("EFFECTIVE_SWIFT_VERSION")
10681068
public static let SWIFT_WHOLE_MODULE_OPTIMIZATION = BuiltinMacros.declareBooleanMacro("SWIFT_WHOLE_MODULE_OPTIMIZATION")
1069-
public static let SWIFT_ENABLE_COMPILE_CACHE = BuiltinMacros.declareEnumMacro("SWIFT_ENABLE_COMPILE_CACHE") as EnumMacroDeclaration<CompilationCachingSetting>
1069+
public static let SWIFT_ENABLE_COMPILE_CACHE = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_COMPILE_CACHE")
10701070
public static let SWIFT_ENABLE_PREFIX_MAPPING = BuiltinMacros.declareBooleanMacro("SWIFT_ENABLE_PREFIX_MAPPING")
10711071
public static let SWIFT_OTHER_PREFIX_MAPPINGS = BuiltinMacros.declareStringListMacro("SWIFT_OTHER_PREFIX_MAPPINGS")
10721072
public static let SYMBOL_GRAPH_EXTRACTOR_OUTPUT_DIR = BuiltinMacros.declareStringMacro("SYMBOL_GRAPH_EXTRACTOR_OUTPUT_DIR")
@@ -2631,15 +2631,6 @@ public enum SwiftDependencyRegistrationMode: String, Equatable, Hashable, Enumer
26312631
case verifySwiftDependencyScanner = "verify-swift-dependency-scanner"
26322632
}
26332633

2634-
/// Enumeration macro type for tri-state boolean value of whether the user has enabled compilation caching builds, disabled, or not set.
2635-
public enum CompilationCachingSetting: String, Equatable, Hashable, EnumerationMacroType {
2636-
public static let defaultValue = CompilationCachingSetting.notset
2637-
2638-
case notset = "NOT_SET"
2639-
case enabled = "YES"
2640-
case disabled = "NO"
2641-
}
2642-
26432634
public enum FineGrainedCachingSetting: String, Equatable, Hashable, EnumerationMacroType {
26442635
public static let defaultValue = FineGrainedCachingSetting.notset
26452636

Sources/SWBCore/Settings/Settings.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,11 @@ final class WorkspaceSettings: Sendable {
581581
}
582582

583583
if SWBFeatureFlag.enableClangCachingByDefault.value {
584-
table.push(BuiltinMacros.CLANG_ENABLE_COMPILE_CACHE, literal: .enabled)
584+
table.push(BuiltinMacros.CLANG_ENABLE_COMPILE_CACHE, literal: true)
585585
}
586586

587587
if SWBFeatureFlag.enableSwiftCachingByDefault.value {
588-
table.push(BuiltinMacros.SWIFT_ENABLE_COMPILE_CACHE, literal: .enabled)
588+
table.push(BuiltinMacros.SWIFT_ENABLE_COMPILE_CACHE, literal: true)
589589
}
590590

591591
return table

Sources/SWBCore/ShellScript.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public func computeScriptEnvironment(_ type: ScriptType, scope: MacroEvaluationS
216216
// Ensure that BUILD_DESCRIPTION_CACHE_DIR is never exported as it is *not* something we want customers to use.
217217
result.removeValue(forKey: BuiltinMacros.BUILD_DESCRIPTION_CACHE_DIR.name)
218218

219-
if scope.evaluate(BuiltinMacros.CLANG_ENABLE_COMPILE_CACHE) == .enabled {
219+
if scope.evaluate(BuiltinMacros.CLANG_ENABLE_COMPILE_CACHE) {
220220
// Make sure the cache directory is not going to be deleted via an `xcodebuild` invocation from the script.
221221
result["COMPILATION_CACHE_KEEP_CAS_DIRECTORY"] = "YES"
222222
}

Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
847847
return false
848848
}
849849

850-
let buildSettingEnabled = cbc.scope.evaluate(BuiltinMacros.CLANG_ENABLE_COMPILE_CACHE) == .enabled
850+
let buildSettingEnabled = cbc.scope.evaluate(BuiltinMacros.CLANG_ENABLE_COMPILE_CACHE)
851851

852852
// If a blocklist is provided in the toolchain, use it to determine the default for the current project
853853
guard let blocklist = clangInfo?.clangCachingBlocklist else {

Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
14121412
private func swiftCachingEnabled(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, _ moduleName: String, _ useIntegratedDriver: Bool, _ explicitModuleBuildEnabled: Bool, _ disabledPCHCompile: Bool) async -> Bool {
14131413
guard cbc.producer.supportsCompilationCaching else { return false }
14141414

1415-
guard cbc.scope.evaluate(BuiltinMacros.SWIFT_ENABLE_COMPILE_CACHE) == .enabled else {
1415+
guard cbc.scope.evaluate(BuiltinMacros.SWIFT_ENABLE_COMPILE_CACHE) else {
14161416
return false
14171417
}
14181418
if cbc.scope.evaluate(BuiltinMacros.INDEX_ENABLE_BUILD_ARENA) {

Sources/SWBCore/Specs/CoreBuildSystem.xcspec

+16
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,22 @@ For more information on mergeable libraries, see [Configuring your project to us
17481748
DefaultValue = NO;
17491749
},
17501750

1751+
{
1752+
Name = "COMPILATION_CACHE_ENABLE_CACHING";
1753+
Type = Boolean;
1754+
Category = "Compilation Caching";
1755+
DefaultValue = "$(COMPILATION_CACHE_ENABLE_CACHING_DEFAULT)";
1756+
DisplayName = "Enable Compilation Caching";
1757+
Description = "Caches the results of compilations for a particular set of inputs.";
1758+
},
1759+
{
1760+
Name = "COMPILATION_CACHE_ENABLE_DIAGNOSTIC_REMARKS";
1761+
Type = Boolean;
1762+
Category = "Compilation Caching";
1763+
DisplayName = "Compilation Caching Diagnostic Info";
1764+
Description = "Emits diagnostic information for cached compilation tasks.";
1765+
},
1766+
17511767
// FIXME: The TAPI settings should not need to be here in order to have them appear in the project editor UI.
17521768
{
17531769
Name = "SUPPORTS_TEXT_BASED_API";

Sources/SWBUniversalPlatform/Specs/Clang LLVM 1.0.xcspec

+6
Original file line numberDiff line numberDiff line change
@@ -2948,6 +2948,12 @@
29482948
};
29492949
},
29502950

2951+
{
2952+
Name = "CLANG_ENABLE_COMPILE_CACHE";
2953+
Type = Boolean;
2954+
DefaultValue = "$(COMPILATION_CACHE_ENABLE_CACHING)";
2955+
},
2956+
29512957
// Thread Sanitizer options.
29522958
{
29532959
Name = "CLANG_THREAD_SANITIZER";

Sources/SWBUniversalPlatform/Specs/Swift.xcspec

+5
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,11 @@
930930
Category = "General";
931931
Description = "Coordinates the build of the main module's modular dependencies via explicit tasks scheduled by the build system.";
932932
},
933+
{
934+
Name = "SWIFT_ENABLE_COMPILE_CACHE";
935+
Type = Boolean;
936+
DefaultValue = "$(COMPILATION_CACHE_ENABLE_CACHING)";
937+
},
933938
{
934939
Name = "SWIFT_GENERATE_ADDITIONAL_LINKER_ARGS";
935940
Type = Boolean;

Tests/SWBCoreTests/CommandLineSpecTests.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -1848,14 +1848,14 @@ import SWBMacro
18481848
let core = try await getCore()
18491849
let clangSpec = try core.specRegistry.getSpec("com.apple.compilers.llvm.clang.1_0") as CommandLineToolSpec
18501850
let mockFileType = try core.specRegistry.getSpec("sourcecode.cpp.cpp") as FileTypeSpec
1851-
let enableCompileCache = try #require(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("CLANG_ENABLE_COMPILE_CACHE") as? EnumMacroDeclaration<CompilationCachingSetting>)
1851+
let enableCompileCache = try #require(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("CLANG_ENABLE_COMPILE_CACHE") as? BooleanMacroDeclaration)
18521852
let enablePrefixMap = try #require(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("CLANG_ENABLE_PREFIX_MAPPING") as? BooleanMacroDeclaration)
18531853
let prefixMaps = try #require(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("CLANG_OTHER_PREFIX_MAPPINGS") as? StringListMacroDeclaration)
18541854
let devDir = try #require(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("DEVELOPER_DIR") as? PathMacroDeclaration)
18551855

18561856
func test(caching: Bool, prefixMapping: Bool, extraMaps: [String], completion: ([String]) throws -> Void) async throws {
18571857
var table = MacroValueAssignmentTable(namespace: core.specRegistry.internalMacroNamespace)
1858-
table.push(enableCompileCache, literal: caching ? .enabled : .disabled)
1858+
table.push(enableCompileCache, literal: caching)
18591859
table.push(enablePrefixMap, literal: prefixMapping)
18601860
table.push(prefixMaps, literal: extraMaps)
18611861
table.push(devDir, literal: "/Xcode.app/Contents/Developer")
@@ -1902,7 +1902,7 @@ import SWBMacro
19021902
let swiftSpec = try core.specRegistry.getSpec("com.apple.xcode.tools.swift.compiler") as CompilerSpec
19031903

19041904
let mockFileType = try core.specRegistry.getSpec("sourcecode.swift") as FileTypeSpec
1905-
let enableCompileCache = try #require(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("SWIFT_ENABLE_COMPILE_CACHE") as? EnumMacroDeclaration<CompilationCachingSetting>)
1905+
let enableCompileCache = try #require(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("SWIFT_ENABLE_COMPILE_CACHE") as? BooleanMacroDeclaration)
19061906
let enablePrefixMap = try #require(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("SWIFT_ENABLE_PREFIX_MAPPING") as? BooleanMacroDeclaration)
19071907
let prefixMaps = try #require(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("SWIFT_OTHER_PREFIX_MAPPINGS") as? StringListMacroDeclaration)
19081908
let devDir = try #require(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("DEVELOPER_DIR") as? PathMacroDeclaration)
@@ -1922,7 +1922,7 @@ import SWBMacro
19221922

19231923
// remove in rdar://53000820
19241924
table.push(BuiltinMacros.USE_SWIFT_RESPONSE_FILE, literal: true)
1925-
table.push(enableCompileCache, literal: caching ? .enabled : .disabled)
1925+
table.push(enableCompileCache, literal: caching)
19261926
table.push(enablePrefixMap, literal: prefixMapping)
19271927
table.push(prefixMaps, literal: extraMaps)
19281928
table.push(devDir, literal: "/Xcode.app/Contents/Developer")

0 commit comments

Comments
 (0)