Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(toolchain): Improved local setup #2695

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ cmake_minimum_required(VERSION 3.13.1)

set(CONFIG_APPLICATION_DEFINED_SYSCALL true)

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../zmk-config AND NOT DEFINED ZMK_CONFIG_LOCAL_MODULE)
set(ZMK_CONFIG_LOCAL_MODULE ${CMAKE_CURRENT_SOURCE_DIR}/../zmk-config)
endif()

set(ZEPHYR_BOARD_ALIASES "boards/aliases.cmake")
set(ZEPHYR_EXTRA_MODULES "${ZMK_EXTRA_MODULES};${CMAKE_CURRENT_SOURCE_DIR}/module;${CMAKE_CURRENT_SOURCE_DIR}/keymap-module")
set(EXTRA_ZEPHYR_MODULES "${ZMK_EXTRA_MODULES};${CMAKE_CURRENT_SOURCE_DIR}/module;${CMAKE_CURRENT_SOURCE_DIR}/keymap-module;${ZMK_CONFIG_LOCAL_MODULE}")

# Find Zephyr. This also loads Zephyr's build system.
find_package(Zephyr REQUIRED HINTS ../zephyr)
Expand Down
6 changes: 6 additions & 0 deletions app/keymap-module/modules/modules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ elseif(DEFINED ENV{ZMK_CONFIG})

elseif(user_config_app_cmake_lists)
set(ZMK_CONFIG ${user_config_app_cmake_lists})

elseif(EXISTS ${APPLICATION_SOURCE_DIR}/../zmk-config/config)
set(ZMK_CONFIG ${APPLICATION_SOURCE_DIR}/../zmk-config/config)

endif()

# Store the selected user_config in the cache
Expand All @@ -50,10 +54,12 @@ if (ZMK_CONFIG)
set(ENV{ZMK_CONFIG} "${ZMK_CONFIG}")
if(EXISTS ${ZMK_CONFIG}/boards)
message(STATUS "Adding ZMK config directory as board root: ${ZMK_CONFIG}")
message(DEPRECATION "Using the config folder as board root is deprecated.")
list(APPEND BOARD_ROOT ${ZMK_CONFIG})
endif()
if(EXISTS ${ZMK_CONFIG}/dts)
message(STATUS "Adding ZMK config directory as DTS root: ${ZMK_CONFIG}")
message(DEPRECATION "Using the config folder as DTS root is deprecated.")
list(APPEND DTS_ROOT ${ZMK_CONFIG})
endif()
endif()
Expand Down
35 changes: 20 additions & 15 deletions docs/docs/development/local-toolchain/build-flash.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ Build times can be significantly reduced after the initial build by omitting all

### Building With External Modules

ZMK supports loading additional boards, shields, code, etc. from [external Zephyr modules](https://docs.zephyrproject.org/3.5.0/develop/modules.html), facilitating out-of-tree management and versioning independent of the ZMK repository. To build with any additional modules, use the `ZMK_EXTRA_MODULES` define added to your `west build` command.
ZMK supports loading additional boards, shields, code, etc. from [external Zephyr modules](https://docs.zephyrproject.org/3.5.0/develop/modules.html), facilitating out-of-tree management and versioning independent of the ZMK repository.

**Building with any modules specified in `zmk/zmk-config/config/west.yml` is done automatically.**

To build with any additional modules beyond that, use the `ZMK_EXTRA_MODULES` define added to your `west build` command.

For instance, building with the `my-vendor-keebs-module` checked out to your documents directory, you would build like:

Expand All @@ -157,27 +161,28 @@ When adding multiple modules, make sure they are separated by a semicolon, e.g.:
west build -b nice_nano_v2 -- -DSHIELD=vendor_shield -DZMK_EXTRA_MODULES="C:/Users/myUser/Documents/my-vendor-keebs-module;C:/Users/myUser/Documents/my-other-keebs-module"
```

### Building from `zmk-config` Folder
### Building from Alternative `zmk-config` Folders

Instead of building .uf2 files using the default keymap and config files, you
can build using files from your [`zmk-config` folder](../../user-setup.mdx#github-repo)
by adding `-DZMK_CONFIG="C:/the/absolute/path/config"` to your `west build`
command. **Notice that this path should point to the folder labeled `config`
within your `zmk-config` folder.**
ZMK will build using files from your []`zmk/zmk-config/config` folder](../../user-setup.mdx#github-repo) automatically.
If you have an alternative `zmk-config` that you'd like to use instead, you can point to it with the `ZMK_CONFIG` CMake argument.

For instance, building kyria firmware from a user `myUser`'s `zmk-config` folder
on Windows may look something like this:
Add the `-DZMK_CONFIG="C:/the/absolute/path/alternative/config"` to your `west build`
command. **Notice that this path should point to the folder labeled `config`
within your `zmk-config` folder.** For example:

```sh
west build -b nice_nano -- -DSHIELD=kyria_left \
-DZMK_CONFIG="C:/Users/myUser/Documents/Github/zmk-config/config"
-DZMK_CONFIG="C:/Users/myUser/Documents/Github/zmk-config-two/config"
```

:::warning
If your config is also a [module](../../features/modules.mdx), then you should
also add the root (the folder in which the `zephyr` folder is found) of your
`zmk-config` as an [external module to build with](#building-with-external-modules).
:::
If this alternative config is also a [module](../../features/modules.mdx), you will need to mark it as such with the `ZMK_CONFIG_LOCAL_MODULE` flag.
Note that this flag should point to the `zmk-config` root, _not_ the folder labeled `config`.

```sh
west build -b nice_nano -- -DSHIELD=kyria_left \
-DZMK_CONFIG="C:/Users/myUser/Documents/Github/zmk-config-two/config" \
-DZMK_CONFIG_LOCAL_MODULE="C:/Users/myUser/Documents/Github/zmk-config-two"
```

## Flashing

Expand Down
10 changes: 8 additions & 2 deletions docs/docs/development/local-toolchain/setup/native.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ Then step into the repository.
cd zmk
```

Clone your `zmk-config` into the repository, making sure that the local name for it is `zmk-config`.

```sh
git clone [email protected]:<Your Username>/zmk-config.git zmk-config
```

## 3. Get Zephyr and install Python dependencies

:::note
Expand Down Expand Up @@ -179,7 +185,7 @@ pip install west
5. Initialize the application and update to fetch modules, including Zephyr:

```sh
west init -l app/
west init -l local/
west update
```

Expand Down Expand Up @@ -268,7 +274,7 @@ pip3 install -U west
2. Initialize the application and update to fetch modules, including Zephyr:

```sh
west init -l app/
west init -l local/
west update
```

Expand Down
6 changes: 6 additions & 0 deletions local/config-import.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
manifest:
self:
import:
file: ../zmk-config/config/west.yml
name-blocklist: [zmk]
path-prefix: modules
5 changes: 5 additions & 0 deletions local/west.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
manifest:
self:
import:
- config-import.yml
- ../app/west.yml
Loading