Skip to content

Commit 4e628ec

Browse files
authored
Merge pull request #122 from Peefy/ci-enhance-tests-including-c-and-cpp
ci: enhance tests including c and cpp
2 parents f47b7b3 + 695689a commit 4e628ec

File tree

18 files changed

+199
-1528
lines changed

18 files changed

+199
-1528
lines changed

.github/workflows/c-test.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: c-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+
- "c/**"
15+
- ".github/workflows/c-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: "c"
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
- name: Install Rust
34+
uses: actions-rs/toolchain@v1
35+
with:
36+
toolchain: 1.79
37+
override: true
38+
components: clippy, rustfmt
39+
- name: Build
40+
run: |
41+
make
42+
make examples
43+
- name: Run Examples
44+
shell: bash
45+
run: |
46+
cd examples
47+
for file in ./*
48+
do
49+
if [[ -f "$file" && -x "$file" ]]; then
50+
echo "Executing: $file"
51+
if ! "$file"; then
52+
echo "Error occurred while executing $file. Exiting script."
53+
exit 1
54+
fi
55+
fi
56+
done

.github/workflows/cpp-test.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: cpp-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+
- "cpp/**"
15+
- ".github/workflows/cpp-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: "cpp"
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
- name: Install dependencies
34+
run: |
35+
sudo apt-get update
36+
sudo apt-get install libgtest-dev ninja-build
37+
- name: Install Rust
38+
uses: actions-rs/toolchain@v1
39+
with:
40+
toolchain: 1.79
41+
override: true
42+
components: clippy, rustfmt
43+
- name: Build
44+
run: |
45+
mkdir build
46+
cd build
47+
cmake ..
48+
make -j8
49+
- name: Run Examples
50+
shell: bash
51+
run: |
52+
cd build
53+
for file in ./*
54+
do
55+
if [[ -f "$file" && -x "$file" ]]; then
56+
echo "Executing: $file"
57+
if ! "$file"; then
58+
echo "Error occurred while executing $file. Exiting script."
59+
exit 1
60+
fi
61+
fi
62+
done

.github/workflows/dotnet-test.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
- main
1313
paths:
1414
- "dotnet/**"
15+
- ".github/workflows/dotnet-test.yaml"
1516
workflow_dispatch:
1617

1718
jobs:
@@ -68,7 +69,7 @@ jobs:
6869
- name: Install Rust
6970
uses: actions-rs/toolchain@v1
7071
with:
71-
toolchain: 1.77
72+
toolchain: 1.79
7273
override: true
7374
components: clippy, rustfmt
7475
- name: Setup linux-aarch_64 rust target
@@ -123,7 +124,7 @@ jobs:
123124
- name: Install Rust
124125
uses: actions-rs/toolchain@v1
125126
with:
126-
toolchain: 1.77
127+
toolchain: 1.79
127128
override: true
128129
components: clippy, rustfmt
129130

.github/workflows/go-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414
- "go/**"
1515
- "go.mod"
1616
- "go.sum"
17+
- ".github/workflows/go-test.yaml"
1718
workflow_dispatch:
1819

1920
permissions:

.github/workflows/java-test.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
- main
1313
paths:
1414
- "java/**"
15+
- ".github/workflows/java-test.yaml"
1516
workflow_dispatch:
1617

1718
jobs:
@@ -59,7 +60,7 @@ jobs:
5960
- name: Install rust nightly toolchain
6061
uses: actions-rs/toolchain@v1
6162
with:
62-
toolchain: 1.77
63+
toolchain: 1.79
6364
override: true
6465
components: clippy, rustfmt
6566

.github/workflows/nodejs-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ on:
1515
- main
1616
paths:
1717
- "nodejs/**"
18+
- ".github/workflows/nodejs-test.yaml"
1819
workflow_dispatch:
1920

2021
jobs:

.github/workflows/python-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ on:
1717
- main
1818
paths:
1919
- "python/**"
20+
- ".github/workflows/python-test.yaml"
2021
workflow_dispatch:
2122

2223
permissions:

.github/workflows/rust-test.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ on:
1313
paths:
1414
- "Cargo.toml"
1515
- "src/**"
16+
- ".github/workflows/rust-test.yaml"
1617
workflow_dispatch:
1718

1819
permissions:
@@ -30,7 +31,7 @@ jobs:
3031
- name: Install rust nightly toolchain
3132
uses: actions-rs/toolchain@v1
3233
with:
33-
toolchain: 1.77
34+
toolchain: 1.79
3435
override: true
3536
components: clippy, rustfmt
3637
- name: Rust code test

.github/workflows/wasm-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
- main
1212
paths:
1313
- "wasm/**"
14+
- ".github/workflows/wasm-test.yaml"
1415
workflow_dispatch:
1516

1617
jobs:

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,61 @@ function main() {
161161
main();
162162
```
163163

164+
### C++
165+
166+
For CMake, you can use FetchContent to add KCL C++ Lib to your project.
167+
168+
```shell
169+
FetchContent_Declare(
170+
kcl-lib
171+
GIT_REPOSITORY https://github.com/kcl-lang/lib.git
172+
GIT_TAG v0.9.3
173+
SOURCE_SUBDIR cpp
174+
)
175+
FetchContent_MakeAvailable(kcl-lib)
176+
```
177+
178+
Or you can download the source code and add it to your project.
179+
180+
```shell
181+
mkdir third_party
182+
cd third_party
183+
git clone https://github.com/kcl-lang/lib.git
184+
```
185+
186+
```shell
187+
add_subdirectory(third_party/lib/cpp)
188+
```
189+
190+
```shell
191+
target_link_libraries(your_target kcl-lib-cpp)
192+
```
193+
194+
Write the code
195+
196+
```cpp
197+
#include "kcl_lib.hpp"
198+
#include <iostream>
199+
200+
int main()
201+
{
202+
auto args = kcl_lib::ExecProgramArgs();
203+
auto files = rust::Vec<rust::String>();
204+
files.push_back(rust::String("../test_data/schema.k"));
205+
args.k_filename_list = files;
206+
auto result = kcl_lib::exec_program(args);
207+
std::cout << result.yaml_result.c_str() << std::endl;
208+
}
209+
```
210+
211+
### C
212+
213+
See [here](./c/)
214+
215+
### WASM
216+
217+
See [here](./wasm/)
218+
164219
## Documents
165220

166221
See [here](https://www.kcl-lang.io/docs/reference/xlang-api/overview)

0 commit comments

Comments
 (0)