Skip to content
Merged
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
Empty file added .agents/interfaces/.gitkeep
Empty file.
136 changes: 136 additions & 0 deletions .agents/interfaces/macos/AssociatedObjects.swiftinterface
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// swift-interface-format-version: 1.0
// swift-compiler-version: Apple Swift version 6.4 (swiftlang-6.4.0.25.4 clang-2100.3.25.1)
// swift-module-flags: -target arm64-apple-macosx12.0 -enable-objc-interop -language-mode 6 -Onone -module-name AssociatedObjects -package-name swift_associated_objects
// swift-module-flags-ignorable: -formal-cxx-interoperability-mode=off -interface-compiler-version 6.4
import Foundation
import Swift
import _Concurrency
import _StringProcessing
import _SwiftConcurrencyShims
public protocol AssociatingObject : AnyObject {
@discardableResult
@inlinable func setAssociatedObject<Object>(_ object: Object?, forKey key: Swift::StaticString, policy: ObjectiveC::objc_AssociationPolicy) -> Swift::Bool
@discardableResult
@inlinable func setAssociatedObject<Object>(_ object: Object?, forKey key: Swift::StaticString, threadSafety: AssociatedObjects::_AssociationPolicyThreadSafety) -> Swift::Bool
@inlinable func getAssociatedObject<Object>(of type: Object.Type, forKey key: Swift::StaticString) -> Object?
}
extension AssociatedObjects::AssociatingObject {
@discardableResult
@inlinable public func setAssociatedObject<Object>(_ object: Object?, forKey key: Swift::StaticString, policy: ObjectiveC::objc_AssociationPolicy = .retain(.nonatomic)) -> Swift::Bool {
return _setAssociatedObject(
object,
to: self,
forKey: key,
policy: policy
)
}
@discardableResult
@inlinable public func setAssociatedObject<Object>(_ object: Object?, forKey key: Swift::StaticString, threadSafety: AssociatedObjects::_AssociationPolicyThreadSafety) -> Swift::Bool {
return _setAssociatedObject(
object,
to: self,
forKey: key,
threadSafety: threadSafety
)
}
@inlinable public func getAssociatedObject<Object>(of type: Object.Type = Object.self, forKey key: Swift::StaticString) -> Object? {
return _getAssociatedObject(
forKey: key,
from: self
)
}
}
@discardableResult
@inlinable public func _setAssociatedObject<Object>(_ object: Object?, to associatingObject: Swift::AnyObject, forKey key: Swift::StaticString, threadSafety: AssociatedObjects::_AssociationPolicyThreadSafety = .nonatomic) -> Swift::Bool {
_setAssociatedObject(
object,
to: associatingObject,
forKey: key,
policy: .init(
Object.self is AnyClass ? .retain : .copy,
threadSafety
)
)
}
@discardableResult
@inlinable public func _setAssociatedObject<Object>(_ object: Object?, to associatingObject: Swift::AnyObject, forKey key: Swift::StaticString, policy: ObjectiveC::objc_AssociationPolicy) -> Swift::Bool {
guard key.hasPointerRepresentation
else { return false }

objc_setAssociatedObject(
associatingObject,
UnsafeRawPointer(key.utf8Start),
object,
policy
)

return true
}
@inlinable public func _getAssociatedObject<Object>(of type: Object.Type = Object.self, forKey key: Swift::StaticString, from associatingObject: Swift::AnyObject) -> Object? {
guard key.hasPointerRepresentation
else { return nil }

return objc_getAssociatedObject(
associatingObject,
UnsafeRawPointer(key.utf8Start)
)
.flatMap { $0 as? Object }
}
extension ObjectiveC::NSObject : AssociatedObjects::AssociatingObject {
}
public enum _AssociationPolicyKind : Swift::String {
case copy
case assign
case retain
@inlinable public init?(rawValue: Swift::String)
public typealias RawValue = Swift::String
public var rawValue: Swift::String {
@inlinable get
}
}
public enum _AssociationPolicyThreadSafety : Swift::String {
case atomic
case nonatomic
@inlinable public init?(rawValue: Swift::String)
public typealias RawValue = Swift::String
public var rawValue: Swift::String {
@inlinable get
}
}
extension ObjectiveC::objc_AssociationPolicy {
@inlinable public init(_ kind: AssociatedObjects::_AssociationPolicyKind, _ threadSafety: AssociatedObjects::_AssociationPolicyThreadSafety) {
switch kind {
case .copy:
self = .copy(threadSafety)
case .assign:
self = .assign
case .retain:
self = .retain(threadSafety)
}
}
@inlinable public static var assign: ObjectiveC::objc_AssociationPolicy {
get { .OBJC_ASSOCIATION_ASSIGN }
}
@inlinable public static func retain(_ threadSafety: AssociatedObjects::_AssociationPolicyThreadSafety) -> ObjectiveC::objc_AssociationPolicy {
switch threadSafety {
case .atomic:
.OBJC_ASSOCIATION_RETAIN
case .nonatomic:
.OBJC_ASSOCIATION_RETAIN_NONATOMIC
}
}
@inlinable public static func copy(_ threadSafety: AssociatedObjects::_AssociationPolicyThreadSafety) -> ObjectiveC::objc_AssociationPolicy {
switch threadSafety {
case .atomic:
.OBJC_ASSOCIATION_COPY
case .nonatomic:
.OBJC_ASSOCIATION_COPY_NONATOMIC
}
}
}
extension AssociatedObjects::_AssociationPolicyKind : Swift::Equatable {}
extension AssociatedObjects::_AssociationPolicyKind : Swift::Hashable {}
extension AssociatedObjects::_AssociationPolicyKind : Swift::RawRepresentable {}
extension AssociatedObjects::_AssociationPolicyThreadSafety : Swift::Equatable {}
extension AssociatedObjects::_AssociationPolicyThreadSafety : Swift::Hashable {}
extension AssociatedObjects::_AssociationPolicyThreadSafety : Swift::RawRepresentable {}
18 changes: 18 additions & 0 deletions .agents/interfaces/macos/AssociatedObjectsMacros.swiftinterface
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// swift-interface-format-version: 1.0
// swift-compiler-version: Apple Swift version 6.4 (swiftlang-6.4.0.25.4 clang-2100.3.25.1)
// swift-module-flags: -target arm64-apple-macosx12.0 -enable-objc-interop -language-mode 6 -Onone -module-name AssociatedObjectsMacros -package-name swift_associated_objects
// swift-module-flags-ignorable: -formal-cxx-interoperability-mode=off -interface-compiler-version 6.4
@_exported import AssociatedObjects
import Foundation
import Swift
import _Concurrency
import _StringProcessing
import _SwiftConcurrencyShims
@attached(accessor) public macro AssociatedObject(policy: ObjectiveC::objc_AssociationPolicy, readonly: Swift::Bool) = #externalMacro(
module: "AssociatedObjectsMacrosPlugin",
type: "AssociatedObjectMacro"
)
@attached(accessor) public macro AssociatedObject(threadSafety: AssociatedObjects::_AssociationPolicyThreadSafety = .nonatomic, readonly: Swift::Bool = true) = #externalMacro(
module: "AssociatedObjectsMacrosPlugin",
type: "AssociatedObjectMacro"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// swift-interface-format-version: 1.0
// swift-compiler-version: Apple Swift version 6.4 (swiftlang-6.4.0.25.4 clang-2100.3.25.1)
// swift-module-flags: -target arm64-apple-macosx12.0 -enable-objc-interop -language-mode 6 -Onone -module-name AssociatedObjectsMacrosPlugin -package-name swift_associated_objects
// swift-module-flags-ignorable: -formal-cxx-interoperability-mode=off -interface-compiler-version 6.4
import Foundation
import MacroToolkit
import Swift
import SwiftCompilerPlugin
import SwiftDiagnostics
import SwiftSyntax
import SwiftSyntaxMacros
import _Concurrency
import _StringProcessing
import _SwiftConcurrencyShims
public struct AssociatedObjectMacro : SwiftSyntaxMacros::AccessorMacro {
public static func expansion(of node: SwiftSyntax::AttributeSyntax, providingAccessorsOf declaration: some DeclSyntaxProtocol, in context: some MacroExpansionContext) throws -> [SwiftSyntax::AccessorDeclSyntax]
}
extension SwiftSyntaxMacros::MacroExpansionContext {
public func diagnose<T>(_ diagnostic: SwiftDiagnostics::Diagnostic, return value: T) -> T
}
public func == <A, B>(lhs: Swift::KeyPath<A, B>, rhs: B) -> (A) -> Swift::Bool where B : Swift::Equatable
public func != <A, B>(lhs: Swift::KeyPath<A, B>, rhs: B) -> (A) -> Swift::Bool where B : Swift::Equatable
public func || <A>(lhs: @escaping (A) -> Swift::Bool, rhs: @escaping (A) -> Swift::Bool) -> (A) -> Swift::Bool
public func && <A>(lhs: @escaping (A) -> Swift::Bool, rhs: @escaping (A) -> Swift::Bool) -> (A) -> Swift::Bool
prefix public func ! <A>(f: @escaping (A) -> Swift::Bool) -> (A) -> Swift::Bool
120 changes: 120 additions & 0 deletions .github/workflows/generate-swiftinterface.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Generate Swift interface
run-name: Generate ${{ inputs.platform }} interfaces

