Skip to content

Commit bd945ee

Browse files
Merge pull request #2 from NeedleInAJayStack/feature/linux-compat
Linux compatibility
2 parents 35b9e00 + e30666a commit bd945ee

File tree

18 files changed

+705
-133
lines changed

18 files changed

+705
-133
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ on:
44
push: { branches: [ main ] }
55

66
jobs:
7-
test:
8-
strategy:
9-
matrix:
10-
os: [ubuntu-latest, macos-latest]
11-
runs-on: ${{ matrix.os }}
7+
darwin-test:
8+
runs-on: macos-latest
129
steps:
13-
- uses: fwal/setup-swift@v1
10+
- uses: maxim-lobanov/setup-xcode@v1
11+
with:
12+
xcode-version: latest
1413
- uses: actions/checkout@v2
15-
- name: Run tests
16-
run: swift test
14+
- name: Darwin build & test
15+
run: swift test --skip IntegrationTests
16+
linux-build:
17+
runs-on: ubuntu-latest
18+
container:
19+
image: swift:latest
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Linux build
23+
run: swift build --target HaystackClientNIO

Package.resolved

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,65 @@ import PackageDescription
44

55
let package = Package(
66
name: "Haystack",
7+
platforms: [
8+
.macOS(.v12),
9+
.iOS(.v15),
10+
.tvOS(.v15),
11+
.watchOS(.v8)
12+
],
713
products: [
814
.library(
915
name: "Haystack",
1016
targets: ["Haystack"]
1117
),
1218
.library(
13-
name: "HaystackClient",
14-
targets: ["HaystackClient"]
19+
name: "HaystackClientDarwin",
20+
targets: [
21+
"HaystackClient",
22+
"HaystackClientDarwin"
23+
]
24+
),
25+
.library(
26+
name: "HaystackClientNIO",
27+
targets: [
28+
"HaystackClient",
29+
"HaystackClientNIO"
30+
]
1531
),
1632
],
17-
dependencies: [],
33+
dependencies: [
34+
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "3.0.0"),
35+
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.9.0")
36+
],
1837
targets: [
1938
.target(
2039
name: "Haystack",
2140
dependencies: []
2241
),
2342
.target(
2443
name: "HaystackClient",
25-
dependencies: ["Haystack"]
44+
dependencies: [
45+
"Haystack",
46+
.product(name: "Crypto", package: "swift-crypto"),
47+
]
2648
),
49+
.target(
50+
name: "HaystackClientDarwin",
51+
dependencies: [
52+
"Haystack",
53+
"HaystackClient",
54+
]
55+
),
56+
.target(
57+
name: "HaystackClientNIO",
58+
dependencies: [
59+
"Haystack",
60+
"HaystackClient",
61+
.product(name: "AsyncHTTPClient", package: "async-http-client"),
62+
]
63+
),
64+
65+
// Tests
2766
.testTarget(
2867
name: "HaystackTests",
2968
dependencies: ["Haystack"]
@@ -33,8 +72,12 @@ let package = Package(
3372
dependencies: ["HaystackClient"]
3473
),
3574
.testTarget(
36-
name: "HaystackClientIntegrationTests",
37-
dependencies: ["HaystackClient"]
75+
name: "HaystackClientNIOIntegrationTests",
76+
dependencies: ["HaystackClientNIO"]
77+
),
78+
.testTarget(
79+
name: "HaystackClientDarwinIntegrationTests",
80+
dependencies: ["HaystackClientDarwin"]
3881
),
3982
]
4083
)

README.md

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,120 @@
11
# Swift Haystack
22

3-
An implementation of Project Haystack in Swift.
3+
An implementation of [Project Haystack](https://project-haystack.org/) in Swift.
4+
5+
## Getting Started
6+
7+
To use this package, add it to your `Package.swift` dependencies:
8+
9+
```swift
10+
dependencies: [
11+
.package(url: "https://github.com/NeedleInAJayStack/swift-haystack.git", from: "0.0.0"),
12+
],
13+
targets: [
14+
.target(
15+
name: "MyTarget",
16+
dependencies: [
17+
.product(name: "Haystack", package: "swift-haystack"),
18+
]
19+
),
20+
]
21+
```
22+
23+
You can then import and use the different libraries:
24+
25+
```swift
26+
import Haystack
27+
28+
func testGrid() throws -> Grid {
29+
return try ZincReader(
30+
"""
31+
ver:"3.0" foo:"bar"
32+
dis dis:"Equip Name", equip, siteRef, installed
33+
"RTU-1", M, @153c-699a HQ, 2005-06-01
34+
"RTU-2", M, @153c-699b Library, 1997-07-12
35+
"""
36+
).readGrid()
37+
}
38+
```
39+
40+
See below for available libraries and descriptions.
41+
42+
## Available Packages
43+
44+
### Haystack
45+
46+
This contains the
47+
[Haystack type-system primitives](https://project-haystack.org/doc/docHaystack/Kinds)
48+
and utilities to interact with them.
49+
50+
### HaystackClientDarwin
51+
52+
A Darwin-only client driver for the
53+
[Haystack HTTP API](https://project-haystack.org/doc/docHaystack/HttpApi) that
54+
requires minimal dependencies. Use this if you are only deploying to MacOS, iOS, etc and want
55+
to reduce dependencies.
56+
57+
Here's an example of how to use it:
58+
59+
```swift
60+
import HaystackClientDarwin
61+
62+
func client() throws -> Client {
63+
return try Client(
64+
baseUrl: "http://mydomain.com/api/",
65+
username: "username",
66+
password: "password"
67+
)
68+
}
69+
```
70+
71+
### HaystackClientNIO
72+
73+
A cross-platform client driver for the
74+
[Haystack HTTP API](https://project-haystack.org/doc/docHaystack/HttpApi) that
75+
has larger dependency requirements. Use this if you are only deploying to Linux or if you
76+
are deploying to Darwin platforms and are willing to accept more dependencies.
77+
78+
Here's an example of how to use it:
79+
80+
```swift
81+
import HaystackClientNIO
82+
83+
func client() throws -> Client {
84+
return try Client(
85+
baseUrl: "http://mydomain.com/api/",
86+
username: "username",
87+
password: "password",
88+
eventLoopGroup: MultiThreadedEventLoopGroup(numberOfThreads: 1)
89+
)
90+
}
91+
```
92+
93+
### HaystackClient
94+
95+
This defines the main functionality of Haystack API clients. It should not be imported directly;
96+
its assets are imported automatically by `HaystackClientDarwin` or `HaystackClientNIO`.
97+
98+
Once you create a client, you can use it to make requests:
99+
100+
```swift
101+
func yesterdaysValues() async throws -> Grid {
102+
let client = ...
103+
104+
// Open and authenticate. This must be called before requests can be made
105+
try await client.open()
106+
107+
// Request the historical values for @28e7fb7d-e20316e0
108+
let grid = try await client.hisRead(id: Ref("28e7fb7d-e20316e0"), range: .yesterday)
109+
110+
// Close the client session and log out
111+
try await client.close()
112+
113+
return grid
114+
}
115+
```
116+
117+
## License
118+
119+
This package is licensed under the Academic Free License 3.0 for maximum compatibility with
120+
Project Haystack itself.
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import CryptoKit
1+
import Crypto
22

3-
@available(macOS 10.15, *)
43
enum AuthHash: String {
54
case SHA512 = "SHA-512"
65
case SHA256 = "SHA-256"
76

87
var hash: any HashFunction.Type {
98
switch self {
109
case .SHA256:
11-
return CryptoKit.SHA256.self
10+
return Crypto.SHA256.self
1211
case .SHA512:
13-
return CryptoKit.SHA512.self
12+
return Crypto.SHA512.self
1413
}
1514
}
1615
}

0 commit comments

Comments
 (0)