Skip to content

Commit 50e4330

Browse files
Don't plan compileJob if emitModule is all that is needed in a separate job
When the requested output is `-emit-module` and also using `-experimental-emit-module-separately`, do not schedule compileJob for each individual source files since all outputs already satisfied by the separately emit module job. The compileJob will only produce unnecessary outputs like per-file modules and slow down the build. rdar://84979778
1 parent 4e5cfa4 commit 50e4330

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,9 @@ extension Driver {
470470
assert(backendJobs.count <= 1)
471471
addCompileJobGroup(CompileJobGroup(compileJob: compile, backendJob: backendJobs.first))
472472
} else {
473-
// TODO: if !canSkipIfOnlyModule {
474-
// Some other tools still expect the partial jobs. Bring this check
475-
// back once they are updated. rdar://84979778
476-
477473
// We can skip the compile jobs if all we want is a module when it's
478474
// built separately.
475+
if parsedOptions.hasArgument(.driverExplicitModuleBuild), canSkipIfOnlyModule { return }
479476
let compile = try compileJob(primaryInputs: [primaryInput],
480477
outputType: compilerOutputType,
481478
addJobOutputs: addJobOutputs,

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,6 +2269,44 @@ final class ExplicitModuleBuildTests: XCTestCase {
22692269
}
22702270
}
22712271

2272+
func testEmitModuleSeparatelyJobs() throws {
2273+
try withTemporaryDirectory { path in
2274+
try localFileSystem.changeCurrentWorkingDirectory(to: path)
2275+
let moduleCachePath = path.appending(component: "ModuleCache")
2276+
try localFileSystem.createDirectory(moduleCachePath)
2277+
let fileA = path.appending(component: "fileA.swift")
2278+
try localFileSystem.writeFileContents(fileA, bytes:
2279+
"""
2280+
public struct A {}
2281+
"""
2282+
)
2283+
let fileB = path.appending(component: "fileB.swift")
2284+
try localFileSystem.writeFileContents(fileB, bytes:
2285+
"""
2286+
public struct B {}
2287+
"""
2288+
)
2289+
2290+
let outputModule = path.appending(component: "Test.swiftmodule")
2291+
let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? []
2292+
var driver = try Driver(args: ["swiftc",
2293+
"-explicit-module-build", "-v", "-module-name", "Test",
2294+
"-module-cache-path", moduleCachePath.nativePathString(escaped: true),
2295+
"-working-directory", path.nativePathString(escaped: true),
2296+
"-emit-module", outputModule.nativePathString(escaped: true),
2297+
"-experimental-emit-module-separately",
2298+
fileA.nativePathString(escaped: true), fileB.nativePathString(escaped: true)] + sdkArgumentsForTesting,
2299+
env: ProcessEnv.vars)
2300+
let jobs = try driver.planBuild()
2301+
let compileJobs = jobs.filter({ $0.kind == .compile })
2302+
XCTAssertEqual(compileJobs.count, 0)
2303+
let emitModuleJob = jobs.filter({ $0.kind == .emitModule })
2304+
XCTAssertEqual(emitModuleJob.count, 1)
2305+
try driver.run(jobs: jobs)
2306+
XCTAssertFalse(driver.diagnosticEngine.hasErrors)
2307+
}
2308+
}
2309+
22722310
// We only care about prebuilt modules in macOS.
22732311
#if os(macOS)
22742312
func testPrebuiltModuleGenerationJobs() throws {

0 commit comments

Comments
 (0)