@@ -2691,12 +2691,11 @@ final class SwiftDriverTests: XCTestCase {
26912691 func testEmitModuleSeparatelyWMO( ) throws {
26922692 var envVars = ProcessEnv . vars
26932693 envVars [ " SWIFT_DRIVER_LD_EXEC " ] = ld. nativePathString ( escaped: false )
2694+ let root = try localFileSystem. currentWorkingDirectory. map { AbsolutePath ( " /foo/bar " , relativeTo: $0) }
2695+ ?? AbsolutePath ( validating: " /foo/bar " )
26942696
26952697 do {
2696- let symbolGraphDir =
2697- try localFileSystem. currentWorkingDirectory. map { AbsolutePath ( " /foo/bar " , relativeTo: $0) }
2698- ?? AbsolutePath ( validating: " /Foo/Bar " )
2699- var driver = try Driver ( args: [ " swiftc " , " foo.swift " , " bar.swift " , " -module-name " , " Test " , " -emit-module-path " , rebase ( " Test.swiftmodule " , at: symbolGraphDir) , " -emit-symbol-graph " , " -emit-symbol-graph-dir " , symbolGraphDir. pathString, " -emit-library " , " -target " , " x86_64-apple-macosx10.15 " , " -wmo " , " -emit-module-separately-wmo " ] ,
2698+ var driver = try Driver ( args: [ " swiftc " , " foo.swift " , " bar.swift " , " -module-name " , " Test " , " -emit-module-path " , rebase ( " Test.swiftmodule " , at: root) , " -emit-symbol-graph " , " -emit-symbol-graph-dir " , root. pathString, " -emit-library " , " -target " , " x86_64-apple-macosx10.15 " , " -wmo " , " -emit-module-separately-wmo " ] ,
27002699 env: envVars)
27012700
27022701 let abiFileCount = ( driver. isFeatureSupported ( . emit_abi_descriptor) && driver. targetTriple. isDarwin) ? 1 : 0
@@ -2715,21 +2714,18 @@ final class SwiftDriverTests: XCTestCase {
27152714 let emitModuleJob = plannedJobs. first ( where: { $0. kind == . emitModule} ) !
27162715 XCTAssertTrue ( emitModuleJob. tool. name. contains ( " swift " ) )
27172716 XCTAssertEqual ( emitModuleJob. outputs. count, 3 + abiFileCount)
2718- XCTAssertEqual ( 1 , emitModuleJob. outputs. filter ( { $0. file == . absolute( AbsolutePath ( rebase ( " Test.swiftmodule " , at: symbolGraphDir ) ) ) } ) . count)
2719- XCTAssertEqual ( 1 , emitModuleJob. outputs. filter ( { $0. file == . absolute( AbsolutePath ( rebase ( " Test.swiftdoc " , at: symbolGraphDir ) ) ) } ) . count)
2720- XCTAssertEqual ( 1 , emitModuleJob. outputs. filter ( { $0. file == . absolute( AbsolutePath ( rebase ( " Test.swiftsourceinfo " , at: symbolGraphDir ) ) ) } ) . count)
2717+ XCTAssertEqual ( 1 , emitModuleJob. outputs. filter ( { $0. file == . absolute( AbsolutePath ( rebase ( " Test.swiftmodule " , at: root ) ) ) } ) . count)
2718+ XCTAssertEqual ( 1 , emitModuleJob. outputs. filter ( { $0. file == . absolute( AbsolutePath ( rebase ( " Test.swiftdoc " , at: root ) ) ) } ) . count)
2719+ XCTAssertEqual ( 1 , emitModuleJob. outputs. filter ( { $0. file == . absolute( AbsolutePath ( rebase ( " Test.swiftsourceinfo " , at: root ) ) ) } ) . count)
27212720 if abiFileCount == 1 {
2722- XCTAssertEqual ( abiFileCount, emitModuleJob. outputs. filter ( { $0. file == . absolute( AbsolutePath ( rebase ( " Test.abi.json " , at: symbolGraphDir ) ) ) } ) . count)
2721+ XCTAssertEqual ( abiFileCount, emitModuleJob. outputs. filter ( { $0. file == . absolute( AbsolutePath ( rebase ( " Test.abi.json " , at: root ) ) ) } ) . count)
27232722 }
27242723
27252724 // We don't know the output file of the symbol graph, just make sure the flag is passed along.
27262725 XCTAssertTrue ( emitModuleJob. commandLine. contains ( . flag( " -emit-symbol-graph-dir " ) ) )
27272726 }
27282727
27292728 do {
2730- let root = try localFileSystem. currentWorkingDirectory. map { AbsolutePath ( " /foo/bar " , relativeTo: $0) }
2731- ?? AbsolutePath ( validating: " /foo/bar " )
2732-
27332729 // Ignore the `-emit-module-separately-wmo` flag when building only the module files to avoid duplicating outputs.
27342730 var driver = try Driver ( args: [ " swiftc " , " foo.swift " , " bar.swift " , " -module-name " , " Test " , " -emit-module-path " , rebase ( " Test.swiftmodule " , at: root) , " -wmo " , " -emit-module-separately-wmo " ] )
27352731 let abiFileCount = ( driver. isFeatureSupported ( . emit_abi_descriptor) && driver. targetTriple. isDarwin) ? 1 : 0
@@ -2750,9 +2746,6 @@ final class SwiftDriverTests: XCTestCase {
27502746 }
27512747
27522748 do {
2753- let root = try localFileSystem. currentWorkingDirectory. map { AbsolutePath ( " /foo/bar " , relativeTo: $0) }
2754- ?? AbsolutePath ( validating: " /foo/bar " )
2755-
27562749 // Specifying -no-emit-module-separately-wmo doesn't schedule the separate emit-module job.
27572750 var driver = try Driver ( args: [ " swiftc " , " foo.swift " , " bar.swift " , " -module-name " , " Test " , " -emit-module-path " , rebase ( " Test.swiftmodule " , at: root) , " -emit-library " , " -wmo " , " -emit-module-separately-wmo " , " -no-emit-module-separately-wmo " ] )
27582751 let abiFileCount = ( driver. isFeatureSupported ( . emit_abi_descriptor) && driver. targetTriple. isDarwin) ? 1 : 0
@@ -2777,6 +2770,40 @@ final class SwiftDriverTests: XCTestCase {
27772770 }
27782771 }
27792772
2773+ #if os(Linux) || os(Android)
2774+ let autoLinkExtractJob = 1
2775+ #else
2776+ let autoLinkExtractJob = 0
2777+ #endif
2778+
2779+ do {
2780+ // non library-evolution builds require a single job, because cross-module-optimization is enabled by default.
2781+ var driver = try Driver ( args: [ " swiftc " , " foo.swift " , " bar.swift " , " -module-name " , " Test " , " -emit-module-path " , rebase ( " Test.swiftmodule " , at: root) , " -c " , " -o " , rebase ( " test.o " , at: root) , " -wmo " , " -O " ] )
2782+ let plannedJobs = try driver. planBuild ( )
2783+ XCTAssertEqual ( plannedJobs. count, 1 + autoLinkExtractJob)
2784+ }
2785+
2786+ do {
2787+ // library-evolution builds can emit the module in a separate job.
2788+ var driver = try Driver ( args: [ " swiftc " , " foo.swift " , " bar.swift " , " -module-name " , " Test " , " -emit-module-path " , rebase ( " Test.swiftmodule " , at: root) , " -c " , " -o " , rebase ( " test.o " , at: root) , " -wmo " , " -O " , " -enable-library-evolution " ] )
2789+ let plannedJobs = try driver. planBuild ( )
2790+ XCTAssertEqual ( plannedJobs. count, 2 + autoLinkExtractJob)
2791+ }
2792+
2793+ do {
2794+ // When disabling cross-module-optimization, the module can be emitted in a separate job.
2795+ var driver = try Driver ( args: [ " swiftc " , " foo.swift " , " bar.swift " , " -module-name " , " Test " , " -emit-module-path " , rebase ( " Test.swiftmodule " , at: root) , " -c " , " -o " , rebase ( " test.o " , at: root) , " -wmo " , " -O " , " -disable-cmo " ] )
2796+ let plannedJobs = try driver. planBuild ( )
2797+ XCTAssertEqual ( plannedJobs. count, 2 + autoLinkExtractJob)
2798+ }
2799+
2800+ do {
2801+ // non optimized builds can emit the module in a separate job.
2802+ var driver = try Driver ( args: [ " swiftc " , " foo.swift " , " bar.swift " , " -module-name " , " Test " , " -emit-module-path " , rebase ( " Test.swiftmodule " , at: root) , " -c " , " -o " , rebase ( " test.o " , at: root) , " -wmo " ] )
2803+ let plannedJobs = try driver. planBuild ( )
2804+ XCTAssertEqual ( plannedJobs. count, 2 + autoLinkExtractJob)
2805+ }
2806+
27802807 do {
27812808 // Don't use emit-module-separetely as a linker.
27822809 var driver = try Driver ( args: [ " swiftc " , " foo.sil " , " bar.sil " , " -module-name " , " Test " , " -emit-module-path " , " /foo/bar/Test.swiftmodule " , " -emit-library " , " -target " , " x86_64-apple-macosx10.15 " , " -wmo " , " -emit-module-separately-wmo " ] ,
0 commit comments