Skip to content

Build breaks if reserved layer added but Studio disabled #3045

@joelspadin

Description

@joelspadin

If your keymap contains a layer with status = "reserved" but CONFIG_ZMK_STUDIO=n, then it will fail to compile with a 5000 line long error. The error starts with

zmk/app/src/keymap.c:60:81: warning: excess elements in array initializer

Some other context

zmk/app/src/keymap.c:60:81: note: (near initialization for 'zmk_keymap_layer_names')
   60 | #define LAYER_NAME(node) DT_PROP_OR(node, display_name, DT_PROP_OR(node, label, ""))
      |                                                                                 ^~

The culprit seems to be this code at line 98 of keymap.c:

static const char *zmk_keymap_layer_names[ZMK_KEYMAP_LAYERS_LEN] = {
    DT_INST_FOREACH_CHILD_SEP(0, LAYER_NAME, (, ))};

Where ZMK_KEYMAP_LAYERS_LEN uses DT_FOREACH_CHILD_STATUS_OKAY when Studio is disabled, the code here (and in several other places in keymap.c) does not, so it tries to add more items to the array than there are layers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    keymapsPRs and issues related to keymapsstudioZMK Studio (runtime keymaps)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions