Skip to content

Commit 008bd85

Browse files
authored
Start passing in -sdk-module-cache-path to swiftc command-line invocations for EBM builds (swiftlang#377)
This will be used to share modules built from interfaces in the SDK rdar://148465272
1 parent ad1ea35 commit 008bd85

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,11 +1800,15 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
18001800
args.append("-explicit-module-build")
18011801
let explicitDependencyOutputPath = Path(cbc.scope.evaluate(BuiltinMacros.SWIFT_EXPLICIT_MODULES_OUTPUT_PATH))
18021802
args.append(contentsOf: ["-module-cache-path", explicitDependencyOutputPath.str])
1803+
let moduleCacheDir = cbc.scope.evaluate(BuiltinMacros.MODULE_CACHE_DIR)
18031804
if LibSwiftDriver.supportsDriverFlag(spelled: "-clang-scanner-module-cache-path"),
1804-
!cbc.scope.evaluate(BuiltinMacros.MODULE_CACHE_DIR).isEmpty {
1805+
!moduleCacheDir.isEmpty {
18051806
// Specify the Clang scanner cache separately as a shared cache among different projects
1806-
let globalModuleCacheForScanningPath = cbc.scope.evaluate(BuiltinMacros.MODULE_CACHE_DIR)
1807-
args.append(contentsOf: ["-clang-scanner-module-cache-path", globalModuleCacheForScanningPath.str])
1807+
args.append(contentsOf: ["-clang-scanner-module-cache-path", moduleCacheDir.str])
1808+
}
1809+
if LibSwiftDriver.supportsDriverFlag(spelled: "-sdk-module-cache-path"),
1810+
!moduleCacheDir.isEmpty {
1811+
args.append(contentsOf: ["-sdk-module-cache-path", moduleCacheDir.str])
18081812
}
18091813
}
18101814
} else {

Tests/SWBTaskConstructionTests/SwiftTaskConstructionTests.swift

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,67 @@ fileprivate struct SwiftTaskConstructionTests: CoreBasedTests {
11571157
}
11581158
}
11591159

1160+
@Test(.requireSDKs(.macOS))
1161+
func swiftModuleCacheFlags() async throws {
1162+
let swiftCompilerPath = try await self.swiftCompilerPath
1163+
let swiftVersion = try await self.swiftVersion
1164+
let testProject = TestProject(
1165+
"aProject",
1166+
groupTree: TestGroup(
1167+
"SomeFiles", path: "Sources",
1168+
children: [
1169+
TestFile("Foo.swift"),
1170+
]),
1171+
buildConfigurations: [
1172+
TestBuildConfiguration(
1173+
"Debug",
1174+
buildSettings: [
1175+
"CODE_SIGN_IDENTITY": "",
1176+
"PRODUCT_NAME": "$(TARGET_NAME)",
1177+
"GCC_GENERATE_DEBUGGING_SYMBOLS": "NO",
1178+
"SWIFT_ENABLE_EXPLICIT_MODULES": "YES",
1179+
"SWIFT_EXPLICIT_MODULES_OUTPUT_PATH": "/path/to/ExplicitModules",
1180+
]),
1181+
],
1182+
targets: [
1183+
TestStandardTarget(
1184+
"CoreFoo", type: .framework,
1185+
buildConfigurations: [
1186+
TestBuildConfiguration("Debug",
1187+
buildSettings: [
1188+
"SDKROOT": "macosx",
1189+
"SWIFT_VERSION": swiftVersion,
1190+
]),
1191+
],
1192+
buildPhases: [
1193+
TestSourcesBuildPhase([
1194+
"Foo.swift",
1195+
]),
1196+
])
1197+
])
1198+
let core = try await getCore()
1199+
let tester = try TaskConstructionTester(core, testProject)
1200+
1201+
let fs = PseudoFS()
1202+
1203+
try await fs.writeFileContents(swiftCompilerPath) { $0 <<< "binary" }
1204+
let arena = ArenaInfo(derivedDataPath: Path("/path/to/DerivedData"), buildProductsPath: Path.root, buildIntermediatesPath: Path.root, pchPath: Path.root, indexRegularBuildProductsPath: nil, indexRegularBuildIntermediatesPath: nil, indexPCHPath: Path.root, indexDataStoreFolderPath: nil, indexEnableDataStore: false)
1205+
await tester.checkBuild(BuildParameters(configuration: "Debug", arena: arena), runDestination: .macOS, fs: fs) { results in
1206+
results.checkTarget("CoreFoo") { target in
1207+
results.checkTask(.matchTarget(target), .matchRuleType("SwiftDriver Compilation")) { task in
1208+
task.checkCommandLineContains(["-module-cache-path", "/path/to/ExplicitModules"])
1209+
if LibSwiftDriver.supportsDriverFlag(spelled: "-clang-scanner-module-cache-path") {
1210+
task.checkCommandLineContains(["-clang-scanner-module-cache-path", "/path/to/DerivedData/ModuleCache.noindex"])
1211+
}
1212+
if LibSwiftDriver.supportsDriverFlag(spelled: "-sdk-module-cache-path") {
1213+
task.checkCommandLineContains(["-sdk-module-cache-path", "/path/to/DerivedData/ModuleCache.noindex"])
1214+
}
1215+
}
1216+
}
1217+
results.checkNoDiagnostics()
1218+
}
1219+
}
1220+
11601221
@Test(.requireSDKs(.macOS))
11611222
func swiftLTO() async throws {
11621223
let testProject = try await TestProject(

0 commit comments

Comments
 (0)