Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 41 additions & 1 deletion .script/build-rmcs-cross
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,15 +7,17 @@ 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
EOF
}

target_arch=""
link_default=0
colcon_args=()

while (($# > 0)); do
Expand All@@ -33,6 +35,10 @@ while (($# > 0)); do
target_arch="${1#*=}"
shift
;;
--link-default)
link_default=1
shift
;;
-h | --help)
usage
exit 0
Expand DownExpand Up@@ -150,6 +156,30 @@ 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 +193,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
1 change: 1 addition & 0 deletions .script/complete/_build-rmcs-cross
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff 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
Loading