Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,40 @@ for Ubuntu Jammy and Swift 5.9 this would be `swift:5.9-jammy-slim`. If you'd li
an arbitrary Ubuntu Jammy system, make sure you pass `--static-swift-stdlib` flag to `swift build`, in addition
to the `--experimental-swift-sdk` option.

## Common Generator Options

By default, on macOS hosts running on Apple Silicon, the Swift SDK Generator will create Swift SDKs
for Ubuntu Jammy on aarch64, which matches the arch of the host. However, it is possible to change
the default target architecture by passing the `--target` flag:

```bash
swift run swift-sdk-generator make-linux-sdk --target x86_64-unknown-linux-gnu
```

The Linux distribution name and version can also be passed to change from the default of Ubuntu Jammy:

```bash
swift run swift-sdk-generator make-linux-sdk --linux-distribution-name ubuntu --linux-distribution-version noble
```

### Host Toolchain

The host toolchain is not included in the generated Swift SDK by default on Linux to match the behavior
of the [Static Linux Swift SDKs](https://www.swift.org/documentation/articles/static-linux-getting-started.html)
downloadable from [swift.org](https://www.swift.org/install/). However, on macOS, since most users are using Xcode
and are likely not using the Swift OSS toolchain to build and run Swift projects, the Swift host toolchain
is included by *default*. This default behavior can be changed by passing `--no-host-toolchain`:

```bash
swift run swift-sdk-generator make-linux-sdk --no-host-toolchain --target x86_64-unknown-linux-gnu
```

Or, if on Linux, and desiring to generate the Swift SDK with the host toolchain included, add `--host-toolchain`:

```bash
swift run swift-sdk-generator make-linux-sdk --host-toolchain --target aarch64-unknown-linux-gnu
```

## Building an SDK from a container image

You can base your SDK on a container image, such as one of the
Expand Down
11 changes: 10 additions & 1 deletion Sources/GeneratorCLI/GeneratorCLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ extension GeneratorCLI {
but requires exactly the same version of the swift.org toolchain to be installed for it to work.
"""
)
var hostToolchain: Bool = false
var hostToolchain: Bool = hostToolchainDefault

@Option(
help: """
Expand Down Expand Up @@ -159,6 +159,15 @@ extension GeneratorCLI {
@Option(help: "Deprecated. Use `--target` instead")
var targetArch: Triple.Arch? = nil

/// Default to adding host toolchain when building on macOS
static var hostToolchainDefault: Bool {
#if os(macOS)
true
#else
false
#endif
}

func deriveHostTriple() throws -> Triple {
if let host {
return host
Expand Down