Skip to content

Commit d67879e

Browse files
authored
Merge pull request #815 from ahoppen/index-store-options
Add build settings to control the emission of the Index Store
2 parents 17536f7 + 0d3e361 commit d67879e

File tree

7 files changed

+284
-0
lines changed

7 files changed

+284
-0
lines changed

Sources/SWBApplePlatform/Specs/MetalCompiler.xcspec

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,20 @@
235235
NO = ();
236236
};
237237
},
238+
{
239+
Name = "METAL_INDEX_STORE_ONLY_PROJECT_FILES";
240+
Type = Boolean;
241+
DefaultValue = "$(INDEX_STORE_ONLY_PROJECT_FILES)";
242+
Condition = "$(MTL_ENABLE_INDEX_STORE)";
243+
CommandLineArgs = {
244+
YES = (
245+
// See corresponding definition in Clang.xcspec
246+
"-index-ignore-system-symbols",
247+
"-index-ignore-pcms",
248+
);
249+
NO = ();
250+
};
251+
},
238252
{
239253
Name = "MTL_LANGUAGE_REVISION";
240254
Type = Enumeration;

Sources/SWBCore/Specs/CoreBuildSystem.xcspec

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3505,6 +3505,20 @@ For more information on mergeable libraries, see [Configuring your project to us
35053505
DisplayName = "Enable Index-While-Building Functionality";
35063506
Description = "Control whether the compiler should emit index data while building.";
35073507
},
3508+
{
3509+
Name = "INDEX_STORE_ONLY_PROJECT_FILES";
3510+
Type = Boolean;
3511+
DefaultValue = NO;
3512+
DisplayName = "Index only project files";
3513+
Description = "Only index the source files that are being compiled within this project. Do not emit data into the index store for system modules.";
3514+
},
3515+
{
3516+
Name = "INDEX_STORE_COMPRESS";
3517+
Type = Boolean;
3518+
DefaultValue = NO;
3519+
DisplayName = "Compress Index Store";
3520+
Description = "Compress the index store, reducing its size on disk.";
3521+
},
35083522
{
35093523
Name = TOOLCHAINS;
35103524
Type = StringList;

Sources/SWBUniversalPlatform/Specs/Clang.xcspec

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,6 +3116,46 @@
31163116
NO = ();
31173117
};
31183118
},
3119+
{
3120+
Name = "CLANG_INDEX_STORE_ONLY_PROJECT_FILES";
3121+
Type = Boolean;
3122+
DefaultValue = "$(INDEX_STORE_ONLY_PROJECT_FILES)";
3123+
Condition = "$(CLANG_INDEX_STORE_ENABLE)";
3124+
CommandLineArgs = {
3125+
YES = (
3126+
"-index-ignore-system-symbols",
3127+
// 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.
3128+
"-index-ignore-pcms",
3129+
);
3130+
NO = ();
3131+
};
3132+
},
3133+
{
3134+
Name = "CLANG_INDEX_STORE_COMPRESS";
3135+
Type = Boolean;
3136+
DefaultValue = "$(INDEX_STORE_COMPRESS)";
3137+
Condition = "$(CLANG_INDEX_STORE_ENABLE)";
3138+
CommandLineArgs = {
3139+
YES = (
3140+
"-index-store-compress",
3141+
);
3142+
NO = ();
3143+
};
3144+
},
3145+
{
3146+
Name = "CLANG_INDEX_STORE_IGNORE_MACROS";
3147+
Type = Boolean;
3148+
DefaultValue = NO;
3149+
Condition = "$(CLANG_INDEX_STORE_ENABLE)";
3150+
DisplayName = "Do not index C macros";
3151+
Description = "Do not emit entries for C macros into the Index Store.";
3152+
CommandLineArgs = {
3153+
YES = (
3154+
"-index-ignore-macros",
3155+
);
3156+
NO = ();
3157+
};
3158+
},
31193159

31203160
{
31213161
Name = "CLANG_ENABLE_COMPILE_CACHE";

Sources/SWBUniversalPlatform/Specs/Swift.xcspec

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,33 @@
13191319
NO = ();
13201320
};
13211321
},
1322+
{
1323+
Name = "SWIFT_INDEX_STORE_ONLY_PROJECT_FILES";
1324+
Type = Boolean;
1325+
DefaultValue = "$(INDEX_STORE_ONLY_PROJECT_FILES)";
1326+
Condition = "$(SWIFT_INDEX_STORE_ENABLE)";
1327+
CommandLineArgs = {
1328+
YES = (
1329+
// 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.
1330+
"-index-ignore-clang-modules",
1331+
"-index-ignore-system-modules",
1332+
);
1333+
NO = ();
1334+
};
1335+
},
1336+
{
1337+
Name = "SWIFT_INDEX_STORE_COMPRESS";
1338+
Type = Boolean;
1339+
DefaultValue = "$(INDEX_STORE_COMPRESS)";
1340+
Condition = "$(SWIFT_INDEX_STORE_ENABLE)";
1341+
CommandLineArgs = {
1342+
YES = (
1343+
"-Xfrontend",
1344+
"-index-store-compress",
1345+
);
1346+
NO = ();
1347+
};
1348+
},
13221349

13231350
// Swift caching options.
13241351
{

Tests/SWBTaskConstructionTests/ClangTests.swift

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,62 @@ fileprivate struct ClangTests: CoreBasedTests {
330330
}
331331
}
332332
}
333+
334+
335+
@Test(.requireSDKs(.host))
336+
func indexOptions() async throws {
337+
try await withTemporaryDirectory { tmpDir in
338+
let testProject = TestProject(
339+
"ProjectName",
340+
sourceRoot: tmpDir,
341+
groupTree: TestGroup(
342+
"SomeFiles",
343+
children: [
344+
TestFile("File1.c")
345+
]),
346+
targets: [
347+
TestStandardTarget(
348+
"Test",
349+
type: .dynamicLibrary,
350+
buildConfigurations: [
351+
TestBuildConfiguration(
352+
"Debug",
353+
buildSettings: [
354+
"COMPILER_INDEX_STORE_ENABLE": "YES",
355+
"INDEX_DATA_STORE_DIR": tmpDir.join("index").str,
356+
"INDEX_STORE_COMPRESS": "YES",
357+
"INDEX_STORE_ONLY_PROJECT_FILES": "YES",
358+
"CLANG_INDEX_STORE_IGNORE_MACROS": "YES",
359+
]
360+
),
361+
],
362+
buildPhases: [
363+
TestSourcesBuildPhase(["File1.c"]),
364+
]
365+
)
366+
])
367+
368+
let core = try await getCore()
369+
let tester = try TaskConstructionTester(core, testProject)
370+
await tester.checkBuild(BuildParameters(configuration: "Debug", commandLineOverrides: ["INDEX_ENABLE_DATA_STORE": "YES"]), runDestination: .host) { results in
371+
results.checkTask(.matchRuleType("CompileC")) { compileTask in
372+
compileTask.checkCommandLineContains(["-index-store-path"])
373+
compileTask.checkCommandLineContains(["-index-store-compress"])
374+
compileTask.checkCommandLineContains(["-index-ignore-system-symbols"])
375+
compileTask.checkCommandLineContains(["-index-ignore-pcms"])
376+
compileTask.checkCommandLineContains(["-index-ignore-macros"])
377+
}
378+
}
379+
// Check that we don't emit any index-related options when INDEX_ENABLE_DATA_STORE is not enabled
380+
await tester.checkBuild(BuildParameters(configuration: "Debug", commandLineOverrides: [:]), runDestination: .host) { results in
381+
results.checkTask(.matchRuleType("CompileC")) { compileTask in
382+
compileTask.checkCommandLineDoesNotContain("-index-store-path")
383+
compileTask.checkCommandLineDoesNotContain("-index-store-compress")
384+
compileTask.checkCommandLineDoesNotContain("-index-ignore-system-symbols")
385+
compileTask.checkCommandLineDoesNotContain("-index-ignore-pcms")
386+
compileTask.checkCommandLineDoesNotContain("-index-ignore-macros")
387+
}
388+
}
389+
}
390+
}
333391
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import Testing
14+
import SWBTestSupport
15+
import SWBCore
16+
import SWBUtil
17+
18+
@Suite
19+
fileprivate struct MetalTests: CoreBasedTests {
20+
@Test(.requireSDKs(.macOS), .skipInGitHubActions("Metal toolchain is not installed on GitHub runners"))
21+
func indexOptions() async throws {
22+
try await withTemporaryDirectory { tmpDir in
23+
let testProject = TestProject(
24+
"ProjectName",
25+
sourceRoot: tmpDir,
26+
groupTree: TestGroup(
27+
"SomeFiles",
28+
children: [
29+
TestFile("File1.metal")
30+
]),
31+
targets: [
32+
TestStandardTarget(
33+
"Test",
34+
type: .staticLibrary,
35+
buildConfigurations: [
36+
TestBuildConfiguration(
37+
"Debug",
38+
buildSettings: [
39+
"COMPILER_INDEX_STORE_ENABLE": "YES",
40+
"INDEX_DATA_STORE_DIR": tmpDir.join("index").str,
41+
"INDEX_STORE_COMPRESS": "YES",
42+
"INDEX_STORE_ONLY_PROJECT_FILES": "YES",
43+
"CLANG_INDEX_STORE_IGNORE_MACROS": "YES",
44+
]
45+
),
46+
],
47+
buildPhases: [
48+
TestSourcesBuildPhase(["File1.metal"]),
49+
]
50+
)
51+
])
52+
53+
let core = try await getCore()
54+
let tester = try TaskConstructionTester(core, testProject)
55+
await tester.checkBuild(BuildParameters(configuration: "Debug", commandLineOverrides: ["INDEX_ENABLE_DATA_STORE": "YES"]), runDestination: .macOS) { results in
56+
results.checkTask(.matchRuleType("CompileMetalFile")) { compileTask in
57+
compileTask.checkCommandLineContains(["-index-store-path"])
58+
compileTask.checkCommandLineContains(["-index-ignore-system-symbols"])
59+
compileTask.checkCommandLineContains(["-index-ignore-pcms"])
60+
// metal doesn't support index store compression at the moment.
61+
compileTask.checkCommandLineDoesNotContain("-index-store-compress")
62+
}
63+
}
64+
// Check that we don't emit any index-related options when INDEX_ENABLE_DATA_STORE is not enabled
65+
await tester.checkBuild(BuildParameters(configuration: "Debug", commandLineOverrides: [:]), runDestination: .macOS) { results in
66+
results.checkTask(.matchRuleType("CompileMetalFile")) { compileTask in
67+
compileTask.checkCommandLineDoesNotContain("-index-store-path")
68+
compileTask.checkCommandLineDoesNotContain("-index-store-compress")
69+
compileTask.checkCommandLineDoesNotContain("-index-ignore-system-symbols")
70+
compileTask.checkCommandLineDoesNotContain("-index-ignore-pcms")
71+
}
72+
}
73+
}
74+
}
75+
}

