diff --git a/scripts/zmk_build.sh b/scripts/zmk_build.sh index 849f612..332f394 100755 --- a/scripts/zmk_build.sh +++ b/scripts/zmk_build.sh @@ -12,6 +12,10 @@ while [[ $# -gt 0 ]]; do RUNWITH_DOCKER="false" ;; + -m|--multithread) + MULTITHREAD="true" + ;; + -c|--clear-cache) CLEAR_CACHE="true" ;; @@ -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 \ @@ -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 @@ -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