Differences between SDK, Swift SDK, Toolchain and Toolset

I’m fairly new to Swift tooling and I’m a bit confused.

swift build --help mentions these flags:

--toolset <toolset>     Specify a toolset JSON file to use when building for the   target platform. Use the option multiple times to specify more than one toolset. Toolsets will be merged in the order they're specified into a single
                          final toolset for the current build.

--swift-sdk <swift-sdk> Filter for selecting a specific Swift SDK to build with.
--triple <triple>
--sdk <sdk>
--toolchain <toolchain>
  1. What’s the difference between --sdk and -–swift-sdk. Could both be used at the same time or just one of them?
  2. What exactly is –-toolchain? I was under the impression that a toolchain (e.g. on macOS) contains the swift binary and selection of such toolchain is done via xcrun or swiftly run. Is there another concept of a toolchain for swift?
  3. What’s –-toolset? Is a Swift SDK the evolution of the concept of toolset JSON?
  4. For cross-compilation, would –swift-sdk be sufficient or is –triple still needed somehow? Is the former the better alternative for the latter?

I hope you don’t mind my questions. Even a little help would be much appreciated!

(I’m working on Swift support for JetBrains IDEs).

1 Like

Take a look at the cross-compilation SDK bundle spec, it explains a lot of this. Some of those flags you list didn't always work on the command line, so you're probably better off writing a destination JSON file instead.

Quickly, --sdk is the platform C/C++ SDK, whereas --swift-sdk is a bundle identifier or triple from a bundle. --toolchain is weird, used in some scenarios and not others, but I believe it is a way to pass in the Swift toolchain used. --toolset is a way to pass in fine-grained tools and flags to them: see that bundle spec, which was written when that was added.

--swift-sdk is usually sufficient because you can use it to specify the triple instead. Maybe both are only needed when multiple SDK bundles list the same triple, but I'm unsure if SwiftPM disambiguates those properly anyway.

2 Likes

The spec is for Swift SDK bundles, not "SDK bundle", that's a crucial difference.

SDKs, toolchains, and toolsets are low-level compiler driver building blocks that Swift SDK feature of SwiftPM is implemented with.

Most of the time as an end user of SwiftPM you only need Swift SDKs or toolsets, rarely both.

Toolsets allow setting up an ad-hoc build environment with custom options and tools specified in the toolset. Swift SDK packages up such environment in a directory (bundle) that you can re-distribute, it does include a toolset in most cases.

You might need to specify triples for those Swift SDKs that support multiple target triples to disambiguate which triple you're building for. Otherwise it's not needed, unless you're cross-compiling without a Swift SDK and again need to drop down to a lower level which requires an explicit triple.

1 Like

He is not an end user, but implementing Swift support for JetBrains IDEs, hence the detailed questions about our confusing terminology. :smiley:

As you might know, the standard IDE integration with Swift uses LSP, e.g., with vscode-swift; both are actively developed and have already solved much of the configuration and interaction complexity to build a reasonable interface and user experience. Would those help (to use or copy), or have you found them insufficient? (Do you need/want to update those efforts to suit them to JetBrains’ IDEs?)

LSP: < GitHub - swiftlang/sourcekit-lsp: Language Server Protocol implementation for Swift and C-based languages >

Sample integration: https://github.com/swiftlang/vscode-swift

I‘m already using sourcekit-lsp as a base layer for the functionality. By default, JetBrains is not based on LSP and is very different to VSCode.

But LSP doesn‘t cover things like syntax parsing/highlighting, executing swift programs, executing tests, debugging, UI to create new projects, configuring builds, etc.

I‘m aware of the VSCode integration.

1 Like

If I recall correctly, JetBrains IDEs use BSP? If so, maybe this could be helpful as inspiration, although it is tailored towards Bazel.