Skip to content

Commit 5121f4f

Browse files
committed
ci: add Docker builds for Ubuntu 20.04/22.04 and fix libcanbus linking
- Add Dockerfiles and build scripts for Ubuntu 20.04 and 22.04 - Fix linking failure of pre-built libcanbus library by updating linker flags
1 parent 1dd18da commit 5121f4f

11 files changed

Lines changed: 487 additions & 91 deletions

File tree

.github/workflows/ci.yml

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,67 @@ on:
99

1010
env:
1111
BUILD_TYPE: Release
12+
DEBIAN_FRONTEND: noninteractive
13+
TZ: Asia/Shanghai
1214

1315
jobs:
1416
build-and-test:
15-
name: Build and Test - ${{ matrix.os }} (${{ matrix.arch }})
17+
name: Build and Test - ${{ matrix.container || matrix.os }} (${{ matrix.arch }}, ${{ matrix.cmake_build_type }})
1618
runs-on: ${{ matrix.os }}
19+
container: ${{ matrix.container }}
1720
strategy:
1821
fail-fast: false
1922
matrix:
2023
include:
21-
# Linux x86_64 (主要测试平台)
24+
# Linux x86_64 (主要测试平台, runner 原生环境)
2225
- os: ubuntu-latest
26+
container: ''
2327
arch: x86_64
2428
cmake_build_type: Release
2529
use_qemu: false
2630
# Linux x86_64 Debug 构建
2731
- os: ubuntu-latest
32+
container: ''
2833
arch: x86_64
2934
cmake_build_type: Debug
3035
use_qemu: false
3136
# Linux aarch64 Release 构建 (使用 QEMU 模拟)
3237
- os: ubuntu-latest
38+
container: ''
3339
arch: aarch64
3440
cmake_build_type: Release
3541
use_qemu: true
42+
# Ubuntu 22.04 容器 (Docker)
43+
- os: ubuntu-latest
44+
container: 'ubuntu:22.04'
45+
arch: x86_64
46+
cmake_build_type: Release
47+
use_qemu: false
48+
# Ubuntu 20.04 容器 (Docker)
49+
- os: ubuntu-latest
50+
container: 'ubuntu:20.04'
51+
arch: x86_64
52+
cmake_build_type: Release
53+
use_qemu: false
3654

3755
steps:
56+
- name: 准备容器环境 (Ubuntu 20.04/22.04)
57+
if: matrix.container != ''
58+
shell: bash
59+
run: |
60+
apt-get update
61+
apt-get install -y --no-install-recommends \
62+
sudo \
63+
ca-certificates \
64+
tzdata \
65+
git \
66+
build-essential \
67+
cmake \
68+
make \
69+
libpthread-stubs0-dev \
70+
tar \
71+
gzip
72+
3873
- name: 检出代码
3974
uses: actions/checkout@v4
4075

@@ -50,9 +85,9 @@ jobs:
5085
path: |
5186
build
5287
~/.cmake
53-
key: ${{ runner.os }}-cmake-${{ matrix.arch }}-${{ matrix.cmake_build_type }}-${{ hashFiles('**/CMakeLists.txt') }}
88+
key: ${{ runner.os }}-${{ matrix.container || 'native' }}-cmake-${{ matrix.arch }}-${{ matrix.cmake_build_type }}-${{ hashFiles('**/CMakeLists.txt') }}
5489
restore-keys: |
55-
${{ runner.os }}-cmake-${{ matrix.arch }}-${{ matrix.cmake_build_type }}-
90+
${{ runner.os }}-${{ matrix.container || 'native' }}-cmake-${{ matrix.arch }}-${{ matrix.cmake_build_type }}-
5691
5792
- name: 安装构建依赖
5893
run: |

cmake/linkerhand-cpp-sdk-config.cmake

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,31 @@ if(NOT TARGET LinkerHand::linkerhand_cpp_sdk)
123123
set_target_properties(LinkerHand::linkerhand_cpp_sdk PROPERTIES
124124
IMPORTED_IMPLIB "${_lh_imported_implib}")
125125
endif()
126-
# 公共头 CanFD.h / PCANBus.h / CanFrame.h 引用了 third_party 头(Hcanbus.h /
127-
# PCANBasic.h)。把对应 include 目录补到 imported target,下游 link 后无需手动配。
126+
# 是否启用 CAN-FD:release-package 由 CI 在 USE_CANFD=ON 下打包,默认 ON;
127+
# 下游可显式 -DLINKERHAND_USE_CANFD=OFF 覆盖,跳过 libcanbus 头依赖。
128+
if(NOT DEFINED LINKERHAND_USE_CANFD)
129+
if(EXISTS "${_lh_thirdparty_root}/libcanbus")
130+
set(LINKERHAND_USE_CANFD ON)
131+
else()
132+
set(LINKERHAND_USE_CANFD OFF)
133+
endif()
134+
endif()
135+
set_property(TARGET LinkerHand::linkerhand_cpp_sdk APPEND PROPERTY
136+
INTERFACE_COMPILE_DEFINITIONS "LINKERHAND_USE_CANFD=$<IF:$<BOOL:${LINKERHAND_USE_CANFD}>,1,0>")
137+
# 公共头 PCANBus.h / CanFrame.h(以及 CANFD 开启时的 CanFD.h)引用了 third_party
138+
# 头(PCANBasic.h / Hcanbus.h)。把对应 include 目录补到 imported target,下游 link
139+
# 后无需手动配。
128140
if(_lh_thirdparty_root)
129141
if(WIN32)
130-
if(EXISTS "${_lh_thirdparty_root}/libcanbus/include/windows")
131-
set_property(TARGET LinkerHand::linkerhand_cpp_sdk APPEND PROPERTY
132-
INTERFACE_INCLUDE_DIRECTORIES "${_lh_thirdparty_root}/libcanbus/include/windows")
133-
endif()
134142
if(EXISTS "${_lh_thirdparty_root}/PCAN_Basic/Include")
135143
set_property(TARGET LinkerHand::linkerhand_cpp_sdk APPEND PROPERTY
136144
INTERFACE_INCLUDE_DIRECTORIES "${_lh_thirdparty_root}/PCAN_Basic/Include")
137145
endif()
138-
elseif(UNIX AND EXISTS "${_lh_thirdparty_root}/libcanbus/include/linux")
146+
if(LINKERHAND_USE_CANFD AND EXISTS "${_lh_thirdparty_root}/libcanbus/include/windows")
147+
set_property(TARGET LinkerHand::linkerhand_cpp_sdk APPEND PROPERTY
148+
INTERFACE_INCLUDE_DIRECTORIES "${_lh_thirdparty_root}/libcanbus/include/windows")
149+
endif()
150+
elseif(UNIX AND LINKERHAND_USE_CANFD AND EXISTS "${_lh_thirdparty_root}/libcanbus/include/linux")
139151
set_property(TARGET LinkerHand::linkerhand_cpp_sdk APPEND PROPERTY
140152
INTERFACE_INCLUDE_DIRECTORIES "${_lh_thirdparty_root}/libcanbus/include/linux")
141153
endif()

0 commit comments

Comments
 (0)