on:
workflow_dispatch:
inputs:
platform:
description: Normalized platform name (macos, ios, linux, windows, wasi, ...)
required: true
type: string
target_branch:
description: Branch that receives the generated-interface PR (defaults to the dispatched branch)
required: false
default: ""
type: string
workflow_call:
inputs:
platform:
required: true
type: string
target_branch:
required: true
type: string

permissions:
contents: write
pull-requests: write

jobs:
generate:
name: Generate ${{ inputs.platform }}
runs-on: ${{ (inputs.platform == 'linux' || inputs.platform == 'wasi') && 'ubuntu-latest' || inputs.platform == 'windows' && 'windows-latest' || 'macos-latest' }}
env:
GH_TOKEN: ${{ github.token }}
INPUT_TARGET_BRANCH: ${{ inputs.target_branch }}
PLATFORM: ${{ inputs.platform }}
steps:
- name: Validate request
shell: bash
run: |
if [[ ! "$PLATFORM" =~ ^[a-z0-9][a-z0-9._-]*$ ]]; then
echo "Platform must be a normalized lowercase directory name: $PLATFORM" >&2
exit 1
fi

- uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ inputs.target_branch != '' && inputs.target_branch || github.ref_name }}

- name: Set up Swift outside Xcode
if: runner.os != 'macOS'
uses: SwiftyLab/setup-swift@v1
with:
swift-version: "6"
sdks: ${{ inputs.platform == 'wasi' && 'wasm' || '' }}

