Skip to content

Commit 496f1c9

Browse files
authored
Merge pull request #4 from int0x7/feat/arm64-support
build: add ARM64 (aarch64) architecture support
2 parents 788314b + b47a6d9 commit 496f1c9

5 files changed

Lines changed: 188 additions & 20 deletions

File tree

.github/workflows/ci.yml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ on:
77
branches: [main, develop]
88

99
jobs:
10-
build:
10+
build-x86_64:
11+
name: Build (x86_64)
1112
runs-on: ubuntu-22.04
1213
container: ubuntu:20.04
1314
env:
@@ -27,7 +28,36 @@ jobs:
2728
uses: actions/cache@v4
2829
with:
2930
path: 3rd_party
30-
key: deps-${{ runner.os }}-iceoryx2.0.3-cyclonedds0.10.2
31+
key: deps-${{ runner.os }}-x86_64-iceoryx2.0.3-cyclonedds0.10.2
32+
33+
- name: Build dependencies
34+
run: ./scripts/build_deps.sh
35+
36+
- name: Build and Test
37+
run: ./build.sh -t -r
38+
39+
build-aarch64:
40+
name: Build (aarch64)
41+
runs-on: ubuntu-22.04-arm
42+
container: ubuntu:20.04
43+
env:
44+
DEBIAN_FRONTEND: noninteractive
45+
BUILD_TYPE: Release
46+
47+
steps:
48+
- name: Checkout
49+
uses: actions/checkout@v4
50+
51+
- name: Install dependencies
52+
run: |
53+
apt-get update
54+
apt-get install -y cmake g++ libacl1-dev git
55+
56+
- name: Cache dependencies
57+
uses: actions/cache@v4
58+
with:
59+
path: 3rd_party
60+
key: deps-${{ runner.os }}-aarch64-iceoryx2.0.3-cyclonedds0.10.2
3161

3262
- name: Build dependencies
3363
run: ./scripts/build_deps.sh

.github/workflows/release.yml

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ permissions:
99
contents: write
1010

1111
jobs:
12-
build:
12+
build-x86_64:
13+
name: Build Release (x86_64)
1314
runs-on: ubuntu-22.04
1415
container: ubuntu:20.04
1516
env:
@@ -28,7 +29,7 @@ jobs:
2829
uses: actions/cache@v4
2930
with:
3031
path: 3rd_party
31-
key: deps-${{ runner.os }}-cyclonedds0.10.2-shm
32+
key: deps-${{ runner.os }}-x86_64-cyclonedds0.10.2-shm
3233

3334
- name: Build
3435
run: |
@@ -52,12 +53,57 @@ jobs:
5253
name: ${{ env.PKG_NAME }}
5354
path: ${{ env.PKG_NAME }}.tar.gz
5455

