zmk/scripts
urob 4fbcfb1afa Squashed commit of the following:
commit ea2fdc05e454f6fb0d7e5468e0f40b9497c6a0b0
Author: urob <978080+urob@users.noreply.github.com>
Date:   Mon Jul 31 10:56:02 2023 -0400

    Multithreading support for docker/podman

commit 9da06f8f5c97da66a6be83bbaa144f60759a9b89
Merge: c21715b c7e299e
Author: urob <978080+urob@users.noreply.github.com>
Date:   Tue Jun 27 16:53:15 2023 -0400

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

commit c7e299e5588ba85586c0231e53f544d1e71cf2dc
Author: ffnf <133487359+ffnf@users.noreply.github.com>
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 <133487359+ffnf@users.noreply.github.com>
2023-07-31 12:52:44 -04:00
..
readme.md Option to use podman 2023-03-31 23:37:39 -04:00
zmk_build.sh Squashed commit of the following: 2023-07-31 12:52:44 -04:00
zmk_local_install.sh Keep SDK version fixed at 0.15.2 2023-01-20 11:48:21 -05:00
zmk_run_docker.sh Include initial setup in build script 2023-01-19 11:14:35 -05:00

This folder contains scripts that automate installing and building using a local toolchain. The scripts provide an alternative to using Github Actions and the developer toolchain.

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.

For example, to build against my main-3.2 branch, run:

cd "$HOME"
git clone https://github.com/urob/zmk
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.

For example, to use my zmk-config repo, run:

cd "$HOME"
git clone https://github.com/urob/zmk-config

3. Install the build requisites

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:
    sudo apt-get install podman
    echo 'unqualified-search-registries = ["docker.io"]' > $XDG_CONFIG_HOME/containers/registries.conf
    
  2. Install a local developer toolchain. 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.

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.

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.

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:

zmk_build.sh -s -v 3.2 -- -p

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).

For example, to start an interactive Docker session in sudo mode using Zephyr version 3.2, run:

zmk_run_docker.sh -s -v 3.2