Skip to content

Use experimental prefix only for old Swift versions #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Pull request

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
tests:
name: Test
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
with:
linux_pre_build_command: apt-get update && apt-get install -y locales locales-all libsqlite3-dev
enable_windows_checks: false
soundness:
name: Soundness
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
with:
api_breakage_check_enabled: false
12 changes: 12 additions & 0 deletions .license_header_template
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@@===----------------------------------------------------------------------===@@
@@
@@ This source file is part of the Swift open source project
@@
@@ Copyright (c) YEARS Apple Inc. and the Swift project authors
@@ Licensed under Apache License v2.0 with Runtime Library Exception
@@
@@ See https://swift.org/LICENSE.txt for license information
@@ See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
@@
@@===----------------------------------------------------------------------===@@

22 changes: 22 additions & 0 deletions .licenseignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.gitignore
.swiftformat
.swiftformatignore
.editorconfig
.unacceptablelanguageignore
Brewfile
Package.swift
Package.resolved
*.md
*.txt
*.yml
**/.editorconfig
**/*.docc/**
**/*.entitlements
**/*.input
**/*.modulemap
**/*.plist
**/*.xcodeproj/**
**/CODEOWNERS
**/Dockerfile
**/Package.swift
Utilities/git.commit.template
70 changes: 70 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"fileScopedDeclarationPrivacy" : {
"accessLevel" : "private"
},
"indentConditionalCompilationBlocks" : true,
"indentSwitchCaseLabels" : false,
"indentation" : {
"spaces" : 2
},
"lineBreakAroundMultilineExpressionChainComponents" : false,
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : true,
"lineBreakBeforeEachGenericRequirement" : false,
"lineLength" : 120,
"maximumBlankLines" : 1,
"multiElementCollectionTrailingCommas" : true,
"noAssignmentInExpressions" : {
"allowedFunctions" : [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether" : false,
"respectsExistingLineBreaks" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : false,
"AlwaysUseLowerCamelCase" : false,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
"DoNotUseSemicolons" : true,
"DontRepeatTypeInStaticProperties" : true,
"FileScopedDeclarationPrivacy" : true,
"FullyIndirectEnum" : true,
"GroupNumericLiterals" : true,
"IdentifiersMustBeASCII" : true,
"NeverForceUnwrap" : false,
"NeverUseForceTry" : false,
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : true,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : true,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoPlaygroundLiterals" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : false,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : true,
"ReplaceForEachWithForLoop" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"TypeNamesShouldBeCapitalized" : true,
"UseEarlyExits" : false,
"UseExplicitNilCheckInConditions" : true,
"UseLetInEveryBoundCaseVariable" : false,
"UseShorthandTypeNames" : true,
"UseSingleLinePropertyGetter" : true,
"UseSynthesizedInitializer" : true,
"UseTripleSlashForDocumentationComments" : true,
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : false
},
"spacesAroundRangeFormationOperators" : false,
"tabWidth" : 8,
"version" : 1
}
2 changes: 2 additions & 0 deletions .swiftformatignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Sources/Helpers/Vendor/*
Sources/AsyncProcess/ProcessExecutor.swift
2 changes: 2 additions & 0 deletions .unacceptablelanguageignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Sources/AsyncProcess/ProcessExecutor.swift
Tests/AsyncProcessTests/IntegrationTests.swift
25 changes: 1 addition & 24 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,6 @@ We require that your commit messages match our template. The easiest way to do t

git config commit.template Utilities/git.commit.template

### Run `./Utilities/soundness.sh`

The scripts directory contains a [`soundness.sh` script](https://github.com/apple/swift-sdk-generator/blob/main/Utilities/soundness.sh)
that enforces additional checks, like license headers and formatting style.

Please make sure to run `./Utilities/soundness.sh` before pushing a change upstream, otherwise it is likely the PR validation will fail
on minor changes such as formatting issues.

For frequent contributors, we recommend adding the script as a [git pre-push hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks), which you can do via executing the following command in the project root directory:

```bash
cat << EOF > .git/hooks/pre-push

if [[ -f "Utilities/soundness.sh" ]]; then
Utilities/soundness.sh
fi
EOF
```

Which makes the script execute, and only allow the `git push` to complete if the check has passed.

In the case of formatting issues, you can then `git add` the formatting changes, and attempt the push again.

## How to contribute your work

Please open a pull request at https://github.com/apple/swift-sdk-generator. Make sure the CI passes, and then wait for code review.
Please open a pull request at https://github.com/apple/swift-sdk-generator. Make sure the CI passes, and then wait for code review.
4 changes: 0 additions & 4 deletions Docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ services:
- ..:/code:z
working_dir: /code

soundness:
<<: *common
command: /bin/bash -xcl "swift -version && uname -a && ./Utilities/soundness.sh"

test:
<<: *common
environment:
Expand Down
18 changes: 9 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.8
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -11,7 +11,7 @@ let package = Package(
.executable(
name: "swift-sdk-generator",
targets: ["GeneratorCLI"]
),
)
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand All @@ -23,7 +23,7 @@ let package = Package(
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency=complete"),
.enableExperimentalFeature("StrictConcurrency=complete")
]
),
.target(
Expand All @@ -38,22 +38,22 @@ let package = Package(
],
exclude: ["Dockerfiles"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency=complete"),
.enableExperimentalFeature("StrictConcurrency=complete")
]
),
.testTarget(
name: "SwiftSDKGeneratorTests",
dependencies: [
"SwiftSDKGenerator",
"SwiftSDKGenerator"
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency=complete"),
.enableExperimentalFeature("StrictConcurrency=complete")
]
),
.testTarget(
name: "GeneratorEngineTests",
dependencies: [
"Helpers",
"Helpers"
]
),
.target(
Expand All @@ -66,13 +66,13 @@ let package = Package(
],
exclude: ["Vendor/README.md"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency=complete"),
.enableExperimentalFeature("StrictConcurrency=complete")
]
),
.testTarget(
name: "HelpersTests",
dependencies: [
"Helpers",
"Helpers"
]
),
.systemLibrary(name: "SystemSQLite", pkgConfig: "sqlite3"),
Expand Down
50 changes: 38 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@ a newly generated Swift SDK for users to install.

## Requirements

Usage of Swift SDKs requires Swift 5.9, follow [installation instructions on swift.org](https://www.swift.org/install/) to install it first.
Usage of Swift SDKs requires Swift 6.0 or later (experimental implementation is available in Swift 5.9/5.10), follow [installation instructions on swift.org](https://www.swift.org/install/) to install it first.

After that, verify that the `sdk` command is available:

```
swift sdk list
```

For Swift 5.9/5.10 add `experimental-` prefix to the command invocation:

After that, verify that the `experimental-sdk` command is available:

```
swift experimental-sdk list
```

The output will either state that no Swift SDKs are available, or produce a list of those you previously had
installed, in case you've used the `swift experimental-sdk install` command before.
installed, in case you've used the `swift sdk install` (or `swift experimental-sdk install` with Swift 5.9/5.10) command before.

### macOS Requirements

Expand All @@ -47,14 +54,14 @@ The generator also allows cross-compiling between any Linux distributions offici
| macOS (arm64) | ✅ macOS 13.0+ | ❌ |
| macOS (x86_64) | ✅ macOS 13.0+[^1] | ❌ |
| Ubuntu | ✅ 20.04+ | ✅ 20.04+ |
| RHEL | ✅ Fedora 39[^2], UBI 9 | ✅ UBI 9 |
| Debian | ✅ 11, 12[^2] | ✅ 11, 12[^2] |
| RHEL | ✅ Fedora 39, UBI 9 | ✅ Fedora 39, UBI 9[^3] |
| Amazon Linux 2 | ✅ Supported | ✅ Supported[^3] |
| Debian 12 | ✅ Supported[^2] | ✅ Supported[^2][^3] |

[^1]: Since LLVM project doesn't provide pre-built binaries of `lld` for macOS on x86_64, it will be automatically built
from sources by the generator, which will increase its run by at least 15 minutes on recent hardware. You will also
need CMake and Ninja preinstalled (e.g. via `brew install cmake ninja`).
[^2]: These distributions are only supported by Swift 5.10.1 and later as both host and target platforms.
[^2]: Swift does not officially support Debian 11 or Debian 12 with Swift versions before 5.10.1. However, the Ubuntu 20.04/22.04 toolchains can be used with Debian 11 and 12 (respectively) since they are binary compatible.
[^3]: These versions are technically supported but require custom commands and a Docker container to build the Swift SDK, as the generator will not download dependencies for these distributions automatically. See [issue #138](https://github.com/swiftlang/swift-sdk-generator/issues/138).

## How to use it
Expand All @@ -78,7 +85,7 @@ swift run swift-sdk-generator make-linux-sdk --help
After installing a Swift SDK, verify that it's available to SwiftPM:

```
swift experimental-sdk list
swift sdk list
```

The output of the last command should contain `ubuntu22.04`. Note the full Swift SDK ID in the output, we'll refer to it
Expand All @@ -87,12 +94,18 @@ subsequently as `<generated_sdk_id>`.
Create a new project to verify that the SDK works:

```
mkdir cross-compilation test
mkdir cross-compilation-test
cd cross-compilation-test
swift package init --type executable
```

Build this project with the SDK:
Build this project with the Swift SDK:

```
swift build --swift-sdk <generated_sdk_id>
```

When cross-compiling with Swift 5.9/5.10, add `experimental-` prefix to the option name:

```
swift build --experimental-swift-sdk <generated_sdk_id>
Expand All @@ -112,9 +125,9 @@ dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0,
```

You can then copy this binary to a Docker image that has Swift runtime libraries installed. For example,
for Ubuntu Jammy and Swift 5.9 this would be `swift:5.9-jammy-slim`. If you'd like to copy the binary to
for Ubuntu Jammy and Swift 6.0 this would be `swift:6.0-jammy-slim`. If you'd like to copy the binary to
an arbitrary Ubuntu Jammy system, make sure you pass `--static-swift-stdlib` flag to `swift build`, in addition
to the `--experimental-swift-sdk` option.
to the `--swift-sdk` option.

## Building an SDK from a container image

Expand Down Expand Up @@ -169,9 +182,22 @@ swift run swift-sdk-generator make-linux-sdk --with-docker --from-container-imag
## Swift SDK distribution

The `.artifactbundle` directory produced in the previous section can be packaged as a `.tar.gz` archive and redistributed
in this form. Users of such Swift SDK bundle archive can easily install it with `swift experimental-sdk install`
in this form. Users of such Swift SDK bundle archive can easily install it with `swift sdk install`
command, which supports both local file system paths and public `http://` and `https://` URLs as an argument.
Copy link
Contributor

@xtremekforever xtremekforever Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there should also be information about generating a checksum for the package. If you try installing a Swift SDK from a remote URL, swiftpm wants you to pass a checksum. For example:

$ swift sdk install https://download.swift.org/swift-6.0.3-release/static-sdk/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz
Error: Bundles installed from remote URLs (`https://download.swift.org/swift-6.0.3-release/static-sdk/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz`) require their checksum passed via `--checksum` option.
The distributor of the bundle must compute it with the `swift package compute-checksum` command and provide it with their Swift SDK installation instructions.


To make an `.artifactbundle.tar.gz` archive installable directly from `http://` and `https://` URLs, a checksum must be
generated. This can be done using the `swift package compute-checksum` command, like this:

```console
swift package compute-checksum ./Bundles/6.1-RELEASE_ubuntu_jammy_x86_64.artifactbundle.tar.gz
<checksum>
```

This checksum should be provided along with the artifact bundles to be included with the sdk install invocation:

```console
swift sdk install https://my-public-site/sdks/6.1-RELEASE_ubuntu_jammy_x86_64.artifactbundle.tar.gz --checksum <checksum>
```

## Contributing

Expand Down
10 changes: 5 additions & 5 deletions Sources/AsyncProcess/ChunkSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import NIO

#if os(Linux) || os(Android) || os(Windows)
@preconcurrency import Foundation
@preconcurrency import Foundation
#else
import Foundation
import Foundation
#endif

public struct IllegalStreamConsumptionError: Error {
Expand Down Expand Up @@ -53,9 +53,9 @@ public struct ChunkSequence: AsyncSequence & Sendable {
} else {
throw IllegalStreamConsumptionError(
description: """
Either `.discard`ed, `.inherit`ed or redirected this stream to a `.fileHandle`,
cannot also consume it. To consume, please `.stream` it.
"""
Either `.discard`ed, `.inherit`ed or redirected this stream to a `.fileHandle`,
cannot also consume it. To consume, please `.stream` it.
"""
)
}
}
Expand Down
Loading