Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#1,086 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
88/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
zig
Lĩnh vực
embedded-iot

Hướng nghiên cứu

Đọc port/raspberrypi/rp2xxx/src/hal/pio/assembler.zig ở phần quanh Output.get_define_by_name và kiểu Define của nó. Issue có ví dụ về kiểm thử hồi quy; hãy bổ sung kiểm thử cho việc tra cứu T1 và chạy zig build test trong port/raspberrypi/rp2xxx. Công việc được xem là hoàn tất khi hàm biên dịch được, trả về giá trị define và kiểm thử thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Zig
Star
2.3k
Fork
198
Merge trung bình
1 ngày 8 giờ
Pull request đã merge (30 ngày)
37

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ZigEmbeddedGroup/microzig

Tất cả issue của ZigEmbeddedGroup/microzig

Issue tương tự

Thêm issue về Embedded & IoT

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.