Skip to content

Commit

Permalink
ci: enhance tests including c and cpp
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Jul 22, 2024
1 parent f47b7b3 commit b9b9ec4
Show file tree
Hide file tree
Showing 16 changed files with 199 additions and 1,506 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/c-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: c-test

on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
branches:
- main
paths:
- "c/**"
- ".github/workflows/c-test.yaml"
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

permissions:
contents: read

jobs:
build-and-test:
defaults:
run:
working-directory: "c"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.79
override: true
components: clippy, rustfmt
- name: Build
run: |
make
make examples
- name: Run Examples
shell: bash
run: |
cd examples
for file in ./*
do
if [[ -f "$file" && -x "$file" ]]; then
echo "Executing: $file"
if ! "$file"; then
echo "Error occurred while executing $file. Exiting script."
exit 1
fi
fi
done
62 changes: 62 additions & 0 deletions .github/workflows/cpp-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: cpp-test

on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
branches:
- main
paths:
- "cpp/**"
- ".github/workflows/cpp-test.yaml"
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

permissions:
contents: read

jobs:
build-and-test:
defaults:
run:
working-directory: "cpp"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install libgtest-dev ninja-build
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.79
override: true
components: clippy, rustfmt
- name: Build
run: |
mkdir build
cd build
cmake ..
make -j8
- name: Run Examples
shell: bash
run: |
cd build
for file in ./*
do
if [[ -f "$file" && -x "$file" ]]; then
echo "Executing: $file"
if ! "$file"; then
echo "Error occurred while executing $file. Exiting script."
exit 1
fi
fi
done
5 changes: 3 additions & 2 deletions .github/workflows/dotnet-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- main
paths:
- "dotnet/**"
- ".github/workflows/dotnet-test.yaml"
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -68,7 +69,7 @@ jobs:
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.77
toolchain: 1.79
override: true
components: clippy, rustfmt
- name: Setup linux-aarch_64 rust target
Expand Down Expand Up @@ -123,7 +124,7 @@ jobs:
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.77
toolchain: 1.79
override: true
components: clippy, rustfmt

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
- "go/**"
- "go.mod"
- "go.sum"
- ".github/workflows/go-test.yaml"
workflow_dispatch:

permissions:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/java-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- main
paths:
- "java/**"
- ".github/workflows/java-test.yaml"
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -59,7 +60,7 @@ jobs:
- name: Install rust nightly toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.77
toolchain: 1.79
override: true
components: clippy, rustfmt

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/nodejs-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
- main
paths:
- "nodejs/**"
- ".github/workflows/nodejs-test.yaml"
workflow_dispatch:

jobs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/python-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:
- main
paths:
- "python/**"
- ".github/workflows/python-test.yaml"
workflow_dispatch:

permissions:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/rust-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
paths:
- "Cargo.toml"
- "src/**"
- ".github/workflows/rust-test.yaml"
workflow_dispatch:

permissions:
Expand All @@ -30,7 +31,7 @@ jobs:
- name: Install rust nightly toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.77
toolchain: 1.79
override: true
components: clippy, rustfmt
- name: Rust code test
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/wasm-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- main
paths:
- "wasm/**"
- ".github/workflows/wasm-test.yaml"
workflow_dispatch:

jobs:
Expand Down
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,61 @@ function main() {
main();
```

### C++

For CMake, you can use FetchContent to add KCL C++ Lib to your project.

```shell
FetchContent_Declare(
kcl-lib
GIT_REPOSITORY https://github.com/kcl-lang/lib.git
GIT_TAG v0.9.3
SOURCE_SUBDIR cpp
)
FetchContent_MakeAvailable(kcl-lib)
```

Or you can download the source code and add it to your project.

```shell
mkdir third_party
cd third_party
git clone https://github.com/kcl-lang/lib.git
```

```shell
add_subdirectory(third_party/lib/cpp)
```

```shell
target_link_libraries(your_target kcl-lib-cpp)
```

Write the code

```cpp
#include "kcl_lib.hpp"
#include <iostream>

int main()
{
auto args = kcl_lib::ExecProgramArgs();
auto files = rust::Vec<rust::String>();
files.push_back(rust::String("../test_data/schema.k"));
args.k_filename_list = files;
auto result = kcl_lib::exec_program(args);
std::cout << result.yaml_result.c_str() << std::endl;
}
```

### C

See [here](./c/)

### WASM

See [here](./wasm/)

## Documents

See [here](https://www.kcl-lang.io/docs/reference/xlang-api/overview)
Expand Down
2 changes: 1 addition & 1 deletion c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ STATIC_LIB = $(LIB_DIR)/libkcl_lib_c.a
CCFLAGS=-I./include
CXXFLAGS=-I./include -std=c++14

all: cargo-build $(STATIC_LIB)
all: cargo $(STATIC_LIB)

debug: CFLAGS += -g
debug: all
Expand Down
22 changes: 0 additions & 22 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,3 @@ if(WIN32)
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}
)
endif()

# Tests
if (KCL_LIB_ENABLE_TESTING)
enable_testing()
find_package(GTest REQUIRED)
file(GLOB_RECURSE TEST_SOURCE_FILE tests/*.cpp)
add_executable(kcl-lib-cpp_test ${TEST_SOURCE_FILE})
target_include_directories(kcl-lib-cpp_test PUBLIC ${CPP_INCLUDE_DIR} ${GTEST_INCLUDE_DIRS})
target_link_libraries(kcl-lib-cpp_test ${GTEST_LDFLAGS} GTest::gtest_main kcl-lib-cpp)
target_compile_options(kcl-lib-cpp_test PRIVATE ${GTEST_CFLAGS})

# Platform-specific test configuration
if(WIN32)
target_link_libraries(kcl-lib-cpp_test userenv ws2_32 bcrypt)
endif()
if(APPLE)
target_link_libraries(kcl-lib-cpp_test "-framework CoreFoundation -framework Security")
endif()

include(GoogleTest)
gtest_discover_tests(kcl-lib-cpp_test)
endif()
4 changes: 4 additions & 0 deletions cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ fmt:
.PHONY: cargo
cargo:
cargo build -r

.PHONY: cpp
cpp:
cmake --build build --parallel
12 changes: 10 additions & 2 deletions cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,20 @@ target_link_libraries(your_target kcl-lib-cpp)
+ C++ Compiler with C++17 Support
+ Cargo

If you build in macos, you set the environment.

```shell
# Set cargo build target on macos
export MACOSX_DEPLOYMENT_TARGET='10.13'
mkdir build
```

Use cmake to build the whole project.

```shell
mkdir -p build
cd build
cmake ..
make
make -j8
```

## Examples
Expand Down
8 changes: 0 additions & 8 deletions spec/gpyrpc/Makefile

This file was deleted.

Loading

0 comments on commit b9b9ec4

Please sign in to comment.