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
14 changes: 14 additions & 0 deletions Sources/SWBApplePlatform/Specs/MetalCompiler.xcspec
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,20 @@
NO = ();
};
},
{
Name = "METAL_INDEX_STORE_ONLY_PROJECT_FILES";
Type = Boolean;
DefaultValue = "$(INDEX_STORE_ONLY_PROJECT_FILES)";
Condition = "$(MTL_ENABLE_INDEX_STORE)";
CommandLineArgs = {
YES = (
// See corresponding definition in Clang.xcspec
"-index-ignore-system-symbols",
"-index-ignore-pcms",
);
NO = ();
};
},
{
Name = "MTL_LANGUAGE_REVISION";
Type = Enumeration;
Expand Down
14 changes: 14 additions & 0 deletions Sources/SWBCore/Specs/CoreBuildSystem.xcspec
Original file line number Diff line number Diff line change
Expand Up @@ -3505,6 +3505,20 @@ For more information on mergeable libraries, see [Configuring your project to us
DisplayName = "Enable Index-While-Building Functionality";
Description = "Control whether the compiler should emit index data while building.";
},
{
Name = "INDEX_STORE_ONLY_PROJECT_FILES";
Type = Boolean;
DefaultValue = NO;
DisplayName = "Index only project files";
Description = "Only index the source files that are being compiled within this project. Do not emit data into the index store for system modules.";
},
{
Name = "INDEX_STORE_COMPRESS";
Type = Boolean;
DefaultValue = NO;
DisplayName = "Compress Index Store";
Description = "Compress the index store, reducing its size on disk.";
},
{
Name = TOOLCHAINS;
Type = StringList;
Expand Down
40 changes: 40 additions & 0 deletions Sources/SWBUniversalPlatform/Specs/Clang.xcspec
Original file line number Diff line number Diff line change
Expand Up @@ -3116,6 +3116,46 @@
NO = ();
};
},
{
Name = "CLANG_INDEX_STORE_ONLY_PROJECT_FILES";
Type = Boolean;
DefaultValue = "$(INDEX_STORE_ONLY_PROJECT_FILES)";
Condition = "$(CLANG_INDEX_STORE_ENABLE)";
CommandLineArgs = {
YES = (
"-index-ignore-system-symbols",
// If the PCM covers files generated within the project, we should have indexed them in the task that compiles them, otherwise it's a system module that we don't want to index.
"-index-ignore-pcms",
);
NO = ();
};
},
{
Name = "CLANG_INDEX_STORE_COMPRESS";
Type = Boolean;
DefaultValue = "$(INDEX_STORE_COMPRESS)";
Condition = "$(CLANG_INDEX_STORE_ENABLE)";
CommandLineArgs = {
YES = (
"-index-store-compress",
);
NO = ();
};
},
{
Name = "CLANG_INDEX_STORE_IGNORE_MACROS";
Type = Boolean;
DefaultValue = NO;
Condition = "$(CLANG_INDEX_STORE_ENABLE)";
DisplayName = "Do not index C macros";
Description = "Do not emit entries for C macros into the Index Store.";
CommandLineArgs = {
YES = (
"-index-ignore-macros",
);
NO = ();
};
},

{
Name = "CLANG_ENABLE_COMPILE_CACHE";
Expand Down
27 changes: 27 additions & 0 deletions Sources/SWBUniversalPlatform/Specs/Swift.xcspec
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,33 @@
NO = ();
};
},
{
Name = "SWIFT_INDEX_STORE_ONLY_PROJECT_FILES";
Type = Boolean;
DefaultValue = "$(INDEX_STORE_ONLY_PROJECT_FILES)";
Condition = "$(SWIFT_INDEX_STORE_ENABLE)";
CommandLineArgs = {
YES = (
// Assume that clang modules are getting indexed by a clang file within them. While this is technically not correct, since you could have a clang module that only consists of header files and is only included from Swift, such scenarios are rare.
"-index-ignore-clang-modules",
"-index-ignore-system-modules",
);
NO = ();
};
},
{
Name = "SWIFT_INDEX_STORE_COMPRESS";
Type = Boolean;
DefaultValue = "$(INDEX_STORE_COMPRESS)";
Condition = "$(SWIFT_INDEX_STORE_ENABLE)";
CommandLineArgs = {
YES = (
"-Xfrontend",
"-index-store-compress",
);
NO = ();
};
},

