Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion .script/build-rmcs-cross
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ set -euo pipefail
usage() {
cat <<'EOF'
Usage:
build-rmcs-cross --target-arch <arm64|amd64> [colcon build args...]
build-rmcs-cross --target-arch <arm64|amd64> [--link-default] [colcon build args...]

Examples:
build-rmcs-cross --target-arch arm64
build-rmcs-cross --target-arch arm64 --link-default
build-rmcs-cross --target-arch amd64 --packages-up-to rmcs_executor

Notes:
arm64 cross builds automatically skip 'hikcamera' and 'rmcs_auto_aim_v2'.
EOF
}

target_arch=""
link_default=0
colcon_args=()
auto_skip_packages=()

while (($# > 0)); do
case "$1" in
Expand All @@ -33,6 +39,10 @@ while (($# > 0)); do
target_arch="${1#*=}"
shift
;;
--link-default)
link_default=1
shift
;;
-h | --help)
usage
exit 0
Expand All @@ -53,6 +63,7 @@ fi
case "${target_arch}" in
arm64)
target_triplet="aarch64-linux-gnu"
auto_skip_packages=(hikcamera rmcs_auto_aim_v2)
;;
amd64)
target_triplet="x86_64-linux-gnu"
Expand Down Expand Up @@ -146,10 +157,38 @@ export PKG_CONFIG_LIBDIR="${RMCS_SYSROOT}/usr/local/lib/${RMCS_TARGET_TRIPLET}/p

cd "${workspace}"

if ((${#auto_skip_packages[@]} > 0)); then
colcon_args+=(--packages-skip "${auto_skip_packages[@]}")
fi

build_base="build-cross-${RMCS_TARGET_ARCH}"
install_base="install-cross-${RMCS_TARGET_ARCH}"
log_base="log-cross-${RMCS_TARGET_ARCH}"

check_default_linkable() {
local target="$1"
local link_name="$2"

if [[ ! -d "${target}" ]]; then
echo "> ERROR: Cross build output not found: ${workspace}/${target}"
exit 1
fi

if [[ -e "${link_name}" && ! -L "${link_name}" ]]; then
echo "> ERROR: Cannot link ${workspace}/${link_name} -> ${target}."
echo "> ${workspace}/${link_name} exists and is not a symlink. Move or remove it first."
exit 1
fi
}

link_default_base() {
local target="$1"
local link_name="$2"

ln -sfnT "${target}" "${link_name}"
echo "> Linked ${workspace}/${link_name} -> ${target}"
}

CLICOLOR_FORCE=1 NINJA_STATUS="" \
colcon \
--log-base "${log_base}" \
Expand All @@ -163,3 +202,13 @@ CLICOLOR_FORCE=1 NINJA_STATUS="" \
-DRMCS_TARGET_ARCH="${RMCS_TARGET_ARCH}" \
-DRMCS_SYSROOT="${RMCS_SYSROOT}" \
-DRMCS_TARGET_TRIPLET="${RMCS_TARGET_TRIPLET}"

if ((link_default)); then
check_default_linkable "${build_base}" build
check_default_linkable "${install_base}" install
check_default_linkable "${log_base}" log

link_default_base "${build_base}" build
link_default_base "${install_base}" install
link_default_base "${log_base}" log
fi
8 changes: 7 additions & 1 deletion .script/clean-rmcs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ fi
rm -rf -- \
"${RMCS_PATH}/rmcs_ws/build" \
"${RMCS_PATH}/rmcs_ws/install" \
"${RMCS_PATH}/rmcs_ws/log"
"${RMCS_PATH}/rmcs_ws/log" \
"${RMCS_PATH}/rmcs_ws/build-cross-arm64" \
"${RMCS_PATH}/rmcs_ws/install-cross-arm64" \
"${RMCS_PATH}/rmcs_ws/log-cross-arm64" \
"${RMCS_PATH}/rmcs_ws/build-cross-amd64" \
"${RMCS_PATH}/rmcs_ws/install-cross-amd64" \
"${RMCS_PATH}/rmcs_ws/log-cross-amd64"
1 change: 1 addition & 0 deletions .script/complete/_build-rmcs-cross
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

_arguments \
'--target-arch=[Cross compile target architecture]:target:(arm64 amd64)' \
'--link-default[Link build/install/log to cross build output directories]' \
'*:colcon build args:'
28 changes: 26 additions & 2 deletions docs/zh-cn/cross_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,44 @@
build-rmcs-cross --target-arch arm64
```

适用于 `linux/amd64` 的 `latest-full` 变体。
适用于 `linux/arm64` 的 `latest-full` 变体。

```bash
build-rmcs-cross --target-arch amd64
```

适用于 `linux/arm64` 的 `latest-full` 变体。
适用于 `linux/amd64` 的 `latest-full` 变体。

例如,可追加常见 `colcon build` 参数:

```bash
build-rmcs-cross --target-arch arm64 --packages-up-to rmcs_executor
```

若需要让现有 `sync-remote`、`env_setup` 等继续使用默认目录,可在 cross 构建成功后自动链接默认目录:

```bash
build-rmcs-cross --target-arch arm64 --link-default
```

链接方向等价于在 `rmcs_ws` 下执行:

```bash
ln -sfn build-cross-arm64 build
ln -sfn install-cross-arm64 install
ln -sfn log-cross-arm64 log
```

也就是创建或更新默认目录名,让 `build`、`install`、`log` 这三个软链接分别指向对应的 `*-cross-arm64` 目录。

切回 native 构建时,直接运行:

```bash
build-rmcs
```

`build-rmcs` 会自动识别上述 cross 默认软链接,删除软链接并恢复成普通目录。

## 4. 构建环境隔离约束

`build-rmcs-cross` 会显式清理并重建以下环境,避免 host/target 串用:
Expand Down
1 change: 1 addition & 0 deletions rmcs_ws/src/hikcamera
Submodule hikcamera added at f0077f
1 change: 1 addition & 0 deletions rmcs_ws/src/rmcs_auto_aim_v2
Submodule rmcs_auto_aim_v2 added at c486ae
Loading