Compiler flags for SwiftPM source & binary packages in Xcode

What compiler flags should be passed for SPM source & binary packages in Xcode when driving SourceKit-LSP via BSP?

Tags: SourceKit-LSP, SwiftPM, BSP, Xcode

Context

I’m building a BSP server to drive SourceKit-LSP for Xcode projects. These projects often depend on SwiftPM packages that Xcode resolves—both:

  • Source packages (compiled Swift/C targets)

  • Binary packages (delivered as .xcframeworks)

I want to supply SourceKit-LSP with the minimal correct set of compiler arguments for each Swift file, focusing specifically on flags needed for package dependencies so imports resolve and semantic features work.

Question

For an Xcode target that depends on SwiftPM packages, what flags must be passed to SourceKit-LSP for those dependencies?

Current understanding

For source packages

  • -I <path> to the Swift/Clang module outputs in DerivedData

  • -F <path> if the package produces frameworks

  • Any -Xcc flags SwiftPM provides for C targets (e.g. -Xcc -I, -Xcc -fmodule-map-file=<...>)

  • Defines from SwiftPM (-D FOO from SWIFT_ACTIVE_COMPILATION_CONDITIONS, etc.)

For binary packages (.xcframeworks)

  • -F <slice-path> for the correct architecture/platform slice

  • -framework <Name>

  • If static: -L <path> / -l<Name>

  • -Xcc -I or -fmodule-map-file=<...> for bundled headers/module maps in the xcframework

  • Possibly -Xlinker -rpath <...> if runtime lookup is required (but maybe not needed for SourceKit?)

Open questions

  1. Source packages:
    Are include paths + defines from SwiftPM sufficient for SourceKit-LSP, or are there additional flags required for it to correctly load dependent modules?

  2. Binary packages:

    • Does SourceKit-LSP need the linker-related flags (-framework, -L, -l, -rpath), or is it enough to provide the headers/module maps and .swiftinterface search paths?

    • Is there a canonical way to resolve the active slice of an .xcframework that matches the current -target, short of reimplementing Xcode’s selection logic?

  3. Public API for reading Xcode project dependencies:
    Is there any reliable, supported API (or stable file format) for reading out Xcode’s resolved package dependencies and their build settings per target, without invoking xcodebuild? Something like swift package describe --type json, but reflecting Xcode’s resolution and active configuration.

  4. Minimum set vs. full build flags:
    Is there a documented minimum flag set for package dependencies that guarantees SourceKit-LSP will resolve imports and conditionals correctly, without mirroring every single build flag from Xcode?

What I’ve tried

  • Hand-assembling -I/-F paths works for simple source packages, but breaks with binary packages and C targets.

Environment

  • Xcode ≥ 16.0

  • SourceKit-LSP ≥ 6.1.0

  • Platforms: iOS (sim/device), macOS

Ideal answer

  • Documentation or code references showing which dependency-related flags SourceKit-LSP actually consumes.

  • Guidance on extracting those flags for both source and binary packages in an Xcode context (without xcodebuild).

  • Clarification on whether linker flags are necessary, or whether search paths and defines alone are enough for SourceKit services.

  • Any pointer to a public API or reliable mechanism for reading Xcode’s resolved package dependencies and their effective build settings.

Thanks in advance!