Compare commits
12
Commits
0e0047b946
...
v1.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
714281dbf1 | ||
|
|
9bce4b12cf | ||
|
|
e3c40c822b | ||
|
|
f6684bebc9 | ||
|
|
924c33fedf | ||
|
|
89c4e770d5 | ||
|
|
1027d47e04 | ||
|
|
323b6bd464 | ||
|
|
f5cb361ffe | ||
|
|
29c49057b4 | ||
|
|
03039bd493 | ||
|
|
0d06f797f8 |
@@ -4,73 +4,7 @@ on:
|
|||||||
branches: [main]
|
branches: [main]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
|
||||||
runs-on: ubuntu-builder
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
target:
|
|
||||||
- name: linux-amd64
|
|
||||||
toolchain: ""
|
|
||||||
cmake_extra: ""
|
|
||||||
build_testing: ON
|
|
||||||
- name: linux-arm64
|
|
||||||
toolchain: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-linux-arm64.cmake
|
|
||||||
cmake_extra: ""
|
|
||||||
build_testing: OFF
|
|
||||||
- name: linux-armhf
|
|
||||||
toolchain: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-linux-armhf.cmake
|
|
||||||
cmake_extra: ""
|
|
||||||
build_testing: OFF
|
|
||||||
- name: windows-amd64
|
|
||||||
toolchain: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-windows-amd64.cmake
|
|
||||||
cmake_extra: -DBUILD_EXAMPLES=OFF
|
|
||||||
build_testing: OFF
|
|
||||||
- name: baremetal-arm32
|
|
||||||
toolchain: -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-baremetal-arm32.cmake
|
|
||||||
cmake_extra: -DBUILD_EXAMPLES=OFF -DBUILD_SHARED=OFF
|
|
||||||
build_testing: OFF
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Install cross-compilers
|
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y \
|
|
||||||
gcc-arm-linux-gnueabihf \
|
|
||||||
gcc-aarch64-linux-gnu \
|
|
||||||
gcc-mingw-w64-x86-64 \
|
|
||||||
gcc-arm-none-eabi
|
|
||||||
|
|
||||||
- name: Configure
|
|
||||||
run: cmake -S . -B build -DBUILD_TESTING=${{ matrix.target.build_testing }} ${{ matrix.target.toolchain }} ${{ matrix.target.cmake_extra }}
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: cmake --build build
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
if: matrix.target.build_testing == 'ON'
|
|
||||||
run: ctest --test-dir build --output-on-failure
|
|
||||||
|
|
||||||
- name: Package
|
|
||||||
run: |
|
|
||||||
PKG="datarouter-${{ matrix.target.name }}"
|
|
||||||
mkdir -p "dist/$PKG"
|
|
||||||
for f in datarouter.h datarouter_config_template.h LICENSE README.md; do
|
|
||||||
if [ -f "$f" ]; then cp "$f" "dist/$PKG/"; fi
|
|
||||||
done
|
|
||||||
for f in libDataRouter.a libDataRouter.so libDataRouter.dll libDataRouter.dll.a example example.exe; do
|
|
||||||
if [ -f "build/$f" ]; then cp "build/$f" "dist/$PKG/"; fi
|
|
||||||
done
|
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: datarouter-${{ matrix.target.name }}
|
|
||||||
path: dist/datarouter-${{ matrix.target.name }}
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
needs: build
|
|
||||||
runs-on: ubuntu-builder
|
runs-on: ubuntu-builder
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -89,30 +23,64 @@ jobs:
|
|||||||
[ -n "$TAG" ] || exit 78
|
[ -n "$TAG" ] || exit 78
|
||||||
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
|
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- uses: actions/download-artifact@v4
|
- name: Install cross-compilers
|
||||||
with:
|
run: |
|
||||||
path: artifacts
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y \
|
||||||
|
gcc-arm-linux-gnueabihf \
|
||||||
|
gcc-aarch64-linux-gnu \
|
||||||
|
gcc-mingw-w64-x86-64 \
|
||||||
|
gcc-arm-none-eabi
|
||||||
|
|
||||||
|
- name: Build all targets
|
||||||
|
run: |
|
||||||
|
for entry in \
|
||||||
|
"linux-amd64|ON|" \
|
||||||
|
"linux-arm64|OFF|-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-linux-arm64.cmake" \
|
||||||
|
"linux-armhf|OFF|-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-linux-armhf.cmake" \
|
||||||
|
"windows-amd64|OFF|-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-windows-amd64.cmake -DBUILD_EXAMPLES=OFF" \
|
||||||
|
"baremetal-arm32|OFF|-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-baremetal-arm32.cmake -DBUILD_EXAMPLES=OFF -DBUILD_SHARED=OFF"
|
||||||
|
do
|
||||||
|
IFS='|' read -r name testing extra <<< "$entry"
|
||||||
|
echo ">>> Building $name"
|
||||||
|
cmake -S . -B "build-$name" -DBUILD_TESTING=$testing $extra
|
||||||
|
cmake --build "build-$name"
|
||||||
|
[ "$testing" = "ON" ] && ctest --test-dir "build-$name" --output-on-failure
|
||||||
|
|
||||||
|
pkg="datarouter-$name"
|
||||||
|
cmake --install "build-$name" --prefix "dist/$pkg"
|
||||||
|
done
|
||||||
|
|
||||||
- name: Create release & upload assets
|
- name: Create release & upload assets
|
||||||
run: |
|
run: |
|
||||||
TAG="${{ steps.tag.outputs.tag }}"
|
TAG="${{ steps.tag.outputs.tag }}"
|
||||||
API="${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases"
|
API="${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases"
|
||||||
|
TOKEN="${{ gitea.token }}"
|
||||||
|
|
||||||
|
# Check if release already exists
|
||||||
|
echo "=== Checking existing releases for $TAG ==="
|
||||||
|
EXISTING=$(curl -s -H "Authorization: token ${TOKEN}" "${API}" | \
|
||||||
|
python3 -c "import sys,json;rels=json.load(sys.stdin);print(next((r['id'] for r in rels if r['tag_name']=='${TAG}'),''))")
|
||||||
|
|
||||||
|
if [ -n "$EXISTING" ]; then
|
||||||
|
ID="$EXISTING"
|
||||||
|
echo "Release already exists (ID=$ID), updating it"
|
||||||
|
else
|
||||||
echo "=== Creating release $TAG ==="
|
echo "=== Creating release $TAG ==="
|
||||||
RESP=$(curl -s -X POST \
|
RESP=$(curl -s -X POST \
|
||||||
-H "Authorization: token ${{ gitea.token }}" \
|
-H "Authorization: token ${TOKEN}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"tag_name\":\"${TAG}\",\"name\":\"DataRouter ${TAG}\"}" \
|
-d "{\"tag_name\":\"${TAG}\",\"name\":\"DataRouter ${TAG}\"}" \
|
||||||
"$API")
|
"$API")
|
||||||
|
ID=$(echo "$RESP" | python3 -c "import sys,json;d=json.loads(sys.stdin.read());print(d['id'])")
|
||||||
|
fi
|
||||||
|
|
||||||
ID=$(echo "$RESP" | python3 -c "import sys,json;print(json.load(sys.stdin)['id'])")
|
for dir in dist/*/; do
|
||||||
|
|
||||||
for dir in artifacts/*/; do
|
|
||||||
name="$(basename "$dir").tar.gz"
|
name="$(basename "$dir").tar.gz"
|
||||||
tar czf "/tmp/$name" -C "$dir" .
|
tar czf "/tmp/$name" -C "$dir" .
|
||||||
echo "Uploading $name"
|
echo "Uploading $name"
|
||||||
curl -s -X POST \
|
curl -s -X POST \
|
||||||
-H "Authorization: token ${{ gitea.token }}" \
|
-H "Authorization: token ${TOKEN}" \
|
||||||
-H "Content-Type: application/octet-stream" \
|
-H "Content-Type: application/octet-stream" \
|
||||||
--data-binary @"/tmp/$name" \
|
--data-binary @"/tmp/$name" \
|
||||||
"${API}/${ID}/assets?name=${name}"
|
"${API}/${ID}/assets?name=${name}"
|
||||||
|
|||||||
Generated
+8
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CidrCTestProjectState">
|
||||||
|
<ctestState>
|
||||||
|
<lineNumber testId="path:null test:datarouter" value="28" />
|
||||||
|
</ctestState>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
+55
-2
@@ -5,13 +5,19 @@ set(CMAKE_C_STANDARD 11)
|
|||||||
|
|
||||||
# ======== 静态库 ========
|
# ======== 静态库 ========
|
||||||
add_library(DataRouter STATIC datarouter.c)
|
add_library(DataRouter STATIC datarouter.c)
|
||||||
target_include_directories(DataRouter PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
target_include_directories(DataRouter PUBLIC
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||||
|
$<INSTALL_INTERFACE:include>
|
||||||
|
)
|
||||||
|
|
||||||
# ======== 共享库(可选,通过 BUILD_SHARED 控制) ========
|
# ======== 共享库(可选,通过 BUILD_SHARED 控制) ========
|
||||||
option(BUILD_SHARED "Build shared library" ON)
|
option(BUILD_SHARED "Build shared library" ON)
|
||||||
if(BUILD_SHARED)
|
if(BUILD_SHARED)
|
||||||
add_library(DataRouter_shared SHARED datarouter.c)
|
add_library(DataRouter_shared SHARED datarouter.c)
|
||||||
target_include_directories(DataRouter_shared PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
target_include_directories(DataRouter_shared PUBLIC
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||||
|
$<INSTALL_INTERFACE:include>
|
||||||
|
)
|
||||||
set_target_properties(DataRouter_shared PROPERTIES OUTPUT_NAME DataRouter)
|
set_target_properties(DataRouter_shared PROPERTIES OUTPUT_NAME DataRouter)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -28,3 +34,50 @@ if(BUILD_TESTING OR NOT DEFINED BUILD_TESTING)
|
|||||||
target_link_libraries(test_datarouter DataRouter)
|
target_link_libraries(test_datarouter DataRouter)
|
||||||
add_test(NAME datarouter COMMAND test_datarouter)
|
add_test(NAME datarouter COMMAND test_datarouter)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# ======== 安装规则 ========
|
||||||
|
|
||||||
|
# 静态库 → lib/
|
||||||
|
install(TARGETS DataRouter
|
||||||
|
EXPORT DataRouterTargets
|
||||||
|
ARCHIVE DESTINATION lib
|
||||||
|
)
|
||||||
|
|
||||||
|
# 共享库 → lib/(可选)
|
||||||
|
if(TARGET DataRouter_shared)
|
||||||
|
install(TARGETS DataRouter_shared
|
||||||
|
EXPORT DataRouterTargets
|
||||||
|
ARCHIVE DESTINATION lib # .lib (Windows import lib)
|
||||||
|
LIBRARY DESTINATION lib # .so
|
||||||
|
RUNTIME DESTINATION lib # .dll
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# 示例 → bin/
|
||||||
|
if(TARGET example)
|
||||||
|
install(TARGETS example RUNTIME DESTINATION bin)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# 头文件 → include/
|
||||||
|
install(FILES datarouter.h DESTINATION include)
|
||||||
|
|
||||||
|
# 文档 → share/
|
||||||
|
install(FILES datarouter_config_template.h LICENSE DESTINATION share)
|
||||||
|
if(EXISTS ${CMAKE_SOURCE_DIR}/README.md)
|
||||||
|
install(FILES README.md DESTINATION share)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# CMake 包配置文件 → cmake/
|
||||||
|
set(INCLUDE_INSTALL_DIR include)
|
||||||
|
set(LIB_INSTALL_DIR lib)
|
||||||
|
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
configure_package_config_file(
|
||||||
|
cmake/DataRouterConfig.cmake.in
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/DataRouterConfig.cmake
|
||||||
|
INSTALL_DESTINATION cmake
|
||||||
|
PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR
|
||||||
|
)
|
||||||
|
|
||||||
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/DataRouterConfig.cmake DESTINATION cmake)
|
||||||
|
install(EXPORT DataRouterTargets FILE DataRouterTargets.cmake DESTINATION cmake)
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
set_and_check(DataRouter_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
|
||||||
|
set_and_check(DataRouter_LIBRARY_DIR "@PACKAGE_LIB_INSTALL_DIR@")
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/DataRouterTargets.cmake" OPTIONAL)
|
||||||
|
|
||||||
|
if(NOT TARGET DataRouter::DataRouter)
|
||||||
|
add_library(DataRouter::DataRouter STATIC IMPORTED)
|
||||||
|
set_target_properties(DataRouter::DataRouter PROPERTIES
|
||||||
|
IMPORTED_LOCATION "${DataRouter_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}DataRouter${CMAKE_STATIC_LIBRARY_SUFFIX}"
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${DataRouter_INCLUDE_DIR}"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
check_required_components(DataRouter)
|
||||||
Reference in New Issue
Block a user