Skip to content

Commit

Permalink
Add CasePathsCore module (#212)
Browse files Browse the repository at this point in the history
* Add `CasePathsCore` module

It's possible for a library to integrate with case paths in a way that
doesn't require their use and the penalty involved in building their
macros, so let's introduce a "core" module that contains the core
functionality of the library, less macros and other deprecations.

* wip

* wip

* wip

* Update DocC

* wip
  • Loading branch information
stephencelis authored Jan 16, 2025
1 parent dc49b7a commit e7039aa
Show file tree
Hide file tree
Showing 35 changed files with 213 additions and 200 deletions.
21 changes: 7 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
matrix:
xcode:
- '15.4'
- '16.0'
- '16.2'
steps:
- uses: actions/checkout@v4
- name: Select Xcode ${{ matrix.xcode }}
Expand All @@ -38,7 +38,7 @@ jobs:
matrix:
xcode:
- '15.4'
- '16.0'
- '16.2'
steps:
- uses: actions/checkout@v4
- name: Select Xcode ${{ matrix.xcode }}
Expand All @@ -64,29 +64,22 @@ jobs:
run: swift test -c release --parallel

wasm:
name: SwiftWasm
name: Wasm
runs-on: ubuntu-latest
env:
OMIT_MACRO_TESTS: 1
strategy:
matrix:
include:
- toolchain: swift-DEVELOPMENT-SNAPSHOT-2024-09-18-a
swift-sdk: swift-wasm-DEVELOPMENT-SNAPSHOT-2024-09-20-a
checksum: ac7318b8beee4870162292715654499127833b847af6b3d94c32e574579ea189
steps:
- uses: actions/checkout@v4
- uses: bytecodealliance/actions/wasmtime/setup@v1
- name: Install Swift and Swift SDK for WebAssembly
run: |
PREFIX=/opt/swift
SWIFT_TOOLCHAIN_TAG="${{ matrix.toolchain }}"
SWIFT_SDK_TAG="${{ matrix.swift-sdk }}"
set -ex
curl -f -o /tmp/swift.tar.gz "https://download.swift.org/development/ubuntu2204/$SWIFT_TOOLCHAIN_TAG/$SWIFT_TOOLCHAIN_TAG-ubuntu22.04.tar.gz"
curl -f -o /tmp/swift.tar.gz "https://download.swift.org/swift-6.0.2-release/ubuntu2204/swift-6.0.2-RELEASE/swift-6.0.2-RELEASE-ubuntu22.04.tar.gz"
sudo mkdir -p $PREFIX; sudo tar -xzf /tmp/swift.tar.gz -C $PREFIX --strip-component 1
$PREFIX/usr/bin/swift sdk install "https://github.com/swiftwasm/swift/releases/download/$SWIFT_SDK_TAG/$SWIFT_SDK_TAG-wasm32-unknown-wasi.artifactbundle.zip" --checksum ${{ matrix.checksum }}
$PREFIX/usr/bin/swift sdk install https://github.com/swiftwasm/swift/releases/download/swift-wasm-6.0.2-RELEASE/swift-wasm-6.0.2-RELEASE-wasm32-unknown-wasi.artifactbundle.zip --checksum 6ffedb055cb9956395d9f435d03d53ebe9f6a8d45106b979d1b7f53358e1dcb4
echo "$PREFIX/usr/bin" >> $GITHUB_PATH
- name: Build tests
run: swift build --swift-sdk wasm32-unknown-wasi --build-tests -Xlinker -z -Xlinker stack-size=$((1024 * 1024))
- name: Run tests
Expand Down Expand Up @@ -130,4 +123,4 @@ jobs:
env:
OMIT_MACRO_TESTS: 1
steps:
- uses: johankool/swift-android-test-action@v1
- uses: johankool/swift-android-test-action@v1
14 changes: 6 additions & 8 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ concurrency:
jobs:
swift_format:
name: swift-format
runs-on: macos-14
runs-on: macos-15
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Xcode Select
run: sudo xcode-select -s /Applications/Xcode_16.0.app
- name: Tap
run: brew install swift-format
- name: Select Xcode 16.2
run: sudo xcode-select -s /Applications/Xcode_16.2.app
- name: Format
run: make format
- uses: stefanzweifel/git-auto-commit-action@v4
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Run swift-format
branch: 'main'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .spi.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 1
builder:
configs:
- documentation_targets: [CasePaths]
- documentation_targets: [CasePathsCore, CasePaths]
2 changes: 1 addition & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "e4bb2d04e477a6c143e71b4967a73419b0f830aeecd56f64be2b7060b746a574",
"originHash" : "75a28c180eaa852896a1e043cbbf340d2f28af3ec620072b1a1b7d9a6041d14e",
"pins" : [
{
"identity" : "swift-docc-plugin",
Expand Down
22 changes: 16 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,42 @@ let package = Package(
.library(
name: "CasePaths",
targets: ["CasePaths"]
)
),
.library(
name: "CasePathsCore",
targets: ["CasePathsCore"]
),
],
dependencies: [
.package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"601.0.0-prerelease"),
.package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"601.0.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.2.2"),
],
targets: [
.target(
name: "CasePaths",
dependencies: [
"CasePathsCore",
"CasePathsMacros",
]
),
.target(
name: "CasePathsCore",
dependencies: [
.product(name: "IssueReporting", package: "xctest-dynamic-overlay"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
),
.testTarget(
name: "CasePathsTests",
dependencies: ["CasePaths"]
),
.macro(
name: "CasePathsMacros",
dependencies: [
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
]
),
.testTarget(
name: "CasePathsTests",
dependencies: ["CasePaths"]
),
]
)

Expand Down
22 changes: 16 additions & 6 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,42 @@ let package = Package(
.library(
name: "CasePaths",
targets: ["CasePaths"]
)
),
.library(
name: "CasePathsCore",
targets: ["CasePathsCore"]
),
],
dependencies: [
.package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"601.0.0-prerelease"),
.package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"601.0.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.2.2"),
],
targets: [
.target(
name: "CasePaths",
dependencies: [
"CasePathsCore",
"CasePathsMacros",
]
),
.target(
name: "CasePathsCore",
dependencies: [
.product(name: "IssueReporting", package: "xctest-dynamic-overlay"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
),
.testTarget(
name: "CasePathsTests",
dependencies: ["CasePaths"]
),
.macro(
name: "CasePathsMacros",
dependencies: [
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
]
),
.testTarget(
name: "CasePathsTests",
dependencies: ["CasePaths"]
),
],
swiftLanguageModes: [.v6]
)
Expand Down
38 changes: 0 additions & 38 deletions Sources/CasePaths/Documentation.docc/AnyCasePathDeprecations.md

This file was deleted.

7 changes: 3 additions & 4 deletions Sources/CasePaths/Documentation.docc/CasePathableMacro.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# ``CasePaths/CasePathable()``

## Topics
## Further reading

### CasePathable conformance

- ``CasePathable``
See the [`CasePathsCore`](../casepathscore) module for the `CasePathable` protocol and other core
library types.
22 changes: 4 additions & 18 deletions Sources/CasePaths/Documentation.docc/CasePaths.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,17 @@ Case paths bring the power and ergonomics of key paths to enums.

## Overview

<!-- TODO: Copy over README -->
This module exports the core functionality of the Case Paths library, as well as the `@CasePathable`
macro.

## Topics

### Case paths
To read the core documentation, see the [`CasePathsCore`](../casepathscore) module.

- ``CaseKeyPath``
## Topics

### Creating case paths

- ``CasePathable()``

### Swift support

- ``Swift/Optional``
- ``Swift/Result``

### XCTest support

- ``XCTModify(_:case:_:_:file:line:)-94qma``

### Guides

- <doc:Swift59>

### Deprecated interfaces

- <doc:Deprecations>
14 changes: 14 additions & 0 deletions Sources/CasePaths/Documentation.docc/Deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,17 @@ Avoid using deprecated APIs in your app. See the replacement that you should use
- ``extract(case:from:)-ylkc``
- ``extract(_:)-34fjh``
- ``extract(_:)-3twft``

### Creating paths

- ``CasePathsCore/AnyCasePath``

### Type aliases

- ``CasePath``

### Test helpers

- ``XCTModify(_:case:_:_:file:line:)-14526``
- ``XCTModify(_:case:_:_:file:line:)-1pef3``
- ``XCTModify(_:_:_:file:line:)``
2 changes: 1 addition & 1 deletion Sources/CasePaths/Documentation.docc/XCTModify.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ``CasePaths/XCTModify(_:case:_:_:file:line:)-94qma``
# ``CasePaths/XCTModify(_:case:_:_:file:line:)-14526``

## Topics

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Avoid using deprecated APIs in your app. See the replacement that you should use

### XCTModify

- ``XCTModify(_:case:_:_:file:line:)-1lm9s``
- ``XCTModify(_:case:_:_:file:line:)-1pef3``

### XCTUnwrap

Expand Down
6 changes: 2 additions & 4 deletions Sources/CasePaths/EnumReflection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ extension AnyCasePath {
/// given an enum embed function.
///
/// > Important: This operation is provided for backwards compatibility. Avoid introducing it to
/// > your code and instead favor using types that conform to ``CasePathable`` and
/// > ``CaseKeyPath``.
/// > your code and instead favor using types that employ the ``CasePathable()`` macro.
///
/// - Parameter embed: An embed function.
@available(iOS, deprecated: 9999, message: "Use a 'CasePathable' case key path, instead")
Expand All @@ -34,8 +33,7 @@ extension AnyCasePath {
/// Returns a void case path for a case with no associated value.
///
/// > Important: This operation is provided for backwards compatibility. Avoid introducing it to
/// > your code and instead favor using types that conform to ``CasePathable`` and
/// > ``CaseKeyPath``.
/// > your code and instead favor using types that employ the ``CasePathable()`` macro.
@available(iOS, deprecated: 9999, message: "Use a 'CasePathable' case key path, instead")
@available(macOS, deprecated: 9999, message: "Use a 'CasePathable' case key path, instead")
@available(tvOS, deprecated: 9999, message: "Use a 'CasePathable' case key path, instead")
Expand Down
Loading

0 comments on commit e7039aa

Please sign in to comment.