@@ -43,7 +43,7 @@ struct SessionFailedError: Error {
4343 var diagnostics : [ SwiftBuild . SwiftBuildMessage . DiagnosticInfo ]
4444}
4545
46- func withService< T> (
46+ package func withService< T> (
4747 connectionMode: SWBBuildServiceConnectionMode = . default,
4848 variant: SWBBuildServiceVariant = . default,
4949 serviceBundleURL: URL ? = nil ,
@@ -860,7 +860,11 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
860860 )
861861 }
862862
863- private func makeBuildParameters( session: SWBBuildServiceSession , symbolGraphOptions: BuildOutput . SymbolGraphOptions ? ) async throws -> SwiftBuild . SWBBuildParameters {
863+ internal func makeBuildParameters(
864+ session: SWBBuildServiceSession ,
865+ symbolGraphOptions: BuildOutput . SymbolGraphOptions ? ,
866+ setToolchainSetting: Bool = true ,
867+ ) async throws -> SwiftBuild . SWBBuildParameters {
864868 // Generate the run destination parameters.
865869 let runDestination = makeRunDestination ( )
866870
@@ -872,17 +876,19 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
872876 // Generate a table of any overriding build settings.
873877 var settings : [ String : String ] = [ : ]
874878
875- // If the SwiftPM toolchain corresponds to a toolchain registered with the lower level build system, add it to the toolchain stack.
876- // Otherwise, apply overrides for each component of the SwiftPM toolchain.
877- if let toolchainID = try await session. lookupToolchain ( at: buildParameters. toolchain. toolchainDir. pathString) {
878- settings [ " TOOLCHAINS " ] = " \( toolchainID. rawValue) $(inherited) "
879- } else {
880- // FIXME: This list of overrides is incomplete.
881- // An error with determining the override should not be fatal here.
882- settings [ " CC " ] = try ? buildParameters. toolchain. getClangCompiler ( ) . pathString
883- // Always specify the path of the effective Swift compiler, which was determined in the same way as for the
884- // native build system.
885- settings [ " SWIFT_EXEC " ] = buildParameters. toolchain. swiftCompilerPath. pathString
879+ if setToolchainSetting {
880+ // If the SwiftPM toolchain corresponds to a toolchain registered with the lower level build system, add it to the toolchain stack.
881+ // Otherwise, apply overrides for each component of the SwiftPM toolchain.
882+ if let toolchainID = try await session. lookupToolchain ( at: buildParameters. toolchain. toolchainDir. pathString) {
883+ settings [ " TOOLCHAINS " ] = " \( toolchainID. rawValue) $(inherited) "
884+ } else {
885+ // FIXME: This list of overrides is incomplete.
886+ // An error with determining the override should not be fatal here.
887+ settings [ " CC " ] = try ? buildParameters. toolchain. getClangCompiler ( ) . pathString
888+ // Always specify the path of the effective Swift compiler, which was determined in the same way as for the
889+ // native build system.
890+ settings [ " SWIFT_EXEC " ] = buildParameters. toolchain. swiftCompilerPath. pathString
891+ }
886892 }
887893
888894 // FIXME: workaround for old Xcode installations such as what is in CI
@@ -985,6 +991,38 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
985991 settings [ " GENERATE_TEST_ENTRYPOINTS_FOR_BUNDLES " ] = " YES "
986992 }
987993
994+ // Set the value of the index store
995+ struct IndexStoreSettings {
996+ let enableVariableName : String
997+ let pathVariable : String
998+ }
999+
1000+ let indexStoreSettingNames : [ IndexStoreSettings ] = [
1001+ IndexStoreSettings (
1002+ enableVariableName: " CLANG_INDEX_STORE_ENABLE " ,
1003+ pathVariable: " CLANG_INDEX_STORE_PATH " ,
1004+ ) ,
1005+ IndexStoreSettings (
1006+ enableVariableName: " SWIFT_INDEX_STORE_ENABLE " ,
1007+ pathVariable: " SWIFT_INDEX_STORE_PATH " ,
1008+ ) ,
1009+ ]
1010+
1011+ switch self . buildParameters. indexStoreMode {
1012+ case . on:
1013+ for setting in indexStoreSettingNames {
1014+ settings [ setting. enableVariableName] = " YES "
1015+ settings [ setting. pathVariable] = self . buildParameters. indexStore. pathString
1016+ }
1017+ case . off:
1018+ for setting in indexStoreSettingNames {
1019+ settings [ setting. enableVariableName] = " NO "
1020+ }
1021+ case . auto:
1022+ // The settings are handles in the PIF builder
1023+ break
1024+ }
1025+
9881026 func reportConflict( _ a: String , _ b: String ) throws -> String {
9891027 throw StringError ( " Build parameters constructed conflicting settings overrides ' \( a) ' and ' \( b) ' " )
9901028 }
@@ -1223,13 +1261,13 @@ fileprivate extension SwiftBuild.SwiftBuildMessage.DiagnosticInfo.Location {
12231261 case . none:
12241262 return path
12251263 }
1226-
1264+
12271265 case . buildSettings( let names) :
12281266 return names. joined ( separator: " , " )
1229-
1267+
12301268 case . buildFiles( let buildFiles, let targetGUID) :
12311269 return " \( targetGUID) : " + buildFiles. map { String ( describing: $0) } . joined ( separator: " , " )
1232-
1270+
12331271 case . unknown:
12341272 return nil
12351273 }
0 commit comments