Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit ea2fdc05e454f6fb0d7e5468e0f40b9497c6a0b0
Author: urob <[email protected]>
Date:   Mon Jul 31 10:56:02 2023 -0400

    Multithreading support for docker/podman

commit 9da06f8f5c97da66a6be83bbaa144f60759a9b89
Merge: c21715b c7e299e
Author: urob <[email protected]>
Date:   Tue Jun 27 16:53:15 2023 -0400

    Merge remote-tracking branch 'ffnf/main' into parallel

commit c7e299e
Author: ffnf <[email protected]>
Date:   Sat May 13 18:59:27 2023 +0700

    Add multithreading when running locally

    Run it by using the `-m` option.
    It can only run locally, so the `-l` option must be included. Therefore, it should be `-l -m`

Co-authored-by: ffnf <[email protected]>
  • Loading branch information
urob and ffnf committed Jul 31, 2023
1 parent d8421c6 commit 4fbcfb1
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions scripts/zmk_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ while [[ $# -gt 0 ]]; do
RUNWITH_DOCKER="false"
;;

-m|--multithread)
MULTITHREAD="true"
;;

-c|--clear-cache)
CLEAR_CACHE="true"
;;
Expand Down Expand Up @@ -128,7 +132,8 @@ fi
if [[ $RUNWITH_DOCKER = true ]]
then
echo "Build mode: docker"
DOCKER_CMD="$DOCKER_BIN run --name zmk-$ZEPHYR_VERSION --rm \
# DOCKER_CMD="$DOCKER_BIN run --name zmk-$ZEPHYR_VERSION --rm \
DOCKER_CMD="$DOCKER_BIN run --rm \
--mount type=bind,source=$HOST_ZMK_DIR,target=$DOCKER_ZMK_DIR \
--mount type=bind,source=$HOST_CONFIG_DIR,target=$DOCKER_CONFIG_DIR,readonly \
--mount type=volume,source=zmk-root-user-$ZEPHYR_VERSION,target=/root \
Expand Down Expand Up @@ -165,15 +170,15 @@ fi

# usage: compile_board board
compile_board () {
echo -en "\n$(tput setaf 2)Building $1... $(tput sgr0)"
BUILD_DIR="${1}_$SUFFIX"
LOGFILE="$LOG_DIR/zmk_build_$1.log"
[[ $MULTITHREAD = "true" ]] || echo -en "\n$(tput setaf 2)Building $1... $(tput sgr0)"
[[ $MULTITHREAD = "true" ]] && echo -e "$(tput setaf 2)Building $1... $(tput sgr0)"
$DOCKER_PREFIX west build -d "build/$BUILD_DIR" -b $1 $WEST_OPTS \
-- -DZMK_CONFIG="$CONFIG_DIR" -Wno-dev > "$LOGFILE" 2>&1
if [[ $? -eq 0 ]]
then
# echo "$(tput setaf 4)Success: $1 done$(tput sgr0)"
echo "$(tput setaf 2)done$(tput sgr0)"
[[ $MULTITHREAD = "true" ]] || echo "$(tput setaf 2)done$(tput sgr0)"
echo "Build log saved to \"$LOGFILE\"."
if [[ -f $HOST_ZMK_DIR/app/build/$BUILD_DIR/zephyr/zmk.uf2 ]]
then
Expand All @@ -192,8 +197,27 @@ compile_board () {
}

cd "$HOST_ZMK_DIR/app"
for board in $(echo $BOARDS | sed 's/,/ /g')
do
compile_board $board
done

if [[ $MULTITHREAD = "true" ]]; then
i=1
for board in $(echo $BOARDS | sed 's/,/ /g')
do
compile_board $board &
eval "T${i}=\${!}"
eval "B${i}=\$board" # Store the board name in a corresponding variable
((i++))
done

echo "Starting $(($i - 1)) background threads:"
for ((x=1; x<i; x++))
do
pid="T$x"
wait "${!pid}"
board="B$x" # Retrieve the board name from the corresponding variable
echo -e "$(tput setaf 3)Thread $x with PID ${!pid} has finished: ${!board}$(tput sgr0)"
done
else
for board in $(echo $BOARDS | sed 's/,/ /g')
do
compile_board $board
done
fi

0 comments on commit 4fbcfb1

Please sign in to comment.