Skip to content

Commit d5ec9e9

Browse files
committed
scripts: Add aarch64 support to containerized build
This commit adds aarch64 support to containerized build and test. The integration tests are not yet supported for aarch64. Signed-off-by: Akira Moroo <[email protected]>
1 parent 7c62ee1 commit d5ec9e9

File tree

2 files changed

+49
-11
lines changed

2 files changed

+49
-11
lines changed

scripts/dev_cli.sh

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ cmd_help() {
233233
}
234234

235235
cmd_build() {
236+
arch="$(uname -m)"
236237
build="debug"
237238
features_build=""
238239
exported_device="dev/kvm"
@@ -258,20 +259,22 @@ cmd_build() {
258259

259260
process_volumes_args
260261

262+
[ "$arch" = "aarch64" ] && target="aarch64-unknown-none.json"
263+
[ "$arch" = "x86_64" ] && target="x86_64-unknown-none.json"
264+
261265
cargo_args=("$@")
262266
[ $build = "release" ] && cargo_args+=("--release")
263267

264268
rustflags=""
265269

266270
$DOCKER_RUNTIME run \
267-
--user "$(id -u):$(id -g)" \
268271
--workdir "$CTR_RHF_ROOT_DIR" \
269272
--rm \
270273
--volume $exported_device \
271274
--volume "$RHF_ROOT_DIR:$CTR_RHF_ROOT_DIR" $exported_volumes \
272275
--env RUSTFLAGS="$rustflags" \
273276
"$CTR_IMAGE" \
274-
cargo build --target "x86_64-unknown-none.json" \
277+
cargo build --target "$target" \
275278
-Zbuild-std=core,alloc \
276279
-Zbuild-std-features=compiler-builtins-mem \
277280
--target-dir "$CTR_RHF_CARGO_TARGET" \
@@ -285,7 +288,6 @@ cmd_clean() {
285288
ensure_latest_ctr
286289

287290
$DOCKER_RUNTIME run \
288-
--user "$(id -u):$(id -g)" \
289291
--workdir "$CTR_RHF_ROOT_DIR" \
290292
--rm \
291293
--volume "$RHF_ROOT_DIR:$CTR_RHF_ROOT_DIR" $exported_volumes \
@@ -296,6 +298,7 @@ cmd_clean() {
296298
}
297299

298300
cmd_tests() {
301+
arch="$(uname -m)"
299302
unit=false
300303
cargo=false
301304
integration=false
@@ -315,7 +318,7 @@ cmd_tests() {
315318
shift
316319
arg_vols="$1"
317320
;;
318-
"--all") { cargo=true; unit=true; integration=true; } ;;
321+
"--all") { cargo=true; unit=true; [ "$arch" = "x86_64" ] && integration=true; } ;;
319322
"--") { shift; break; } ;;
320323
*)
321324
die "Unknown tests argument: $1. Please use --help for help."
@@ -324,6 +327,18 @@ cmd_tests() {
324327
shift
325328
done
326329

330+
if [ "$(uname -m)" = "aarch64" ] ; then
331+
if [ "$integration" = true ] ; then
332+
die "Integration test is not supported for aarch64."
333+
fi
334+
if [ "$integration_coreboot" = true ] ; then
335+
die "coreboot integration test is not supported for aarch64."
336+
fi
337+
if [ "$integration_windows" = true ] ; then
338+
die "Windows integration test is not supported for aarch64."
339+
fi
340+
fi
341+
327342
ensure_build_dir
328343
ensure_latest_ctr
329344

@@ -409,6 +424,8 @@ cmd_tests() {
409424

410425

411426
cmd_build-container() {
427+
arch="$(uname -m)"
428+
412429
while [ $# -gt 0 ]; do
413430
case "$1" in
414431
"-h"|"--help") { cmd_help; exit 1; } ;;
@@ -427,7 +444,8 @@ cmd_build-container() {
427444
mkdir -p $BUILD_DIR
428445
cp $RHF_DOCKERFILE $BUILD_DIR
429446

430-
[ $(uname -m) = "x86_64" ] && TARGETARCH="amd64"
447+
[ "$arch" = "aarch64" ] && TARGETARCH="arm64"
448+
[ "$arch" = "x86_64" ] && TARGETARCH="amd64"
431449
RUST_TOOLCHAIN="$(rustup show active-toolchain | cut -d ' ' -f1)"
432450

433451
$DOCKER_RUNTIME build \

scripts/run_cargo_tests.sh

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,37 @@ source "${CARGO_HOME:-$HOME/.cargo}/env"
66

77
export RUSTFLAGS="-D warnings"
88

9+
arch="$(uname -m)"
10+
11+
do_cargo_tests() {
12+
local cargo_args=("-Zbuild-std=core,alloc" "-Zbuild-std-features=compiler-builtins-mem")
13+
local cmd="$1"
14+
local target="$2"
15+
local features="$3"
16+
[ -n "$features" ] && cargo_args+=("--features" "$features")
17+
time cargo "$cmd" --target "$target" "${cargo_args[@]}"
18+
time cargo "$cmd" --target "$target" --release "${cargo_args[@]}"
19+
}
20+
21+
cargo_tests() {
22+
local features="$1"
23+
24+
[ "$arch" = "aarch64" ] && target="aarch64-unknown-none.json"
25+
[ "$arch" = "x86_64" ] && target="x86_64-unknown-none.json"
26+
27+
do_cargo_tests "build" "$target" "$features"
28+
do_cargo_tests "clippy" "$target" "$features"
29+
}
30+
931
# Install cargo components
1032
time rustup component add clippy
1133
time rustup component add rustfmt
1234
time rustup component add rust-src
1335

1436
# Run cargo builds and checks
15-
time cargo build --target x86_64-unknown-none.json -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem
16-
time cargo build --release --target x86_64-unknown-none.json -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem
17-
time cargo build --target x86_64-unknown-none.json --features "coreboot" -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem
18-
time cargo build --release --target x86_64-unknown-none.json --features "coreboot" -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem
19-
time cargo clippy --target x86_64-unknown-none.json -Zbuild-std=core,alloc
20-
time cargo clippy --target x86_64-unknown-none.json -Zbuild-std=core,alloc --features "coreboot"
37+
cargo_tests ""
38+
if [ "$arch" = "x86_64" ] ; then
39+
cargo_tests "coreboot"
40+
fi
2141
time cargo clippy --all-targets --all-features
2242
time cargo fmt --all -- --check

0 commit comments

Comments
 (0)