Skip to content

Commit

Permalink
Update README and Package.swift (#12)
Browse files Browse the repository at this point in the history
* Update README.md to add SPI badge

* Update Package.swift

* Update WASI check to os(WASI)

* Fix watchOS and tvOS CI build issue
  • Loading branch information
Kyle-Ye authored Dec 27, 2023
1 parent e0963e6 commit 1b8a26b
Show file tree
Hide file tree
Showing 112 changed files with 428 additions and 321 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ swift-version:
$(SWIFT_EXE) -version

test-compatibility:
$(SWIFT_EXE) test -Xswiftc -DOPENCOMBINE_COMPATIBILITY_TEST
OPENCOMBINE_COMPATIBILITY_TEST=1 $(SWIFT_EXE) test

gyb:
$(shell ./utils/recursively_gyb.sh)
Expand Down
100 changes: 63 additions & 37 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// swift-tools-version:5.7

import Foundation
import PackageDescription

// This list should be updated whenever SwiftPM adds support for a new platform.
Expand All @@ -17,6 +18,50 @@ let supportedPlatforms: [Platform] = [
.wasi,
]

let openCombineTarget: Target = .target(
name: "OpenCombine",
dependencies: [
.target(
name: "COpenCombineHelpers",
condition: .when(platforms: supportedPlatforms.except([.wasi]))
)
],
exclude: [
"Concurrency/Publisher+Concurrency.swift.gyb",
"Publishers/Publishers.Encode.swift.gyb",
"Publishers/Publishers.MapKeyPath.swift.gyb",
"Publishers/Publishers.Catch.swift.gyb"
]
)
let openCombineFoundationTarget: Target = .target(
name: "OpenCombineFoundation",
dependencies: [
"OpenCombine",
.target(
name: "COpenCombineHelpers",
condition: .when(platforms: supportedPlatforms.except([.wasi]))
)
]
)
let openCombineDispatchTarget: Target = .target(
name: "OpenCombineDispatch",
dependencies: ["OpenCombine"]
)

let openCombineTestsTarget: Target = .testTarget(
name: "OpenCombineTests",
dependencies: [
"OpenCombine",
.target(name: "OpenCombineDispatch",
condition: .when(platforms: supportedPlatforms.except([.wasi]))),
.target(name: "OpenCombineFoundation",
condition: .when(platforms: supportedPlatforms.except([.wasi]))),
],
swiftSettings: [
.unsafeFlags(["-enable-testing"]),
]
)

let package = Package(
name: "OpenCombine",
products: [
Expand All @@ -27,29 +72,6 @@ let package = Package(
],
targets: [
.target(name: "COpenCombineHelpers"),
.target(
name: "OpenCombine",
dependencies: [
.target(name: "COpenCombineHelpers",
condition: .when(platforms: supportedPlatforms.except([.wasi])))
],
exclude: [
"Concurrency/Publisher+Concurrency.swift.gyb",
"Publishers/Publishers.Encode.swift.gyb",
"Publishers/Publishers.MapKeyPath.swift.gyb",
"Publishers/Publishers.Catch.swift.gyb"
],
swiftSettings: [.define("WASI", .when(platforms: [.wasi]))]
),
.target(name: "OpenCombineDispatch", dependencies: ["OpenCombine"]),
.target(
name: "OpenCombineFoundation",
dependencies: [
"OpenCombine",
.target(name: "COpenCombineHelpers",
condition: .when(platforms: supportedPlatforms.except([.wasi])))
]
),
.target(
name: "OpenCombineShim",
dependencies: [
Expand All @@ -60,20 +82,10 @@ let package = Package(
condition: .when(platforms: supportedPlatforms.except([.wasi])))
]
),
.testTarget(
name: "OpenCombineTests",
dependencies: [
"OpenCombine",
.target(name: "OpenCombineDispatch",
condition: .when(platforms: supportedPlatforms.except([.wasi]))),
.target(name: "OpenCombineFoundation",
condition: .when(platforms: supportedPlatforms.except([.wasi]))),
],
swiftSettings: [
.unsafeFlags(["-enable-testing"]),
.define("WASI", .when(platforms: [.wasi])),
]
)
openCombineTarget,
openCombineFoundationTarget,
openCombineDispatchTarget,
openCombineTestsTarget,
],
cxxLanguageStandard: .cxx17
)
Expand All @@ -85,3 +97,17 @@ extension Array where Element == Platform {
return filter { !exceptions.contains($0) }
}
}

func envEnable(_ key: String) -> Bool {
guard let value = ProcessInfo.processInfo.environment[key] else {
return false
}
return value == "1"
}

let enableCompatibilityTest = envEnable("OPENCOMBINE_COMPATIBILITY_TEST")
if enableCompatibilityTest {
var settings = openCombineTestsTarget.swiftSettings ?? []
settings.append(.define("OPENCOMBINE_COMPATIBILITY_TEST"))
openCombineTestsTarget.swiftSettings = settings
}
114 changes: 114 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// swift-tools-version:5.9

import Foundation
import PackageDescription

// This list should be updated whenever SwiftPM adds support for a new platform.
// See: https://bugs.swift.org/browse/SR-13814
let supportedPlatforms: [Platform] = [
.macOS,
.macCatalyst,
.iOS,
.watchOS,
.tvOS,
.driverKit,
.linux,
.android,
.windows,
.wasi,
.visionOS,
]

let openCombineTarget: Target = .target(
name: "OpenCombine",
dependencies: [
.target(
name: "COpenCombineHelpers",
condition: .when(platforms: supportedPlatforms.except([.wasi]))
)
],
exclude: [
"Concurrency/Publisher+Concurrency.swift.gyb",
"Publishers/Publishers.Encode.swift.gyb",
"Publishers/Publishers.MapKeyPath.swift.gyb",
"Publishers/Publishers.Catch.swift.gyb"
]
)
let openCombineFoundationTarget: Target = .target(
name: "OpenCombineFoundation",
dependencies: [
"OpenCombine",
.target(
name: "COpenCombineHelpers",
condition: .when(platforms: supportedPlatforms.except([.wasi]))
)
]
)
let openCombineDispatchTarget: Target = .target(
name: "OpenCombineDispatch",
dependencies: ["OpenCombine"]
)

let openCombineTestsTarget: Target = .testTarget(
name: "OpenCombineTests",
dependencies: [
"OpenCombine",
.target(name: "OpenCombineDispatch",
condition: .when(platforms: supportedPlatforms.except([.wasi]))),
.target(name: "OpenCombineFoundation",
condition: .when(platforms: supportedPlatforms.except([.wasi]))),
],
swiftSettings: [
.unsafeFlags(["-enable-testing"]),
]
)

let package = Package(
name: "OpenCombine",
products: [
.library(name: "OpenCombine", targets: ["OpenCombine"]),
.library(name: "OpenCombineDispatch", targets: ["OpenCombineDispatch"]),
.library(name: "OpenCombineFoundation", targets: ["OpenCombineFoundation"]),
.library(name: "OpenCombineShim", targets: ["OpenCombineShim"]),
],
targets: [
.target(name: "COpenCombineHelpers"),
.target(
name: "OpenCombineShim",
dependencies: [
"OpenCombine",
.target(name: "OpenCombineDispatch",
condition: .when(platforms: supportedPlatforms.except([.wasi]))),
.target(name: "OpenCombineFoundation",
condition: .when(platforms: supportedPlatforms.except([.wasi])))
]
),
openCombineTarget,
openCombineFoundationTarget,
openCombineDispatchTarget,
openCombineTestsTarget,
],
cxxLanguageStandard: .cxx17
)

// MARK: Helpers

extension Array where Element == Platform {
func except(_ exceptions: [Platform]) -> [Platform] {
return filter { !exceptions.contains($0) }
}
}

func envEnable(_ key: String) -> Bool {
guard let value = ProcessInfo.processInfo.environment[key] else {
return false
}
return value == "1"
}

let enableCompatibilityTest = envEnable("OPENCOMBINE_COMPATIBILITY_TEST")
if enableCompatibilityTest {
var settings = openCombineTestsTarget.swiftSettings ?? []
settings.append(.define("OPENCOMBINE_COMPATIBILITY_TEST"))
openCombineTestsTarget.swiftSettings = settings
}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# OpenCombine
[![codecov](https://codecov.io/gh/OpenSwiftUIProject/OpenCombine/graph/badge.svg?token=BJSI3J7RZQ)](https://codecov.io/gh/OpenSwiftUIProject/OpenCombine)
![Language](https://img.shields.io/badge/Swift-5.9-orange.svg)

[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FOpenSwiftUIProject%2FOpenCombine%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/OpenSwiftUIProject/OpenCombine)

[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FOpenSwiftUIProject%2FOpenCombine%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/OpenSwiftUIProject/OpenCombine)

Open-source implementation of Apple's [Combine](https://developer.apple.com/documentation/combine) framework for processing values over time.

Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenCombine/CombineIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import COpenCombineHelpers
#endif

#if WASI
#if os(WASI)
private var __identifier: UInt64 = 0

internal func __nextCombineIdentifier() -> UInt64 {
defer { __identifier += 1 }
return __identifier
}
#endif // WASI
#endif // os(WASI)

/// A unique identifier for identifying publisher streams.
///
Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenCombine/Helpers/Locking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import COpenCombineHelpers
#endif

#if WASI
#if os(WASI)
internal struct __UnfairLock { // swiftlint:disable:this type_name
internal static func allocate() -> UnfairLock { return .init() }
internal func lock() {}
Expand All @@ -24,7 +24,7 @@ internal struct __UnfairRecursiveLock { // swiftlint:disable:this type_name
internal func unlock() {}
internal func deallocate() {}
}
#endif // WASI
#endif // os(WASI)

internal typealias UnfairLock = __UnfairLock
internal typealias UnfairRecursiveLock = __UnfairRecursiveLock
4 changes: 2 additions & 2 deletions Sources/OpenCombine/Publishers/Publishers.Breakpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Sergej Jaskiewicz on 03.12.2019.
//

#if !WASI
#if !os(WASI)

#if canImport(COpenCombineHelpers)
import COpenCombineHelpers
Expand Down Expand Up @@ -228,4 +228,4 @@ extension Publishers.Breakpoint {
}
}

#endif // !WASI
#endif // !os(WASI)
2 changes: 1 addition & 1 deletion Tests/OpenCombineTests/AnyCancellableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Combine
import OpenCombine
#endif

@available(macOS 10.15, iOS 13.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
final class AnyCancellableTests: XCTestCase {

func testClosureInitialized() {
Expand Down
4 changes: 2 additions & 2 deletions Tests/OpenCombineTests/AnyPublisherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Combine
import OpenCombine
#endif

@available(macOS 10.15, iOS 13.0, *)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
final class AnyPublisherTests: XCTestCase {

private typealias Sut = AnyPublisher<Int, TestingError>
Expand All @@ -32,7 +32,7 @@ final class AnyPublisherTests: XCTestCase {
XCTAssertEqual(publisher.history, [.subscriber])
}

@available(macOS 11.0, iOS 14.0, *)
@available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
func testDoubleErasure() {
let introspection = TrackingIntrospection()
let subscriber = TrackingSubscriber()
Expand Down
Loading

0 comments on commit 1b8a26b

Please sign in to comment.