- name: Prepare generation branch
shell: bash
run: |
target_branch="${INPUT_TARGET_BRANCH:-$GITHUB_REF_NAME}"
interface_branch="automation/swiftinterfaces/$GITHUB_RUN_ID/$PLATFORM"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git switch -C "$interface_branch"
echo "TARGET_BRANCH=$target_branch" >> "$GITHUB_ENV"
echo "INTERFACE_BRANCH=$interface_branch" >> "$GITHUB_ENV"

- name: Select WASI SDK
if: inputs.platform == 'wasi'
shell: bash
run: |
swift_sdk="$(swift sdk list | sed -nE '/(_wasm|wasi)/ { s/^[[:space:]]*([^[:space:]]+).*/\1/p; q; }')"
if [[ -z "$swift_sdk" ]]; then
echo "No installed WASI Swift SDK was found" >&2
swift sdk list >&2 || true
exit 1
fi
echo "SWIFT_SDK=$swift_sdk" >> "$GITHUB_ENV"

- name: Generate interface
shell: bash
run: |
interface_dir=".agents/interfaces/$PLATFORM"
if [[ -d "$interface_dir" ]]; then
find "$interface_dir" -maxdepth 1 -type f -name '*.swiftinterface' -delete
fi
if [[ -n "${SWIFT_SDK:-}" ]]; then
make swiftinterface platform="$PLATFORM" swift_sdk="$SWIFT_SDK"
else
make swiftinterface platform="$PLATFORM"
fi

