From 6a635cffd9efbcf242fefbe05833c3940168a4f9 Mon Sep 17 00:00:00 2001 From: ohh Date: Tue, 16 Jun 2026 11:28:50 +0800 Subject: [PATCH] =?UTF-8?q?build:=20=E7=BC=A9=E5=B0=8F=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E4=BA=8C=E8=BF=9B=E5=88=B6=E5=B9=B6=E5=88=86=E7=A6=BB=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E7=AC=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 链接时加 --gc-sections + 段切分,丢掉静态链入的 iceoryx/CycloneDDS 中未引用的代码;Release 默认 -Os。x86_64 发布版 bin 从 ~4.0MB 降到 ~2.25MB(约 -44%),-g 保留。 release.yml 在打包时用 objcopy 把 .debug 符号分离出来:发布的 bin strip 后通过 --add-gnu-debuglink 关联符号档,符号包只作为 CI artifact 上传、不挂公开 Release。 gitignore 补上 per-arch 安装前缀(yaml-cpp-*/、iceoryx-*/)。 --- .github/workflows/release.yml | 32 +++++++++++++++++++++++++++----- .gitignore | 4 +++- CMakeLists.txt | 10 ++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d51ed11..625c151 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,16 +42,26 @@ jobs: run: | VERSION=${GITHUB_REF#refs/tags/v} PKG_NAME="cddsctl-${VERSION}-linux-x86_64" + BIN=build/cli/cddsctl + # Split debug info: ship a stripped bin, keep symbols separately. + objcopy --only-keep-debug "$BIN" cddsctl.debug + objcopy --strip-debug --strip-unneeded "$BIN" + objcopy --add-gnu-debuglink=cddsctl.debug "$BIN" mkdir -p ${PKG_NAME}/bin - cp build/cli/cddsctl ${PKG_NAME}/bin/ + cp "$BIN" ${PKG_NAME}/bin/ tar -czvf ${PKG_NAME}.tar.gz ${PKG_NAME} + mkdir -p ${PKG_NAME}-debug + cp cddsctl.debug ${PKG_NAME}-debug/ + tar -czvf ${PKG_NAME}.debug.tar.gz ${PKG_NAME}-debug echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_ENV - name: Upload artifact uses: actions/upload-artifact@v4 with: name: ${{ env.PKG_NAME }} - path: ${{ env.PKG_NAME }}.tar.gz + path: | + ${{ env.PKG_NAME }}.tar.gz + ${{ env.PKG_NAME }}.debug.tar.gz build-aarch64: name: Build Release (aarch64) @@ -86,16 +96,26 @@ jobs: run: | VERSION=${GITHUB_REF#refs/tags/v} PKG_NAME="cddsctl-${VERSION}-linux-aarch64" + BIN=build/cli/cddsctl + # Split debug info: ship a stripped bin, keep symbols separately. + objcopy --only-keep-debug "$BIN" cddsctl.debug + objcopy --strip-debug --strip-unneeded "$BIN" + objcopy --add-gnu-debuglink=cddsctl.debug "$BIN" mkdir -p ${PKG_NAME}/bin - cp build/cli/cddsctl ${PKG_NAME}/bin/ + cp "$BIN" ${PKG_NAME}/bin/ tar -czvf ${PKG_NAME}.tar.gz ${PKG_NAME} + mkdir -p ${PKG_NAME}-debug + cp cddsctl.debug ${PKG_NAME}-debug/ + tar -czvf ${PKG_NAME}.debug.tar.gz ${PKG_NAME}-debug echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_ENV - name: Upload artifact uses: actions/upload-artifact@v4 with: name: ${{ env.PKG_NAME }} - path: ${{ env.PKG_NAME }}.tar.gz + path: | + ${{ env.PKG_NAME }}.tar.gz + ${{ env.PKG_NAME }}.debug.tar.gz release: name: Create Release @@ -158,7 +178,9 @@ jobs: - name: Create Release uses: softprops/action-gh-release@v2 with: - files: artifacts/*.tar.gz + files: | + artifacts/*.tar.gz + !artifacts/*.debug.tar.gz body_path: RELEASE_NOTES.md name: cddsctl ${{ github.ref_name }} env: diff --git a/.gitignore b/.gitignore index 64d1b00..1b26b35 100644 --- a/.gitignore +++ b/.gitignore @@ -43,9 +43,11 @@ # Build directory build/ -# 3rd_party generated directories +# 3rd_party generated directories (build trees + per-arch install prefixes) 3rd_party/yaml-cpp/ +3rd_party/yaml-cpp-*/ 3rd_party/iceoryx/ +3rd_party/iceoryx-*/ 3rd_party/cyclonedds-*/ 3rd_party/build/ diff --git a/CMakeLists.txt b/CMakeLists.txt index b4d6b1c..869b27e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,16 @@ message(STATUS "Target architecture: ${TARGET_ARCH_NAME}") # Debug symbols for all build types add_compile_options(-g) +# Let the linker drop unreferenced code from the statically-linked DDS stack +# (iceoryx/CycloneDDS), of which cddsctl uses only a fraction. +add_compile_options(-ffunction-sections -fdata-sections) +add_link_options(-Wl,--gc-sections) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() +add_compile_options($<$:-Os>) + # Use GNUInstallDirs for standard install paths include(GNUInstallDirs)