56+
build-aarch64:
57+
name: Build Release (aarch64)
58+
runs-on: ubuntu-22.04-arm
59+
container: ubuntu:20.04
60+
env:
61+
DEBIAN_FRONTEND: noninteractive
62+
63+
steps:
64+
- name: Checkout
65+
uses: actions/checkout@v4
66+
67+
- name: Install dependencies
68+
run: |
69+
apt-get update
70+
apt-get install -y cmake g++ ninja-build libacl1-dev git
71+
72+
- name: Cache dependencies
73+
uses: actions/cache@v4
74+
with:
75+
path: 3rd_party
76+
key: deps-${{ runner.os }}-aarch64-cyclonedds0.10.2-shm
77+
78+
- name: Build
79+
run: |
80+
./build.sh -c
81+
82+
- name: Run tests
83+
run: ./build/tests/cddsctl_tests
84+
85+
- name: Package
86+
run: |
87+
VERSION=${GITHUB_REF#refs/tags/v}
88+
PKG_NAME="cddsctl-${VERSION}-linux-aarch64"
89+
mkdir -p ${PKG_NAME}/bin
90+
cp build/cli/cddsctl ${PKG_NAME}/bin/
91+
tar -czvf ${PKG_NAME}.tar.gz ${PKG_NAME}
92+
echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_ENV
93+
94+
- name: Upload artifact
95+
uses: actions/upload-artifact@v4
96+
with:
97+
name: ${{ env.PKG_NAME }}
98+
path: ${{ env.PKG_NAME }}.tar.gz
99+
55100
release:
101+
name: Create Release
56102
runs-on: ubuntu-22.04
57103
container: ubuntu:20.04
58104
env:
59105
DEBIAN_FRONTEND: noninteractive
60-
needs: build
106+
needs: [build-x86_64, build-aarch64]
61107

62108
steps:
63109
- name: Install dependencies
@@ -94,11 +140,18 @@ jobs:
94140
echo "" >> RELEASE_NOTES.md
95141
echo "## Installation" >> RELEASE_NOTES.md
96142
echo "" >> RELEASE_NOTES.md
143+
echo "### x86_64" >> RELEASE_NOTES.md
97144
echo "\`\`\`bash" >> RELEASE_NOTES.md
98145
echo "tar -xzf cddsctl-${VERSION}-linux-x86_64.tar.gz" >> RELEASE_NOTES.md
99146
echo "sudo mv cddsctl-${VERSION}-linux-x86_64/bin/cddsctl /usr/local/bin/" >> RELEASE_NOTES.md
100147
echo "\`\`\`" >> RELEASE_NOTES.md
101148
echo "" >> RELEASE_NOTES.md
149+
echo "### ARM64 (aarch64)" >> RELEASE_NOTES.md
150+
echo "\`\`\`bash" >> RELEASE_NOTES.md
151+
echo "tar -xzf cddsctl-${VERSION}-linux-aarch64.tar.gz" >> RELEASE_NOTES.md
152+
echo "sudo mv cddsctl-${VERSION}-linux-aarch64/bin/cddsctl /usr/local/bin/" >> RELEASE_NOTES.md
153+
echo "\`\`\`" >> RELEASE_NOTES.md
154+
echo "" >> RELEASE_NOTES.md
102155
echo "Built with CycloneDDS 0.10.2 and iceoryx 2.0.5 (shared memory)." >> RELEASE_NOTES.md
103156
echo "SHM is used automatically when a compatible RouDi daemon is running; otherwise falls back to UDP." >> RELEASE_NOTES.md
104157

CMakeLists.txt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ set(CMAKE_CXX_STANDARD 17)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
66
set(CMAKE_CXX_EXTENSIONS OFF)
77

8+
# Detect target architecture
9+
if(CMAKE_SYSTEM_PROCESSOR)
10+
set(TARGET_ARCH "${CMAKE_SYSTEM_PROCESSOR}")
11+
else()
12+
execute_process(COMMAND uname -m OUTPUT_VARIABLE TARGET_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
13+
endif()
14+
15+
# Normalize architecture names
16+
if(TARGET_ARCH MATCHES "^(x86_64|amd64)$")
17+
set(TARGET_ARCH_NAME "x86_64")
18+
elseif(TARGET_ARCH MATCHES "^(aarch64|arm64)$")
19+
set(TARGET_ARCH_NAME "aarch64")
20+
else()
21+
set(TARGET_ARCH_NAME "${TARGET_ARCH}")
22+
endif()
23+
24+
message(STATUS "Target architecture: ${TARGET_ARCH_NAME}")
25+
826
# Debug symbols for all build types
927
add_compile_options(-g)
1028

@@ -28,11 +46,11 @@ foreach(LINE ${VERSION_LINES})
2846
endif()
2947
endforeach()
3048

31-
# Third-party library paths
32-
set(YAMLCPP_DIR ${CDDSCTL_3RD_PARTY}/yaml-cpp)
33-
set(ICEORYX_DIR ${CDDSCTL_3RD_PARTY}/iceoryx)
34-
set(CYCLONEDDS_DIR ${CDDSCTL_3RD_PARTY}/cyclonedds-${CYCLONEDDS_VERSION})
35-
set(CYCLONEDDS_CXX_DIR ${CDDSCTL_3RD_PARTY}/cyclonedds-cxx-${CYCLONEDDS_VERSION})
49+
# Third-party library paths (architecture-specific)
50+
set(YAMLCPP_DIR ${CDDSCTL_3RD_PARTY}/yaml-cpp-${TARGET_ARCH_NAME})
51+
set(ICEORYX_DIR ${CDDSCTL_3RD_PARTY}/iceoryx-${TARGET_ARCH_NAME})
52+
set(CYCLONEDDS_DIR ${CDDSCTL_3RD_PARTY}/cyclonedds-${CYCLONEDDS_VERSION}-${TARGET_ARCH_NAME})
53+
set(CYCLONEDDS_CXX_DIR ${CDDSCTL_3RD_PARTY}/cyclonedds-cxx-${CYCLONEDDS_VERSION}-${TARGET_ARCH_NAME})
3654
list(APPEND CMAKE_PREFIX_PATH ${YAMLCPP_DIR} ${ICEORYX_DIR} ${CYCLONEDDS_DIR} ${CYCLONEDDS_CXX_DIR})
3755

3856
# CycloneDDS depends on iceoryx, need to find iceoryx targets first (static libs)
@@ -86,6 +104,7 @@ message(STATUS "========================================")
86104
message(STATUS "cddsctl Configuration")
87105
message(STATUS "========================================")
88106
message(STATUS "Version: ${PROJECT_VERSION}")
107+
message(STATUS "Architecture: ${TARGET_ARCH_NAME}")
89108
message(STATUS "Build Examples: ${BUILD_EXAMPLES}")
90109
message(STATUS "========================================")
91110
message(STATUS "")

build.sh

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,21 @@ else
1515
exit 1
1616
fi
1717

18-
# 默认并行数
18+
# Detect architecture
19+
ARCH=$(uname -m)
20+
case "${ARCH}" in
21+
x86_64)
22+
ARCH_NAME="x86_64"
23+
;;
24+
aarch64|arm64)
25+
ARCH_NAME="aarch64"
26+
;;
27+
*)
28+
ARCH_NAME="${ARCH}"
29+
;;
30+
esac
31+
32+
# Default parallel jobs
1933
JOBS=$(nproc 2>/dev/null || echo 4)
2034

