Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

rp2xxx: `pio.assembler.Output.get_define_by_name` does not compile (declared `u32`, breaks with a `Define`)

Aperta Adatta ai principianti
#1,086 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
zig
Ambito
embedded-iot

Direzione di ricerca

Leggi port/raspberrypi/rp2xxx/src/hal/pio/assembler.zig nella sezione intorno a Output.get_define_by_name e al suo tipo Define. L’issue include un esempio di test di regressione; aggiungi una verifica per la ricerca di T1 ed esegui zig build test in port/raspberrypi/rp2xxx. Il lavoro è completato quando la funzione compila, restituisce il valore della definizione e il test passa.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

Output.get_define_by_name (port/raspberrypi/rp2xxx/src/hal/pio/assembler.zig:58-66 on
master) is declared to return u32, but its loop does break define;, which is a
Define{ name, value: i64 }. Every call fails inside the package:

assembler.zig:64:23: error: expected type 'u32', found 'hal.pio.assembler.Define'

Nothing in the tree calls it (grep -rn get_define_by_name finds only the
declaration), so CI never compiles it. The function has been in this shape since at
least 185e906e5 (2024-02-25). Users who want a define by name end up indexing
.defines[i] by position, and that silently reads the wrong constant once the
program's .define lines are reordered.

Versions
tree toolchain result
microzig 0.15.1 release zig 0.15.2 compile error (rc=1), assembler.zig:66:23
microzig master f36d59fb7b22 (tag 0.17.17, 2026-10-10) zig 0.17.0 compile error (rc=1), assembler.zig:64:23
master + the fix below zig 0.17.0 builds (rc=0)
Repro

A minimal firmware with microzig as a path dependency, built for boards.raspberrypi.pico:

const microzig = @import("microzig");
const hal = microzig.hal;

const out = hal.pio.assemble(
    \\.define PUBLIC T1 3
    \\.program p
    \\    nop
, .{});

comptime {
    if (@hasDecl(microzig, "export_startup")) _ = microzig.export_startup();
}

pub fn main() void {
    const t1 = comptime out.get_define_by_name("T1");
    if (t1 != 3) @compileError("expected T1 == 3");
    while (true) {}
}

Expected: builds; T1 == 3.
Actual (master, zig 0.17.0):

deps/microzig/port/raspberrypi/rp2xxx/src/hal/pio/assembler.zig:64:23: error: expected type 'u32', found 'hal.pio.assembler.Define'
                break define;
                      ^~~~~~
repro.zig:18:47: note: called at comptime here
    const t1 = comptime out.get_define_by_name("T1");
Fix

Return the define's value, typed as Define.value is (i64), so no cast or range
check is needed. The patch also adds a test, so CI compiles the function from now on:

-    ) u32 {
+    ) i64 {
         return for (output.defines) |define| {
             if (std.mem.eql(u8, name, define.name))
-                break define;
+                break define.value;
test "get_define_by_name" {
    const output = comptime assemble(.RP2040,
        \\.define PUBLIC T1 3
        \\.program testprog
        \\    nop
    , .{});
    try std.testing.expectEqual(@as(i64, 3), comptime output.get_define_by_name("T1"));
}

zig build test in port/raspberrypi/rp2xxx: master gives 135/135 passed; with the
patch it gives 136/136 passed (rc=0).

(Alternative, if you would rather mirror get_program_by_name: return Define
and have callers write .value. The patch keeps the name's promise of a value.)

I have the patch ready and can open it as a PR if you'd like.

Lingua principale
Zig
Stelle
2.3k
Fork
198
Merge medio
1g 8h
PR unite (30g)
37

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ZigEmbeddedGroup/microzig

Tutte le issue di ZigEmbeddedGroup/microzig

Issue simili

Altre issue su Embedded & IoT

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.