@@ -139,8 +139,8 @@ say_noln() {
139139#
140140say_err () {
141141 [ -t 2 ] && [ -n " $TERM " ] \
142- && echo " $( tput setaf 1) [$MY_NAME ] $* $( tput sgr0) " 1>&2 \
143- || echo " [$MY_NAME ] $* " 1>&2
142+ && echo -e " $( tput setaf 1) [$MY_NAME ] $* $( tput sgr0) " 1>&2 \
143+ || echo -e " [$MY_NAME ] $* " 1>&2
144144}
145145
146146# Send a warning-highlighted text to stdout
@@ -234,6 +234,19 @@ ensure_build_dir() {
234234 done
235235}
236236
237+ # Makes sure that Firecracker release binaries were built.
238+ # This is relevant in the context of stripping the already built release binaries.
239+ ensure_release_binaries_exist () {
240+ target=$1
241+ profile=$2
242+ firecracker_bin_path=" $CARGO_TARGET_DIR /$target /$profile /firecracker"
243+ jailer_bin_path=" $CARGO_TARGET_DIR /$target /$profile /jailer"
244+
245+ # Both binaries must exist for the stripping to be succesgitsful.
246+ [ -f $firecracker_bin_path ] && [ -f $jailer_bin_path ] || \
247+ die " Missing release binaries. Needed files:\n* $firecracker_bin_path \n* $jailer_bin_path ."
248+ }
249+
237250# Fix build/ dir permissions after a privileged container run.
238251# Since the privileged cotainer runs as root, any files it creates will be
239252# owned by root. This fixes that by recursively changing the ownership of build/
@@ -385,6 +398,15 @@ cmd_help() {
385398 echo " -l, --libc musl|gnu Choose the libc flavor against which Firecracker will"
386399 echo " be linked. Default is musl."
387400 echo " "
401+ echo " strip [--target-libc musl|gnu]"
402+ echo " Strip debug symbols from the Firecracker release binaries."
403+ echo " "
404+ echo " --target-libc musl|gnu Choose the target libc flavor which determines the"
405+ echo " toolchain used to build Firecracker release binaries."
406+ echo " Stripping will occur only for the Firecracker release"
407+ echo " binaries corresponding to the inferred toolchain. Default"
408+ echo " is musl."
409+ echo " "
388410 echo " fmt"
389411 echo " Auto-format all Rust source files, to match the Firecracker requirements."
390412 echo " This should be used as the last step in every commit, to ensure that the"
@@ -504,6 +526,55 @@ cmd_build() {
504526 return $ret
505527}
506528
529+ cmd_strip () {
530+ profile=" release"
531+ libc=" musl"
532+ target=" $( uname -m) -unknown-linux-${libc} "
533+
534+ # Parse any command line args.
535+ while [ $# -gt 0 ]; do
536+ case " $1 " in
537+ " -h" |" --help" ) { cmd_help; exit 1; } ;;
538+ " --target-libc" )
539+ shift
540+ [[ " $1 " =~ ^(musl| gnu)$ ]] || \
541+ die " Invalid libc: $1 . Valid options are \" musl\" and \" gnu\" ."
542+ libc=" $1 "
543+ target=" $( uname -m) -unknown-linux-${libc} "
544+ ;;
545+ * )
546+ die " Unknown argument: $1 . Please use --help for help."
547+ ;;
548+ esac
549+ shift
550+ done
551+
552+ # Check prerequisites
553+ ensure_devctr
554+ ensure_build_dir
555+ ensure_release_binaries_exist $target $profile
556+
557+ say " Starting stripping the debug symbols for $profile binaries built against $target target."
558+ strip_flags=" --strip-debug"
559+ say " Strip flags: $strip_flags ."
560+
561+ run_devctr \
562+ --user " $( id -u) :$( id -g) " \
563+ -- \
564+ strip $strip_flags \
565+ " $CTR_CARGO_TARGET_DIR /$target /$profile /firecracker" \
566+ " $CTR_CARGO_TARGET_DIR /$target /$profile /jailer"
567+ ret=$?
568+
569+ [ $ret -eq 0 ] && {
570+ cargo_bin_dir=" $CARGO_TARGET_DIR /$target /$profile "
571+ say " Stripping was successful."
572+ say " Stripped binaries placed under $cargo_bin_dir ."
573+ }
574+
575+ return $ret
576+ }
577+
507578# `$0 test` - run integration tests
508579# Please see `$0 help` for more information.
509580#
0 commit comments