2135
usage() {
@@ -76,25 +90,31 @@ while [[ $# -gt 0 ]]; do
7690
esac
7791
done
7892

93+
# Architecture-specific dependency paths
94+
ICEORYX_PREFIX="${THIRD_PARTY}/iceoryx-${ARCH_NAME}"
95+
CYCLONEDDS_PREFIX="${THIRD_PARTY}/cyclonedds-${CYCLONEDDS_VERSION}-${ARCH_NAME}"
96+
CYCLONEDDS_CXX_PREFIX="${THIRD_PARTY}/cyclonedds-cxx-${CYCLONEDDS_VERSION}-${ARCH_NAME}"
97+
YAMLCPP_PREFIX="${THIRD_PARTY}/yaml-cpp-${ARCH_NAME}"
98+
7999
# Check if dependencies exist
80100
YAMLCPP_OK=0
81101
ICEORYX_OK=0
82102
CYCLONEDDS_OK=0
83103
CYCLONEDDS_CXX_OK=0
84104

85-
if [[ -f "${THIRD_PARTY}/yaml-cpp/lib/libyaml-cpp.a" ]]; then
105+
if [[ -f "${YAMLCPP_PREFIX}/lib/libyaml-cpp.a" ]]; then
86106
YAMLCPP_OK=1
87107
fi
88108

89-
if [[ -f "${THIRD_PARTY}/iceoryx/lib/libiceoryx_posh.a" ]]; then
109+
if [[ -f "${ICEORYX_PREFIX}/lib/libiceoryx_posh.a" ]]; then
90110
ICEORYX_OK=1
91111
fi
92112

93-
if [[ -f "${THIRD_PARTY}/cyclonedds-${CYCLONEDDS_VERSION}/lib/libddsc.a" ]]; then
113+
if [[ -f "${CYCLONEDDS_PREFIX}/lib/libddsc.a" ]]; then
94114
CYCLONEDDS_OK=1
95115
fi
96116

97-
if [[ -f "${THIRD_PARTY}/cyclonedds-cxx-${CYCLONEDDS_VERSION}/lib/libddscxx.a" ]]; then
117+
if [[ -f "${CYCLONEDDS_CXX_PREFIX}/lib/libddscxx.a" ]]; then
98118
CYCLONEDDS_CXX_OK=1
99119
fi
100120

@@ -136,6 +156,7 @@ echo "==> Building with ${JOBS} jobs..."
136156
cmake --build "${BUILD_DIR}" -j "${JOBS}"
137157

138158
echo "==> Build complete!"
159+
echo " Architecture: ${ARCH_NAME}"
139160
echo " CLI: ${BUILD_DIR}/cli/cddsctl"
140161

141162
if [[ $RUN_TESTS -eq 1 ]]; then

scripts/build_deps.sh

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@ THIRD_PARTY="${PROJECT_ROOT}/3rd_party"
1010
BUILD_DIR="${THIRD_PARTY}/build"
1111
JOBS=$(nproc 2>/dev/null || echo 4)
1212

13+
# Detect architecture
14+
ARCH=$(uname -m)
15+
case "${ARCH}" in
16+
x86_64)
17+
ARCH_NAME="x86_64"
18+
;;
19+
aarch64|arm64)
20+
ARCH_NAME="aarch64"
21+
;;
22+
*)
23+
echo "Warning: Unsupported architecture '${ARCH}', defaulting to ${ARCH}"
24+
ARCH_NAME="${ARCH}"
25+
;;
26+
esac
27+
28+
# Cross-compilation support
29+
CROSS_COMPILE=0
30+
CROSS_ARCH=""
31+
1332
# Load versions from .versions file
1433
VERSIONS_FILE="${PROJECT_ROOT}/.versions"
1534
if [[ -f "${VERSIONS_FILE}" ]]; then
@@ -19,18 +38,19 @@ else
1938
exit 1
2039
fi
2140

