Skip to content

Commit 6f61c58

Browse files
committed
feat(devctr): add checkbuild command to cargo-check specific arch
Add a new checkbuild command to the devtool so that contributors can run cargo-check against all supported architectures. There is currently no easy way to check compilation against a different architectures. This causes unnecessary back and forth in reviews where the contributor has no easy access to the other architecture. Signed-off-by: Riccardo Mancini <[email protected]>
1 parent bccb658 commit 6f61c58

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

.github/pull_request_template.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Certificate of Origin and signing off your commits, please check
1616
## PR Checklist
1717

1818
- [ ] I have read and understand [CONTRIBUTING.md][3].
19+
- [ ] I have run `tools/devtool checkbuild --all` to verify that the PR passes
20+
build checks on all supported architectures.
1921
- [ ] I have run `tools/devtool checkstyle` to verify that the PR passes the
2022
automated style checks.
2123
- [ ] I have described what is done in these changes, why they are needed, and

tools/devtool

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ cmd_help() {
427427
428428
checkstyle
429429
Run style checks
430+
431+
checkbuild [--all|-m x86_64|aarch64] [-v|--verbose]
432+
Run cargo check on the target architecture (supports cross compilation).
430433
EOF
431434
}
432435

@@ -959,6 +962,56 @@ cmd_checkstyle() {
959962
cmd_test --no-build --no-kvm-check -- -n 4 --doctest-modules framework || exit 1
960963
}
961964

965+
cmd_checkbuild() {
966+
TARGET_ARCH=$(uname -m)
967+
968+
declare -A PACKAGES=(
969+
[x86_64]="gcc-x86-64-linux-gnu g++-x86-64-linux-gnu libc6-dev-amd64-cross linux-libc-dev-amd64-cross"
970+
[aarch64]="gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross linux-libc-dev-arm64-cross"
971+
)
972+
APT_QUIET="-qq > /dev/null"
973+
974+
while [ $# -gt 0 ]; do
975+
case "$1" in
976+
"-h"|"--help") { cmd_help; exit 1; } ;;
977+
"-v"|"--verbose") { APT_QUIET=""; } ;;
978+
"-m"|"--arch") { TARGET_ARCH=$2; shift; } ;;
979+
"--all") {
980+
shift
981+
for arch in ${!PACKAGES[@]}; do
982+
say "Running checkbuild -m $arch $@"
983+
cmd_checkbuild -m $arch $@ || return $?
984+
done
985+
}
986+
say "Build check passed for ${!PACKAGES[@]}"
987+
return 0
988+
;;
989+
*)
990+
die "Unknown argument: $1. Please use --help for help."
991+
;;
992+
esac
993+
shift
994+
done
995+
996+
if [[ ! -v PACKAGES[$TARGET_ARCH] ]]; then
997+
die "Unknown architecture: $TARGET_ARCH. Supported architectures: ${!PACKAGES[@]}"
998+
fi
999+
1000+
# Use GNU target to check build as musl has issues with cross-compilation
1001+
CARGO_TARGET="${TARGET_ARCH}-unknown-linux-gnu"
1002+
CMD="cargo check --target $CARGO_TARGET --all && \
1003+
cargo clippy --target $CARGO_TARGET --all --profile test -- -D warnings"
1004+
if [ $TARGET_ARCH != $(uname -m) ]; then
1005+
CMD="export DEBIAN_FRONTEND=noninteractive && \
1006+
apt update $APT_QUIET && \
1007+
apt install -y ${PACKAGES[$TARGET_ARCH]} $APT_QUIET && \
1008+
rustup target add $CARGO_TARGET && \
1009+
$CMD"
1010+
fi
1011+
cmd_sh "$CMD" || die "Error running build checks for $TARGET_ARCH"
1012+
say "Build check passed for $TARGET_ARCH"
1013+
}
1014+
9621015
# Check if able to run firecracker.
9631016
# ../docs/getting-started.md#prerequisites
9641017
ensure_kvm_rw () {

0 commit comments

Comments
 (0)