// Swift caching options.
{
Expand Down
58 changes: 58 additions & 0 deletions Tests/SWBTaskConstructionTests/ClangTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,62 @@ fileprivate struct ClangTests: CoreBasedTests {
}
}
}


@Test(.requireSDKs(.host))
func indexOptions() async throws {
try await withTemporaryDirectory { tmpDir in
let testProject = TestProject(
"ProjectName",
sourceRoot: tmpDir,
groupTree: TestGroup(
"SomeFiles",
children: [
TestFile("File1.c")
]),
targets: [
TestStandardTarget(
"Test",
type: .dynamicLibrary,
buildConfigurations: [
TestBuildConfiguration(
"Debug",
buildSettings: [
"COMPILER_INDEX_STORE_ENABLE": "YES",
"INDEX_DATA_STORE_DIR": tmpDir.join("index").str,
"INDEX_STORE_COMPRESS": "YES",
"INDEX_STORE_ONLY_PROJECT_FILES": "YES",
"CLANG_INDEX_STORE_IGNORE_MACROS": "YES",
]
),
],
buildPhases: [
TestSourcesBuildPhase(["File1.c"]),
]
)
])

let core = try await getCore()
let tester = try TaskConstructionTester(core, testProject)
await tester.checkBuild(BuildParameters(configuration: "Debug", commandLineOverrides: ["INDEX_ENABLE_DATA_STORE": "YES"]), runDestination: .host) { results in
results.checkTask(.matchRuleType("CompileC")) { compileTask in
compileTask.checkCommandLineContains(["-index-store-path"])
compileTask.checkCommandLineContains(["-index-store-compress"])
compileTask.checkCommandLineContains(["-index-ignore-system-symbols"])
compileTask.checkCommandLineContains(["-index-ignore-pcms"])
compileTask.checkCommandLineContains(["-index-ignore-macros"])
}
}
// Check that we don't emit any index-related options when INDEX_ENABLE_DATA_STORE is not enabled
await tester.checkBuild(BuildParameters(configuration: "Debug", commandLineOverrides: [:]), runDestination: .host) { results in
results.checkTask(.matchRuleType("CompileC")) { compileTask in
compileTask.checkCommandLineDoesNotContain("-index-store-path")
compileTask.checkCommandLineDoesNotContain("-index-store-compress")
compileTask.checkCommandLineDoesNotContain("-index-ignore-system-symbols")
compileTask.checkCommandLineDoesNotContain("-index-ignore-pcms")
compileTask.checkCommandLineDoesNotContain("-index-ignore-macros")
}
}
}
}
}
75 changes: 75 additions & 0 deletions Tests/SWBTaskConstructionTests/MetalTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

import Testing
import SWBTestSupport
import SWBCore
import SWBUtil

