The swift build --help has the following option
--auto-index-store/--enable-index-store/--disable-index-store
Enable or disable indexing-while-building feature. (default: --auto-index-store)
SwiftBuild should have an API to set this option. Ensure SwiftPM supported this with SwiftBuild.