Tests/SWBTaskConstructionTests/SwiftTaskConstructionTests.swift

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4507,6 +4507,62 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
45074507
}
45084508
}
45094509
}
4510+
4511+
@Test(.requireSDKs(.host))
4512+
func indexOptions() async throws {
4513+
try await withTemporaryDirectory { tmpDir in
4514+
let testProject = try await TestProject(
4515+
"ProjectName",
4516+
sourceRoot: tmpDir,
4517+
groupTree: TestGroup(
4518+
"SomeFiles",
4519+
children: [
4520+
TestFile("File1.swift")
4521+
]),
4522+
targets: [
4523+
TestStandardTarget(
4524+
"Test",
4525+
type: .dynamicLibrary,
4526+
buildConfigurations: [
4527+
TestBuildConfiguration(
4528+
"Debug",
4529+
buildSettings: [
4530+
"SWIFT_EXEC": swiftCompilerPath.str,
4531+
"SWIFT_VERSION": swiftVersion,
4532+
"COMPILER_INDEX_STORE_ENABLE": "YES",
4533+
"INDEX_DATA_STORE_DIR": tmpDir.join("index").str,
4534+
"INDEX_STORE_COMPRESS": "YES",
4535+
"INDEX_STORE_ONLY_PROJECT_FILES": "YES"
4536+
]
4537+
),
4538+
],
4539+
buildPhases: [
4540+
TestSourcesBuildPhase(["File1.swift"]),
4541+
]
4542+
)
4543+
])
4544+
4545+
let core = try await getCore()
4546+
let tester = try TaskConstructionTester(core, testProject)
4547+
await tester.checkBuild(BuildParameters(configuration: "Debug", commandLineOverrides: ["INDEX_ENABLE_DATA_STORE": "YES"]), runDestination: .host) { results in
4548+
results.checkTask(.matchRuleType("SwiftDriver Compilation")) { compileTask in
4549+
compileTask.checkCommandLineContains(["-index-store-path"])
4550+
compileTask.checkCommandLineContains(["-Xfrontend", "-index-store-compress"])
4551+
compileTask.checkCommandLineContains(["-index-ignore-clang-modules"])
4552+
compileTask.checkCommandLineContains(["-index-ignore-system-modules"])
4553+
}
4554+
}
4555+
// Check that we don't emit any index-related options when INDEX_ENABLE_DATA_STORE is not enabled
4556+
await tester.checkBuild(BuildParameters(configuration: "Debug", commandLineOverrides: [:]), runDestination: .host) { results in
4557+
results.checkTask(.matchRuleType("SwiftDriver Compilation")) { compileTask in
4558+
compileTask.checkCommandLineDoesNotContain("-index-store-path")
4559+
compileTask.checkCommandLineDoesNotContain("-index-store-compress")
4560+
compileTask.checkCommandLineDoesNotContain("-index-ignore-clang-modules")
4561+
compileTask.checkCommandLineDoesNotContain("-index-ignore-system-modules")
4562+
}
4563+
}
4564+
}
4565+
}
45104566
}
45114567

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

0 commit comments

Comments
 (0)