@Suite
fileprivate struct MetalTests: CoreBasedTests {
@Test(.requireSDKs(.macOS), .skipInGitHubActions("Metal toolchain is not installed on GitHub runners"))
func indexOptions() async throws {
try await withTemporaryDirectory { tmpDir in
let testProject = TestProject(
"ProjectName",
sourceRoot: tmpDir,
groupTree: TestGroup(
"SomeFiles",
children: [
TestFile("File1.metal")
]),
targets: [
TestStandardTarget(
"Test",
type: .staticLibrary,
buildConfigurations: [
TestBuildConfiguration(
"Debug",
buildSettings: [
"COMPILER_INDEX_STORE_ENABLE": "YES",
"INDEX_DATA_STORE_DIR": tmpDir.join("index").str,
"INDEX_STORE_COMPRESS": "YES",
"INDEX_STORE_ONLY_PROJECT_FILES": "YES",
"CLANG_INDEX_STORE_IGNORE_MACROS": "YES",
]
),
],
buildPhases: [
TestSourcesBuildPhase(["File1.metal"]),
]
)
])

let core = try await getCore()
let tester = try TaskConstructionTester(core, testProject)
await tester.checkBuild(BuildParameters(configuration: "Debug", commandLineOverrides: ["INDEX_ENABLE_DATA_STORE": "YES"]), runDestination: .macOS) { results in
results.checkTask(.matchRuleType("CompileMetalFile")) { compileTask in
compileTask.checkCommandLineContains(["-index-store-path"])
compileTask.checkCommandLineContains(["-index-ignore-system-symbols"])
compileTask.checkCommandLineContains(["-index-ignore-pcms"])
// metal doesn't support index store compression at the moment.
compileTask.checkCommandLineDoesNotContain("-index-store-compress")
}
}
// Check that we don't emit any index-related options when INDEX_ENABLE_DATA_STORE is not enabled
await tester.checkBuild(BuildParameters(configuration: "Debug", commandLineOverrides: [:]), runDestination: .macOS) { results in
results.checkTask(.matchRuleType("CompileMetalFile")) { compileTask in
compileTask.checkCommandLineDoesNotContain("-index-store-path")
compileTask.checkCommandLineDoesNotContain("-index-store-compress")
compileTask.checkCommandLineDoesNotContain("-index-ignore-system-symbols")
compileTask.checkCommandLineDoesNotContain("-index-ignore-pcms")
}
}
}
}
}
56 changes: 56 additions & 0 deletions Tests/SWBTaskConstructionTests/SwiftTaskConstructionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4507,6 +4507,62 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
}
}
}

@Test(.requireSDKs(.host))
func indexOptions() async throws {
try await withTemporaryDirectory { tmpDir in
let testProject = try await TestProject(
"ProjectName",
sourceRoot: tmpDir,
groupTree: TestGroup(
"SomeFiles",
children: [
TestFile("File1.swift")
]),
targets: [
TestStandardTarget(
"Test",
type: .dynamicLibrary,
buildConfigurations: [
TestBuildConfiguration(
"Debug",
buildSettings: [
"SWIFT_EXEC": swiftCompilerPath.str,
"SWIFT_VERSION": swiftVersion,
"COMPILER_INDEX_STORE_ENABLE": "YES",
"INDEX_DATA_STORE_DIR": tmpDir.join("index").str,
"INDEX_STORE_COMPRESS": "YES",
"INDEX_STORE_ONLY_PROJECT_FILES": "YES"
]
),
],
buildPhases: [
TestSourcesBuildPhase(["File1.swift"]),
]
)
])

let core = try await getCore()
let tester = try TaskConstructionTester(core, testProject)
await tester.checkBuild(BuildParameters(configuration: "Debug", commandLineOverrides: ["INDEX_ENABLE_DATA_STORE": "YES"]), runDestination: .host) { results in
results.checkTask(.matchRuleType("SwiftDriver Compilation")) { compileTask in
compileTask.checkCommandLineContains(["-index-store-path"])
compileTask.checkCommandLineContains(["-Xfrontend", "-index-store-compress"])
compileTask.checkCommandLineContains(["-index-ignore-clang-modules"])
compileTask.checkCommandLineContains(["-index-ignore-system-modules"])
}
}
// Check that we don't emit any index-related options when INDEX_ENABLE_DATA_STORE is not enabled
await tester.checkBuild(BuildParameters(configuration: "Debug", commandLineOverrides: [:]), runDestination: .host) { results in
results.checkTask(.matchRuleType("SwiftDriver Compilation")) { compileTask in
compileTask.checkCommandLineDoesNotContain("-index-store-path")
compileTask.checkCommandLineDoesNotContain("-index-store-compress")
compileTask.checkCommandLineDoesNotContain("-index-ignore-clang-modules")
compileTask.checkCommandLineDoesNotContain("-index-ignore-system-modules")
}
}
}
}
}

private func XCTAssertEqual(_ lhs: EnvironmentBindings, _ rhs: [String: String], file: StaticString = #filePath, line: UInt = #line) {
Expand Down
Loading