22-
# Install prefixes
23-
ICEORYX_PREFIX="${THIRD_PARTY}/iceoryx"
24-
CYCLONEDDS_PREFIX="${THIRD_PARTY}/cyclonedds-${CYCLONEDDS_VERSION}"
25-
CYCLONEDDS_CXX_PREFIX="${THIRD_PARTY}/cyclonedds-cxx-${CYCLONEDDS_VERSION}"
26-
YAMLCPP_PREFIX="${THIRD_PARTY}/yaml-cpp"
41+
# Install prefixes (architecture-specific)
42+
ICEORYX_PREFIX="${THIRD_PARTY}/iceoryx-${ARCH_NAME}"
43+
CYCLONEDDS_PREFIX="${THIRD_PARTY}/cyclonedds-${CYCLONEDDS_VERSION}-${ARCH_NAME}"
44+
CYCLONEDDS_CXX_PREFIX="${THIRD_PARTY}/cyclonedds-cxx-${CYCLONEDDS_VERSION}-${ARCH_NAME}"
45+
YAMLCPP_PREFIX="${THIRD_PARTY}/yaml-cpp-${ARCH_NAME}"
2746

2847
usage() {
2948
echo "Usage: $0 [OPTIONS]"
3049
echo ""
3150
echo "Options:"
3251
echo " -c, --clean Clean build (remove build directory first)"
3352
echo " -j N Number of parallel jobs (default: $JOBS)"
53+
echo " --arch ARCH Target architecture for cross-compilation (x86_64, aarch64)"
3454
echo " -h, --help Show this help"
3555
}
3656

@@ -46,6 +66,27 @@ while [[ $# -gt 0 ]]; do
4666
JOBS="$2"
4767
shift 2
4868
;;
69+
--arch)
70+
CROSS_ARCH="$2"
71+
CROSS_COMPILE=1
72+
case "${CROSS_ARCH}" in
73+
x86_64|aarch64)
74+
ARCH_NAME="${CROSS_ARCH}"
75+
echo "==> Cross-compiling for ${ARCH_NAME}"
76+
;;
77+
*)
78+
echo "Error: Unsupported architecture '${CROSS_ARCH}'"
79+
echo "Supported architectures: x86_64, aarch64"
80+
exit 1
81+
;;
82+
esac
83+
# Update prefixes with new architecture
84+
ICEORYX_PREFIX="${THIRD_PARTY}/iceoryx-${ARCH_NAME}"
85+
CYCLONEDDS_PREFIX="${THIRD_PARTY}/cyclonedds-${CYCLONEDDS_VERSION}-${ARCH_NAME}"
86+
CYCLONEDDS_CXX_PREFIX="${THIRD_PARTY}/cyclonedds-cxx-${CYCLONEDDS_VERSION}-${ARCH_NAME}"
87+
YAMLCPP_PREFIX="${THIRD_PARTY}/yaml-cpp-${ARCH_NAME}"
88+
shift 2
89+
;;
4990
-h|--help)
5091
usage
5192
exit 0
@@ -189,6 +230,10 @@ echo ""
189230
echo "========================================="
190231
echo "Dependencies built successfully!"
191232
echo "========================================="
233+
echo "Architecture: ${ARCH_NAME}"
234+
if [[ ${CROSS_COMPILE} -eq 1 ]]; then
235+
echo "Build type: Cross-compiled"
236+
fi
192237
echo "yaml-cpp: ${YAMLCPP_PREFIX}"
193238
echo "iceoryx: ${ICEORYX_PREFIX}"
194239
echo "CycloneDDS: ${CYCLONEDDS_PREFIX}"

0 commit comments

Comments
 (0)