- name: Commit and push interface
id: commit
shell: bash
run: |
git add --all -- ".agents/interfaces/$PLATFORM"
if git diff --cached --quiet; then
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "No $PLATFORM interface changes" >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
git commit -m "Update $PLATFORM Swift interfaces"
git push --force-with-lease --set-upstream origin "$INTERFACE_BRANCH"
echo "changed=true" >> "$GITHUB_OUTPUT"

- name: Open platform PR
if: steps.commit.outputs.changed == 'true'
shell: bash
run: |
pr_url="$(gh pr list --state open --base "$TARGET_BRANCH" --head "$INTERFACE_BRANCH" --json url --jq '.[0].url')"
if [[ -z "$pr_url" ]]; then
pr_url="$(gh pr create \
--base "$TARGET_BRANCH" \
--head "$INTERFACE_BRANCH" \
--title "chore: update $PLATFORM Swift interfaces" \
--body "Generated from \`$TARGET_BRANCH\` by workflow run $GITHUB_RUN_ID. Merge this PR into the aggregation branch after reviewing the platform-specific API snapshot.")"
fi
echo "$pr_url" >> "$GITHUB_STEP_SUMMARY"
85 changes: 85 additions & 0 deletions .github/workflows/update-swiftinterfaces.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Update Swift interfaces
run-name: Update Swift interfaces from ${{ github.ref_name }}

on:
workflow_dispatch:
inputs:
platforms:
description: JSON array of independently generated platforms
required: true
default: '["macos","ios","tvos","watchos","maccatalyst"]'
type: string

permissions:
contents: write
pull-requests: write

jobs:
prepare:
name: Create aggregation branch
runs-on: ubuntu-latest
outputs:
update_branch: ${{ steps.branch.outputs.update_branch }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.ref_name }}

- name: Push aggregation branch
id: branch
shell: bash
run: |
update_branch="automation/swiftinterfaces/$GITHUB_RUN_ID"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git switch -C "$update_branch"
git commit --allow-empty -m "Prepare Swift interface update"
git push --force-with-lease --set-upstream origin "$update_branch"
echo "update_branch=$update_branch" >> "$GITHUB_OUTPUT"

generate:
name: Generate ${{ matrix.platform }}
needs: prepare
strategy:
fail-fast: false
matrix:
platform: ${{ fromJSON(inputs.platforms) }}
permissions:
contents: write
pull-requests: write
uses: ./.github/workflows/generate-swiftinterface.yml
with:
platform: ${{ matrix.platform }}
target_branch: ${{ needs.prepare.outputs.update_branch }}

finalize:
name: Open draft aggregation PR
if: always() && needs.prepare.result == 'success'
needs:
- prepare
- generate
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
TARGET_BRANCH: ${{ github.ref_name }}
UPDATE_BRANCH: ${{ needs.prepare.outputs.update_branch }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.ref_name }}

- name: Open draft PR
shell: bash
run: |
pr_url="$(gh pr list --state open --base "$TARGET_BRANCH" --head "$UPDATE_BRANCH" --json url --jq '.[0].url')"
if [[ -z "$pr_url" ]]; then
pr_url="$(gh pr create \
--draft \
--base "$TARGET_BRANCH" \
--head "$UPDATE_BRANCH" \
--title "chore: update platform Swift interfaces" \
--body "Aggregation PR for workflow run $GITHUB_RUN_ID. Merge the successful platform PRs into \`$UPDATE_BRANCH\`; failed platform jobs remain visible in the workflow and can be fixed or intentionally ignored. Matrix result: \`${{ needs.generate.result }}\`.")"
fi
echo "$pr_url" >> "$GITHUB_STEP_SUMMARY"
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output ?= .agents/interfaces
platform ?= host
swift_sdk ?=

.PHONY: swiftinterface
swiftinterface:
@./scripts/generate-swiftinterfaces.sh --package-path . --output "$(output)" --configuration debug --build-arg --build-system --build-arg native --platform "$(platform)" $(if $(swift_sdk),--swift-sdk "$(swift_sdk)")
Loading
Loading