Skip to content

Commit e34063c

Browse files
committed
feat: kcl swift lib
Signed-off-by: peefy <xpf6677@163.com>
1 parent 8facb02 commit e34063c

File tree

18 files changed

+5061
-1
lines changed

18 files changed

+5061
-1
lines changed

.github/workflows/swift-test.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: swift-test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
tags:
9+
- '*'
10+
pull_request:
11+
branches:
12+
- main
13+
paths:
14+
- "swift/**"
15+
- ".github/workflows/swift-test.yaml"
16+
workflow_dispatch:
17+
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
20+
cancel-in-progress: true
21+
22+
permissions:
23+
contents: read
24+
25+
jobs:
26+
build-and-test:
27+
defaults:
28+
run:
29+
working-directory: "swift"
30+
strategy:
31+
matrix:
32+
os: [macos-12, macos-latest, ubuntu-latest]
33+
runs-on: ${{ matrix.os }}
34+
steps:
35+
- uses: actions/checkout@v4
36+
- name: Install dependencies
37+
if: "contains(matrix.os, 'ubuntu-latest')"
38+
run: |
39+
sudo apt-get update
40+
sudo apt-get install libgtest-dev ninja-build
41+
- name: Install Rust
42+
uses: actions-rs/toolchain@v1
43+
with:
44+
toolchain: 1.79
45+
override: true
46+
components: clippy, rustfmt
47+
- name: Setup Swift toolchain
48+
uses: swift-actions/setup-swift@v1
49+
with:
50+
swift-version: 5
51+
- name: Build and run tests
52+
run: make test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ _a.out_*.*
3131
**/.DS_Store
3232
**/.vscode
3333
__pycache__
34+
build

spec/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ run:
55
protoc spec.proto --python_out ../python/kcl_lib/api
66
protoc spec.proto --go_out ../go/api
77
protoc spec.proto --csharp_out ../dotnet/KclLib/api
8-
protoc spec.proto --cpp_out ../cpp/src/api
8+
// brew install swift-protobuf
9+
protoc spec.proto --swift_out=Visibility=Public:../swift/Sources/KclLib

swift/.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/
6+
DerivedData/
7+
.netrc
8+
9+
/KclLib/.build
10+
/KclLib/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
11+
/KclLib/.swiftpm/config/registries.json
12+
/KclLib/Sources/CKclLib/lib

swift/.swift-format

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": 1,
3+
"lineLength": 100,
4+
"indentation": {
5+
"spaces": 4
6+
},
7+
"maximumBlankLines": 1,
8+
"respectsExistingLineBreaks": true,
9+
"lineBreakBeforeControlFlowKeywords": true,
10+
"lineBreakBeforeEachArgument": true
11+
}

swift/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "kcl-lib-c"
3+
version = "0.10.0-alpha.1"
4+
edition = "2021"
5+
publish = false
6+
7+
[lib]
8+
crate-type = ["cdylib", "staticlib"]
9+
doc = false
10+
11+
[build-dependencies]
12+
cbindgen = "0.26.0"
13+
14+
[dependencies]
15+
kclvm-api = { git = "https://github.com/kcl-lang/kcl", version = "0.10.0-alpha.1" }

swift/Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
INCLUDE_DIR=./Sources/CKclLib/include
2+
LIB_DIR=./Sources/CKclLib/lib
3+
4+
.PHONY: all
5+
all: build
6+
7+
.PHONY: build
8+
build: cargo
9+
swift build
10+
11+
.PHONY: cargo
12+
cargo:
13+
cargo build -r
14+
mkdir -p $(LIB_DIR)
15+
cp ./target/release/libkcl_lib_c.a $(LIB_DIR)
16+
17+
.PHONY: test
18+
test: cargo
19+
swift test
20+
21+
.PHONY: clean
22+
clean:
23+
cargo clean
24+
rm -rf $(LIB_DIR)

swift/Package.resolved

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

swift/Package.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// swift-tools-version: 5.8
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "KclLib",
8+
products: [
9+
.library(
10+
name: "KclLib",
11+
targets: ["KclLib"]
12+
)
13+
],
14+
dependencies: [
15+
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.27.0"),
16+
],
17+
targets: [
18+
.systemLibrary(name: "CKclLib"),
19+
.target(
20+
name: "KclLib",
21+
dependencies: [
22+
"CKclLib",
23+
.product(name: "SwiftProtobuf", package: "swift-protobuf")
24+
],
25+
linkerSettings: [
26+
.unsafeFlags(["-L", "Sources/CKclLib/lib"])
27+
]
28+
),
29+
.testTarget(
30+
name: "KclLibTests",
31+
dependencies: ["KclLib"]
32+
),
33+
]
34+
)

swift/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# KCL Artifact Library for Swift
2+
3+
This repo is under development, PRs welcome!
4+
5+
## Developing
6+
7+
If you build on macos, you can set the environment to prevent link errors.
8+
9+
**Prerequisites**
10+
11+
+ Swift 5.8+
12+
+ Cargo
13+
14+
```shell
15+
# Set cargo build target on macos
16+
export MACOSX_DEPLOYMENT_TARGET='10.13'
17+
```
18+
19+
**Build**
20+
21+
```shell
22+
make
23+
```
24+
25+
**Test**
26+
27+
```shell
28+
make test
29+
```

0 commit comments

Comments
 (0)