run formatters
This commit is contained in:
parent
3aed3a0bd6
commit
c7107524a3
6 changed files with 304 additions and 296 deletions
|
@ -1,22 +1,23 @@
|
|||
This folder contains scripts that automate installing and building using a
|
||||
local toolchain. The scripts provide an alternative to using [Github
|
||||
Actions](https://zmk.dev/docs/user-setup#installing-the-firmware) and the
|
||||
[developer toolchain](https://zmk.dev/docs/development/setup).
|
||||
This folder contains scripts that automate installing and building using a local
|
||||
toolchain. The scripts provide an alternative to using
|
||||
[Github Actions](https://zmk.dev/docs/user-setup#installing-the-firmware) and
|
||||
the [developer toolchain](https://zmk.dev/docs/development/setup).
|
||||
|
||||
If the zmk-config repo contains a `combos.dtsi` file, the script will also automatically
|
||||
update the `MAX_COMBOS_PER_KEY` and `MAX_KEYS_PER_COMBO` settings for all boards,
|
||||
depending on the combos specified in `combos.dtsi`.
|
||||
If the zmk-config repo contains a `combos.dtsi` file, the script will also
|
||||
automatically update the `MAX_COMBOS_PER_KEY` and `MAX_KEYS_PER_COMBO` settings
|
||||
for all boards, depending on the combos specified in `combos.dtsi`.
|
||||
|
||||
## Build steps
|
||||
|
||||
### 1. Clone the ZMK repository
|
||||
|
||||
Clone the ZMK repository and checkout the branch that you want to build
|
||||
against. By default the build script will look for the ZMK repo in `~/zmk`.
|
||||
Other locations can be specified with `--host-zmk-dir` or by changing the
|
||||
default location for `HOST_ZMK_DIR` inside the script.
|
||||
Clone the ZMK repository and checkout the branch that you want to build against.
|
||||
By default the build script will look for the ZMK repo in `~/zmk`. Other
|
||||
locations can be specified with `--host-zmk-dir` or by changing the default
|
||||
location for `HOST_ZMK_DIR` inside the script.
|
||||
|
||||
For example, to build against my `main-3.2` branch, run:
|
||||
|
||||
```bash
|
||||
cd "$HOME"
|
||||
git clone https://github.com/urob/zmk
|
||||
|
@ -25,11 +26,12 @@ git checkout main-3.2
|
|||
|
||||
### 2. Clone your zmk-config repository
|
||||
|
||||
By default the build script will look for the zmk-config repo in
|
||||
`~/zmk-config`. Other locations can be specified with `--host-config-dir` or by
|
||||
changing the default location for `HOST_CONFIG_DIR` inside the script.
|
||||
By default the build script will look for the zmk-config repo in `~/zmk-config`.
|
||||
Other locations can be specified with `--host-config-dir` or by changing the
|
||||
default location for `HOST_CONFIG_DIR` inside the script.
|
||||
|
||||
For example, to use my zmk-config repo, run:
|
||||
|
||||
```bash
|
||||
cd "$HOME"
|
||||
git clone https://github.com/urob/zmk-config
|
||||
|
@ -41,47 +43,48 @@ The build script can be used to install either a "docker" or a "local"
|
|||
toolchain. If unsure, I recommend using the docker toolchain. Depending on your
|
||||
installation choice, do **one** of the following:
|
||||
|
||||
1. Install Docker or Podman (recommended) and, if using Podman, configure the docker
|
||||
registry. On Debian or Ubuntu, you can do both by running:
|
||||
1. Install Docker or Podman (recommended) and, if using Podman, configure the
|
||||
docker registry. On Debian or Ubuntu, you can do both by running:
|
||||
```bash
|
||||
sudo apt-get install podman
|
||||
echo 'unqualified-search-registries = ["docker.io"]' > $XDG_CONFIG_HOME/containers/registries.conf
|
||||
```
|
||||
2. Install a local [developer
|
||||
toolchain](https://zmk.dev/docs/development/setup). The
|
||||
2. Install a local
|
||||
[developer toolchain](https://zmk.dev/docs/development/setup). The
|
||||
`zmk_local_install.sh` script in this repository automates the process for
|
||||
Debian-based operating system.
|
||||
|
||||
### 4. Run the build script
|
||||
|
||||
Run the `zmk_build.sh` script to build your boards. By default, the script will
|
||||
build all boards specified in `build.yaml` in your `zmk-config` repo. The default can be
|
||||
overwritten with the `-b` option.
|
||||
build all boards specified in `build.yaml` in your `zmk-config` repo. The
|
||||
default can be overwritten with the `-b` option.
|
||||
|
||||
If using docker/podman, the script will pull down the required dependencies the first
|
||||
time it is used. The script will automatically detect whether the build
|
||||
requirement have changed, and will only re-download the dependencies if needed.
|
||||
If using docker/podman, the script will pull down the required dependencies the
|
||||
first time it is used. The script will automatically detect whether the build
|
||||
requirement have changed, and will only re-download the dependencies if needed.
|
||||
|
||||
In order to easily switch between multiple ZMK branches that have different
|
||||
build requirements, one can specify the desired Zephyr version using the `-v`
|
||||
option. Docker container and volumes are index by the Zephyr version, so
|
||||
switching between Zephyr version won't require re-downloading new dependencies.
|
||||
In order to force re-installing all build requirements, pass the `-c` option, which will
|
||||
wipe out the Docker container and volume.
|
||||
In order to force re-installing all build requirements, pass the `-c` option,
|
||||
which will wipe out the Docker container and volume.
|
||||
|
||||
By default the script will copy the firmware into the `OUTPUT_DIR` folder
|
||||
specified in the script. Other locations can be specified using the
|
||||
`--output-dir` argument.
|
||||
|
||||
To switch between Docker and Podman, set the `DOCKER_BIN` variable in the
|
||||
script (defaults to `podman`). If using Docker and the user is not in the
|
||||
docker-group, then one can use Docker in sudo-mode by using the `-s` flag for
|
||||
the script. If using Podman, running in rootless mode is recommended.
|
||||
To switch between Docker and Podman, set the `DOCKER_BIN` variable in the script
|
||||
(defaults to `podman`). If using Docker and the user is not in the docker-group,
|
||||
then one can use Docker in sudo-mode by using the `-s` flag for the script. If
|
||||
using Podman, running in rootless mode is recommended.
|
||||
|
||||
One can pass custom options to `west` by preluding them with `--`.
|
||||
|
||||
For example, to build my boards using Zephyr version 3.2 in sudo mode and pass
|
||||
the "pristine" option to west, run:
|
||||
|
||||
```bash
|
||||
zmk_build.sh -s -v 3.2 -- -p
|
||||
```
|
||||
|
@ -91,11 +94,12 @@ See the script for a full set of options.
|
|||
## Developing interactively using Docker
|
||||
|
||||
The docker container can be entered interactively using with all the necessary
|
||||
mounts using: The script shares a build environment with the build script
|
||||
(again indexed by Zephyr versions).
|
||||
mounts using: The script shares a build environment with the build script (again
|
||||
indexed by Zephyr versions).
|
||||
|
||||
For example, to start an interactive Docker session in sudo mode using Zephyr
|
||||
version 3.2, run:
|
||||
|
||||
```bash
|
||||
zmk_run_docker.sh -s -v 3.2
|
||||
```
|
||||
|
|
|
@ -3,74 +3,74 @@
|
|||
# Parse input arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
# needed when user isn't in docker group
|
||||
-s|--su)
|
||||
SUDO="sudo"
|
||||
;;
|
||||
# needed when user isn't in docker group
|
||||
-s | --su)
|
||||
SUDO="sudo"
|
||||
;;
|
||||
|
||||
-l|--local)
|
||||
RUNWITH_DOCKER="false"
|
||||
;;
|
||||
-l | --local)
|
||||
RUNWITH_DOCKER="false"
|
||||
;;
|
||||
|
||||
-m|--multithread)
|
||||
MULTITHREAD="true"
|
||||
;;
|
||||
-m | --multithread)
|
||||
MULTITHREAD="true"
|
||||
;;
|
||||
|
||||
-c|--clear-cache)
|
||||
CLEAR_CACHE="true"
|
||||
;;
|
||||
-c | --clear-cache)
|
||||
CLEAR_CACHE="true"
|
||||
;;
|
||||
|
||||
# comma or space separated list of boards (use quotes if space separated)
|
||||
# if ommitted, will compile list of boards in build.yaml
|
||||
-b|--board)
|
||||
BOARDS="$2"
|
||||
shift
|
||||
;;
|
||||
# comma or space separated list of boards (use quotes if space separated)
|
||||
# if ommitted, will compile list of boards in build.yaml
|
||||
-b | --board)
|
||||
BOARDS="$2"
|
||||
shift
|
||||
;;
|
||||
|
||||
-v|--version)
|
||||
ZEPHYR_VERSION="$2"
|
||||
shift
|
||||
;;
|
||||
-v | --version)
|
||||
ZEPHYR_VERSION="$2"
|
||||
shift
|
||||
;;
|
||||
|
||||
-o|--output-dir)
|
||||
OUTPUT_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
-o | --output-dir)
|
||||
OUTPUT_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
|
||||
--log-dir)
|
||||
LOG_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
--log-dir)
|
||||
LOG_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
|
||||
--host-config-dir)
|
||||
HOST_CONFIG_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
--host-config-dir)
|
||||
HOST_CONFIG_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
|
||||
--host-zmk-dir)
|
||||
HOST_ZMK_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
--host-zmk-dir)
|
||||
HOST_ZMK_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
|
||||
--docker-config-dir)
|
||||
DOCKER_CONFIG_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
--docker-config-dir)
|
||||
DOCKER_CONFIG_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
|
||||
--docker-zmk-dir)
|
||||
DOCKER_ZMK_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
--docker-zmk-dir)
|
||||
DOCKER_ZMK_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
|
||||
--)
|
||||
WEST_OPTS="${@:2}"
|
||||
break
|
||||
;;
|
||||
--)
|
||||
WEST_OPTS="${@:2}"
|
||||
break
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown option $1"
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option $1"
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
||||
shift
|
||||
|
@ -103,24 +103,23 @@ DOCKER_BIN="$SUDO podman"
|
|||
|
||||
cd "$HOST_CONFIG_DIR"
|
||||
|
||||
if [[ -f config/combos.dtsi ]]
|
||||
if [[ -f config/combos.dtsi ]]; then
|
||||
# update maximum combos per key
|
||||
then
|
||||
count=$( \
|
||||
tail -n +10 config/combos.dtsi | \
|
||||
grep -Eo '[LR][TMBH][0-9]' | \
|
||||
sort | uniq -c | sort -nr | \
|
||||
awk 'NR==1{print $1}' \
|
||||
count=$(
|
||||
tail -n +10 config/combos.dtsi |
|
||||
grep -Eo '[LR][TMBH][0-9]' |
|
||||
sort | uniq -c | sort -nr |
|
||||
awk 'NR==1{print $1}'
|
||||
)
|
||||
sed -Ei "/CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY/s/=.+/=$count/" config/*.conf
|
||||
echo "Setting MAX_COMBOS_PER_KEY to $count"
|
||||
|
||||
# update maximum keys per combo
|
||||
count=$( \
|
||||
tail -n +10 config/combos.dtsi | \
|
||||
grep -o -n '[LR][TMBH][0-9]' | \
|
||||
cut -d : -f 1 | uniq -c | sort -nr | \
|
||||
awk 'NR==1{print $1}' \
|
||||
count=$(
|
||||
tail -n +10 config/combos.dtsi |
|
||||
grep -o -n '[LR][TMBH][0-9]' |
|
||||
cut -d : -f 1 | uniq -c | sort -nr |
|
||||
awk 'NR==1{print $1}'
|
||||
)
|
||||
sed -Ei "/CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO/s/=.+/=$count/" config/*.conf
|
||||
echo "Setting MAX_KEYS_PER_COMBO to $count"
|
||||
|
@ -130,8 +129,7 @@ fi
|
|||
# | BUILD THE FIRMWARE |
|
||||
# +--------------------+
|
||||
|
||||
if [[ $RUNWITH_DOCKER = true ]]
|
||||
then
|
||||
if [[ $RUNWITH_DOCKER = true ]]; then
|
||||
echo "Build mode: docker"
|
||||
# DOCKER_CMD="$DOCKER_BIN run --name zmk-$ZEPHYR_VERSION --rm \
|
||||
DOCKER_CMD="$DOCKER_BIN run --rm \
|
||||
|
@ -143,8 +141,7 @@ then
|
|||
--mount type=volume,source=zmk-zephyr-tools-$ZEPHYR_VERSION,target=$DOCKER_ZMK_DIR/tools"
|
||||
|
||||
# Reset volumes
|
||||
if [[ $CLEAR_CACHE = true ]]
|
||||
then
|
||||
if [[ $CLEAR_CACHE = true ]]; then
|
||||
$DOCKER_BIN volume rm $($DOCKER_BIN volume ls -q | grep "^zmk-.*-$ZEPHYR_VERSION$")
|
||||
fi
|
||||
|
||||
|
@ -170,19 +167,17 @@ else
|
|||
fi
|
||||
|
||||
# usage: compile_board board
|
||||
compile_board () {
|
||||
compile_board() {
|
||||
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
|
||||
-- -DZMK_CONFIG="$CONFIG_DIR" -Wno-dev >"$LOGFILE" 2>&1
|
||||
if [[ $? -eq 0 ]]; then
|
||||
[[ $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
|
||||
if [[ -f $HOST_ZMK_DIR/app/build/$BUILD_DIR/zephyr/zmk.uf2 ]]; then
|
||||
TYPE="uf2"
|
||||
else
|
||||
TYPE="bin"
|
||||
|
@ -200,25 +195,22 @@ compile_board () {
|
|||
cd "$HOST_ZMK_DIR/app"
|
||||
if [[ $MULTITHREAD = "true" ]]; then
|
||||
i=1
|
||||
for board in $(echo $BOARDS | sed 's/,/ /g')
|
||||
do
|
||||
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
|
||||
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
|
||||
for ((x = 1; x < i; x++)); do
|
||||
pid="T$x"
|
||||
wait "${!pid}"
|
||||
board="B$x" # Retrieve the board name from the corresponding variable
|
||||
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
|
||||
for board in $(echo $BOARDS | sed 's/,/ /g'); do
|
||||
compile_board $board
|
||||
done
|
||||
fi
|
||||
|
|
|
@ -6,9 +6,9 @@ sudo apt upgrade
|
|||
|
||||
### Step 2: Install dependencies
|
||||
sudo apt-get install --yes --no-install-recommends git cmake ninja-build gperf \
|
||||
ccache dfu-util device-tree-compiler wget \
|
||||
python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \
|
||||
make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1
|
||||
ccache dfu-util device-tree-compiler wget \
|
||||
python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \
|
||||
make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1
|
||||
|
||||
### Step 3: Install Zephyr SDK
|
||||
|
||||
|
@ -38,7 +38,7 @@ sudo udevadm control --reload
|
|||
### Step 4: Get Zephyr and install Python dependencies
|
||||
|
||||
# Install West
|
||||
pip3 install --user -U west # may need to replace with "python3 -m pip" or "python -m pip"
|
||||
pip3 install --user -U west # may need to replace with "python3 -m pip" or "python -m pip"
|
||||
|
||||
# Get the Zephyr cource code:
|
||||
cd ~/zmk
|
||||
|
@ -49,10 +49,9 @@ west update
|
|||
west zephyr-export
|
||||
|
||||
# Install Zephyr Python Dependencies
|
||||
pip3 install --user -r zephyr/scripts/requirements.txt # see above
|
||||
pip3 install --user -r zephyr/scripts/requirements.txt # see above
|
||||
|
||||
### Step 5: Install Docusaurus
|
||||
sudo apt-get install --yes --no-install-recommends npm
|
||||
cd ~/zmk/docs
|
||||
npm ci
|
||||
|
||||
|
|
|
@ -7,48 +7,48 @@
|
|||
# Parse input arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
# needed when user isn't in docker group
|
||||
-s|--sudu)
|
||||
SUDO="sudo"
|
||||
;;
|
||||
# needed when user isn't in docker group
|
||||
-s | --sudu)
|
||||
SUDO="sudo"
|
||||
;;
|
||||
|
||||
-c|--clear-cache)
|
||||
CLEAR_CACHE="true"
|
||||
;;
|
||||
-c | --clear-cache)
|
||||
CLEAR_CACHE="true"
|
||||
;;
|
||||
|
||||
-d|--install-doc-tools)
|
||||
DOC_TOOLS="true"
|
||||
;;
|
||||
-d | --install-doc-tools)
|
||||
DOC_TOOLS="true"
|
||||
;;
|
||||
|
||||
-v|--version)
|
||||
ZEPHYR_VERSION="$2"
|
||||
shift
|
||||
;;
|
||||
-v | --version)
|
||||
ZEPHYR_VERSION="$2"
|
||||
shift
|
||||
;;
|
||||
|
||||
--host-config-dir)
|
||||
HOST_CONFIG_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
--host-config-dir)
|
||||
HOST_CONFIG_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
|
||||
--host-zmk-dir)
|
||||
HOST_ZMK_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
--host-zmk-dir)
|
||||
HOST_ZMK_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
|
||||
--docker-config-dir)
|
||||
DOCKER_CONFIG_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
--docker-config-dir)
|
||||
DOCKER_CONFIG_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
|
||||
--docker-zmk-dir)
|
||||
DOCKER_ZMK_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
--docker-zmk-dir)
|
||||
DOCKER_ZMK_DIR="$2"
|
||||
shift
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown option $1"
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option $1"
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
||||
shift
|
||||
|
@ -76,8 +76,7 @@ DOCKER_CMD="$SUDO docker run --name zmk-$ZEPHYR_VERSION --rm \
|
|||
--mount type=volume,source=zmk-zephyr-tools-$ZEPHYR_VERSION,target=$DOCKER_ZMK_DIR/tools"
|
||||
|
||||
# Reset volumes
|
||||
if [[ $CLEAR_CACHE = true ]]
|
||||
then
|
||||
if [[ $CLEAR_CACHE = true ]]; then
|
||||
$SUDO docker volume rm $(sudo docker volume ls -q | grep "^zmk-.*-$ZEPHYR_VERSION$")
|
||||
fi
|
||||
|
||||
|
@ -91,11 +90,9 @@ $DOCKER_CMD -w "$DOCKER_ZMK_DIR" "$DOCKER_IMG" /bin/bash -c " \
|
|||
&& west update"
|
||||
|
||||
# Install docosaurus
|
||||
if [[ $DOC_TOOLS = true ]]
|
||||
then
|
||||
if [[ $DOC_TOOLS = true ]]; then
|
||||
$DOCKER_CMD -w "$DOCKER_ZMK_DIR/docs" "$DOCKER_IMG" npm ci
|
||||
fi
|
||||
|
||||
# Start interactive shell
|
||||
$DOCKER_CMD -w "$DOCKER_ZMK_DIR" -it "$DOCKER_IMG" /bin/bash
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue