Skip to content

Commit 6c545ed

Browse files
slashmoktoso
andauthored
Add support for Swift 5.0 & 5.1 (#26)
* Add support for Swift 5.0 & 5.1 * try to compiler() guard the test * try just compiler() * try separate access * Cannot support Swift 5.0 due to compiler bug #if * Update .swiftformat * Cannot support 5.0 due to compiler bug in #if preventing task-local access * Apply suggestions from code review * Update README.md * formatting Co-authored-by: Konrad `ktoso` Malawski <[email protected]> Co-authored-by: Konrad `ktoso` Malawski <[email protected]>
1 parent 8ea1207 commit 6c545ed

File tree

5 files changed

+57
-9
lines changed

5 files changed

+57
-9
lines changed

.swiftformat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# file options
22

3-
--swiftversion 5.2
3+
--swiftversion 5.1
44
--exclude .build
55
--exclude UseCases/.build
66
--exclude Tests/LinuxMain.swift

[email protected]

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// swift-tools-version:5.1
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "swift-distributed-tracing-baggage",
6+
products: [
7+
.library(
8+
name: "InstrumentationBaggage",
9+
targets: [
10+
"InstrumentationBaggage",
11+
]
12+
),
13+
],
14+
targets: [
15+
.target(name: "InstrumentationBaggage"),
16+
17+
// ==== --------------------------------------------------------------------------------------------------------
18+
// MARK: Tests
19+
20+
.testTarget(
21+
name: "InstrumentationBaggageTests",
22+
dependencies: [
23+
.target(name: "InstrumentationBaggage"),
24+
]
25+
),
26+
]
27+
)

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
# 🧳 Distributed Tracing: Baggage
22

3+
[![Swift 5.1](https://img.shields.io/badge/Swift-5.1-ED523F.svg?style=flat)](https://swift.org/download/)
34
[![Swift 5.2](https://img.shields.io/badge/Swift-5.2-ED523F.svg?style=flat)](https://swift.org/download/)
45
[![Swift 5.3](https://img.shields.io/badge/Swift-5.3-ED523F.svg?style=flat)](https://swift.org/download/)
56
[![Swift 5.4](https://img.shields.io/badge/Swift-5.4-ED523F.svg?style=flat)](https://swift.org/download/)
67
[![Swift 5.5](https://img.shields.io/badge/Swift-5.5-ED523F.svg?style=flat)](https://swift.org/download/)
8+
[![Swift 5.6](https://img.shields.io/badge/Swift-5.6-ED523F.svg?style=flat)](https://swift.org/download/)
9+
[![Swift 5.7](https://img.shields.io/badge/Swift-5.7-ED523F.svg?style=flat)](https://swift.org/download/)
710

8-
> ⚠️ Automatic propagation through task-locals only supported in Swift >= 5.5
11+
> **Warning**
12+
> Automatic propagation through task-locals only supported in Swift >= 5.5
913
1014
`Baggage` is a minimal (zero-dependency) context propagation container, intended to "carry" baggage items
1115
for purposes of cross-cutting tools to be built on top of it.
1216

13-
It is modeled after the concepts explained in [W3C Baggage](https://w3c.github.io/baggage/) and the
17+
It is modeled after the concepts explained in [W3C Baggage](https://w3c.github.io/baggage/) and the
1418
in the spirit of [Tracing Plane](https://cs.brown.edu/~jcmace/papers/mace18universal.pdf) 's "Baggage Context" type,
1519
although by itself it does not define a specific serialization format.
1620

@@ -20,7 +24,7 @@ deploy various cross-cutting instruments all reusing the same baggage type. More
2024

2125
## Dependency
2226

23-
In order to depend on this library you can use the Swift Package Manager, and add the following dependency to your `Package.swift`:
27+
In order to depend on this library you can use the Swift Package Manager, and add the following dependency to your `Package.swift`:
2428

2529
```swift
2630
dependencies: [
@@ -33,18 +37,18 @@ dependencies: [
3337

3438
and depend on the module in your target:
3539

36-
```swift
40+
```swift
3741
targets: [
3842
.target(
3943
name: "MyAwesomeApp",
4044
dependencies: [
4145
.product(
42-
name: "InstrumentationBaggage",
46+
name: "InstrumentationBaggage",
4347
package: "swift-distributed-tracing-baggage"
4448
),
4549
]
4650
),
47-
// ...
51+
// ...
4852
]
4953
```
5054

Tests/InstrumentationBaggageTests/BaggageTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ final class BaggageTests: XCTestCase {
6363
}
6464

6565
func test_automaticPropagationThroughTaskLocal() throws {
66-
#if swift(>=5.5) && canImport(_Concurrency)
66+
#if compiler(>=5.5)
6767
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else {
6868
throw XCTSkip("Task locals are not supported on this platform.")
6969
}
@@ -78,7 +78,8 @@ final class BaggageTests: XCTestCase {
7878
propagatedBaggage = Baggage.current
7979
}
8080

81-
Baggage.$current.withValue(baggage, operation: exampleFunction)
81+
let c = Baggage.$current
82+
c.withValue(baggage, operation: exampleFunction)
8283

8384
XCTAssertEqual(propagatedBaggage?.count, 1)
8485
XCTAssertEqual(propagatedBaggage?[FirstTestKey.self], 42)

docker/docker-compose.1804.51.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: "3"
2+
3+
services:
4+
5+
runtime-setup:
6+
image: swift-distributed-tracing-baggage:18.04-5.1
7+
build:
8+
args:
9+
ubuntu_version: "bionic"
10+
swift_version: "5.1"
11+
12+
test:
13+
image: swift-distributed-tracing-baggage:18.04-5.1
14+
15+
shell:
16+
image: swift-distributed-tracing-baggage:18.04-5.1

0 commit comments

Comments
 (0)