@@ -367,12 +367,14 @@ cmd_help() {
367
367
echo " "
368
368
echo " Available commands:"
369
369
echo " "
370
- echo " build [--debug|--release] [-- [<cargo args>]]"
370
+ echo " build [--debug|--release] [-l|--libc musl|gnu] [- - [<cargo args>]]"
371
371
echo " Build the Firecracker binaries."
372
372
echo " Firecracker is built using the Rust build system (cargo). All arguments after --"
373
373
echo " will be passed through to cargo."
374
- echo " --debug Build the debug binaries. This is the default."
375
- echo " --release Build the release binaries."
374
+ echo " --debug Build the debug binaries. This is the default."
375
+ echo " --release Build the release binaries."
376
+ echo " -l, --libc musl|gnu Choose the libc flavor against which Firecracker will"
377
+ echo " be linked. Default is musl."
376
378
echo " "
377
379
echo " fmt"
378
380
echo " Auto-format all Rust source files, to match the Firecracker requirements."
@@ -414,13 +416,20 @@ cmd_build() {
414
416
415
417
# By default, we'll build the debug binaries.
416
418
profile=" debug"
419
+ libc=" musl"
417
420
418
421
# Parse any command line args.
419
422
while [ $# -gt 0 ]; do
420
423
case " $1 " in
421
424
" -h" |" --help" ) { cmd_help; exit 1; } ;;
422
425
" --debug" ) { profile=" debug" ; } ;;
423
426
" --release" ) { profile=" release" ; } ;;
427
+ " -l" |" --libc" )
428
+ shift
429
+ [[ " $1 " =~ ^(musl| gnu)$ ]] || \
430
+ die " Invalid libc: $1 . Valid options are \" musl\" and \" gnu\" ."
431
+ libc=" $1 "
432
+ ;;
424
433
" --" ) { shift ; break ; } ;;
425
434
* )
426
435
die " Unknown argument: $1 . Please use --help for help."
@@ -429,39 +438,55 @@ cmd_build() {
429
438
shift
430
439
done
431
440
441
+ target=" $( uname -m) -unknown-linux-${libc} "
442
+
432
443
# Check prerequisites
433
444
ensure_devctr
434
445
ensure_build_dir
435
446
436
- say " Starting build ($profile ) ..."
447
+ say " Starting build ($profile , $libc ) ..."
437
448
438
449
# Cargo uses the debug profile by default. If we're building the release
439
450
# binaries, we need to pass an extra argument to cargo.
440
451
cargo_args=(" $@ " )
452
+
441
453
[ $profile = " release" ] && cargo_args+=(" --release" )
442
454
443
455
# Run the cargo build process inside the container.
444
456
# We don't need any special privileges for the build phase, so we run the
445
457
# container as the current user/group.
458
+ #
459
+ # Note: we need to pass an explicit TARGET_CC to cargo, because the `cc`
460
+ # crate gets confused for aarch64 musl.
446
461
run_devctr \
447
462
--user " $( id -u) :$( id -g) " \
448
463
--workdir " $CTR_FC_ROOT_DIR " \
464
+ --env TARGET_CC=musl-gcc \
449
465
-- \
450
466
cargo build \
451
- --target-dir " ${CTR_CARGO_TARGET_DIR} " \
467
+ --target-dir " $CTR_CARGO_TARGET_DIR " \
468
+ --target " $target " \
452
469
" ${cargo_args[@]} "
453
470
ret=$?
454
471
455
472
# If `cargo build` was successful, let's copy the binaries to a more
456
- # accessible location (under build/release or build/debug).
457
- if [ $ret -eq 0 ]; then
458
- mkdir -p " ${FC_BUILD_DIR} /${profile} "
459
- cp -f " ${CARGO_TARGET_DIR} /${profile} " /{firecracker,jailer} \
460
- " ${FC_BUILD_DIR} /${profile} /"
461
- ret=$?
462
- fi
463
- [ $ret -eq 0 ] && \
464
- say " Build complete. Binaries placed under ${FC_BUILD_DIR} /${profile} /"
473
+ # accessible location.
474
+ [ $ret -eq 0 ] && {
475
+ cargo_bin_dir=" $CARGO_TARGET_DIR /$target /$profile "
476
+ friendly_bin_dir=" $FC_BUILD_DIR /$profile -$libc "
477
+ say " Build successful."
478
+
479
+ mkdir -p " $friendly_bin_dir "
480
+ [ $? -eq 0 ] || {
481
+ say_warn " Unable to create dir $friendly_bin_dir ."
482
+ say_warn " Binaries placed under $cargo_bin_dir /"
483
+ return $ret
484
+ }
485
+ cp -f " $cargo_bin_dir " /{firecracker,jailer} " $friendly_bin_dir /"
486
+ say " Build complete."
487
+ say " Binaries placed under $friendly_bin_dir "
488
+ }
489
+
465
490
return $ret
466
491
}
467
492
0 commit comments