Updated to zig 0.13.0 (#198)

* Updated to latest zig

* feat(flake): update zig to 0.13.0 and add zls

This also disable diffs for flake.lock to not
not polute the git diff output too much

* feat(build): Update dependencies to support 0.13.0

* feat(build): disable broken examples

* feat(ci): Update zig to 0.13.0

* feat(rp2040): Update pio tokenizer tests to 0.13.0

* feat(build): Fix uses of deprecated std.zig.CrossTarget

* feat(rezg): Fix uses of deprecated std.mem.{tokenize,slice}

* feat(rp2040): Fix uses of depreacted std.rand

* feat(readme): Update zig version

---------

Co-authored-by: Maciej 'vesim' Kuliński <vesim809@pm.me>
wch-ch32v003
biom4st3r 2 months ago committed by GitHub
parent bb8888944f
commit fcb68ad0e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,2 +1,3 @@
# use_nix if has nix; then
use_flake use flake
fi

1
.gitattributes vendored

@ -1 +1,2 @@
*.zig text=auto eol=lf *.zig text=auto eol=lf
flake.lock -diff

@ -25,7 +25,7 @@ jobs:
- name: Setup Zig - name: Setup Zig
uses: goto-bus-stop/setup-zig@v2 uses: goto-bus-stop/setup-zig@v2
with: with:
version: 0.12.0 version: 0.13.0
- name: Build - name: Build
run: zig build -Doptimize=ReleaseSmall run: zig build -Doptimize=ReleaseSmall

@ -23,7 +23,7 @@ jobs:
- name: Setup Zig - name: Setup Zig
uses: goto-bus-stop/setup-zig@v2 uses: goto-bus-stop/setup-zig@v2
with: with:
version: 0.12.0 version: 0.13.0
- name: Extract version - name: Extract version
run: echo "MICROZIG_VERSION=$(zig build package -- get-version)" >> $GITHUB_ENV run: echo "MICROZIG_VERSION=$(zig build package -- get-version)" >> $GITHUB_ENV

1
.gitignore vendored

@ -1,5 +1,6 @@
zig-out/ zig-out/
zig-cache/ zig-cache/
.zig-cache/
microzig-deploy/ microzig-deploy/
.DS_Store .DS_Store
.gdbinit .gdbinit

@ -8,7 +8,7 @@
## What version of Zig to use ## What version of Zig to use
Zig 0.12.0 Zig 0.13.0
## Getting Started With MicroZig ## Getting Started With MicroZig

@ -10,7 +10,7 @@ fn path(comptime suffix: []const u8) std.Build.LazyPath {
const esp_riscv = .{ const esp_riscv = .{
.name = "Espressif RISC-V", .name = "Espressif RISC-V",
.root_source_file = path("/src/cpus/espressif-riscv.zig"), .root_source_file = path("/src/cpus/espressif-riscv.zig"),
.target = std.zig.CrossTarget{ .target = std.Target.Query{
.cpu_arch = .riscv32, .cpu_arch = .riscv32,
.cpu_model = .{ .explicit = &std.Target.riscv.cpu.generic_rv32 }, .cpu_model = .{ .explicit = &std.Target.riscv.cpu.generic_rv32 },
.cpu_features_add = std.Target.riscv.featureSet(&.{ .cpu_features_add = std.Target.riscv.featureSet(&.{

@ -19,7 +19,7 @@ pub const chips = struct {
.url = "https://www.microchip.com/en-us/product/ATSAMD51J19A", .url = "https://www.microchip.com/en-us/product/ATSAMD51J19A",
.cpu = MicroZig.cpus.cortex_m4, .cpu = MicroZig.cpus.cortex_m4,
.register_definition = .{ .register_definition = .{
.atdf = .{ .path = build_root ++ "/src/chips/ATSAMD51J19A.atdf" }, .atdf = .{ .cwd_relative = build_root ++ "/src/chips/ATSAMD51J19A.atdf" },
}, },
.memory_regions = &.{ .memory_regions = &.{
.{ .kind = .flash, .offset = 0x00000000, .length = 512 * 1024 }, // Embedded Flash .{ .kind = .flash, .offset = 0x00000000, .length = 512 * 1024 }, // Embedded Flash

@ -12,9 +12,9 @@ const build_root = root();
pub fn build(b: *Build) !void { pub fn build(b: *Build) !void {
const unit_tests = b.addTest(.{ const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/hal.zig" }, .root_source_file = b.path("src/hal.zig"),
}); });
unit_tests.addIncludePath(.{ .path = "src/hal/pio/assembler" }); unit_tests.addIncludePath(b.path("src/hal/pio/assembler"));
const unit_tests_run = b.addRunArtifact(unit_tests); const unit_tests_run = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run platform agnostic unit tests"); const test_step = b.step("test", "Run platform agnostic unit tests");
@ -119,7 +119,7 @@ pub const BootROM = union(enum) {
}; };
const linker_script = .{ const linker_script = .{
.path = build_root ++ "/rp2040.ld", .cwd_relative = build_root ++ "/rp2040.ld",
}; };
const hal = .{ const hal = .{
@ -188,8 +188,8 @@ pub fn get_bootrom(mz: *MicroZig, rom: BootROM) Stage2Bootloader {
.root_source_file = null, .root_source_file = null,
}); });
//rom_exe.linkage = .static; //rom_exe.linkage = .static;
rom_exe.setLinkerScript(.{ .path = build_root ++ "/src/bootroms/shared/stage2.ld" }); rom_exe.setLinkerScript(.{ .cwd_relative = build_root ++ "/src/bootroms/shared/stage2.ld" });
rom_exe.addAssemblyFile(.{ .path = rom_path }); rom_exe.addAssemblyFile(.{ .cwd_relative = rom_path });
rom_exe.entry = .{ .symbol_name = "_stage2_boot" }; rom_exe.entry = .{ .symbol_name = "_stage2_boot" };
break :blk rom_exe; break :blk rom_exe;

@ -481,7 +481,7 @@ pub const Tokenizer = struct {
}; };
} }
const directives = std.ComptimeStringMap(*const fn (*Tokenizer, u32, *?Diagnostics) TokenizeError!Token, .{ const directives = std.StaticStringMap(*const fn (*Tokenizer, u32, *?Diagnostics) TokenizeError!Token).initComptime(.{
.{ "program", get_program }, .{ "program", get_program },
.{ "define", get_define }, .{ "define", get_define },
.{ "origin", get_origin }, .{ "origin", get_origin },
@ -527,7 +527,7 @@ pub const Tokenizer = struct {
fn get_jmp(self: *Tokenizer, diags: *?Diagnostics) TokenizeError!Token.Instruction.Payload { fn get_jmp(self: *Tokenizer, diags: *?Diagnostics) TokenizeError!Token.Instruction.Payload {
const Condition = Token.Instruction.Jmp.Condition; const Condition = Token.Instruction.Jmp.Condition;
const conditions = std.ComptimeStringMap(Condition, .{ const conditions = std.StaticStringMap(Condition).initComptime(.{
.{ "!x", .x_is_zero }, .{ "!x", .x_is_zero },
.{ "x--", .x_dec }, .{ "x--", .x_dec },
.{ "!y", .y_is_zero }, .{ "!y", .y_is_zero },
@ -828,7 +828,7 @@ pub const Tokenizer = struct {
}; };
} }
const instructions = std.ComptimeStringMap(*const fn (*Tokenizer, *?Diagnostics) TokenizeError!Token.Instruction.Payload, .{ const instructions = std.StaticStringMap(*const fn (*Tokenizer, *?Diagnostics) TokenizeError!Token.Instruction.Payload).initComptime(.{
.{ "nop", get_nop }, .{ "nop", get_nop },
.{ "jmp", get_jmp }, .{ "jmp", get_jmp },
.{ "wait", get_wait }, .{ "wait", get_wait },
@ -1588,7 +1588,7 @@ test "tokenize.instr.jmp.value" {
test "tokenize.instr.jmp.conditions" { test "tokenize.instr.jmp.conditions" {
const Condition = Token.Instruction.Jmp.Condition; const Condition = Token.Instruction.Jmp.Condition;
const cases = std.ComptimeStringMap(Condition, .{ const cases = std.StaticStringMap(Condition).initComptime(.{
.{ "!x", .x_is_zero }, .{ "!x", .x_is_zero },
.{ "x--", .x_dec }, .{ "x--", .x_dec },
.{ "!y", .y_is_zero }, .{ "!y", .y_is_zero },
@ -1598,9 +1598,7 @@ test "tokenize.instr.jmp.conditions" {
.{ "!osre", .osre_not_empty }, .{ "!osre", .osre_not_empty },
}); });
inline for (cases.kvs) |case| { inline for (comptime cases.keys(), comptime cases.values()) |op, cond| {
const op = case.key;
const cond = case.value;
const tokens = try bounded_tokenize(comptime std.fmt.comptimePrint("jmp {s} my_label", .{op})); const tokens = try bounded_tokenize(comptime std.fmt.comptimePrint("jmp {s} my_label", .{op}));
try expect_instr_jmp(.{ .cond = cond, .target = "my_label" }, tokens.get(0)); try expect_instr_jmp(.{ .cond = cond, .target = "my_label" }, tokens.get(0));
@ -1762,16 +1760,14 @@ test "tokenize.instr.mov" {
} }
const Operation = Token.Instruction.Mov.Operation; const Operation = Token.Instruction.Mov.Operation;
const operations = std.ComptimeStringMap(Operation, .{ const operations = std.StaticStringMap(Operation).initComptime(.{
.{ "!", .invert }, .{ "!", .invert },
.{ "~", .invert }, .{ "~", .invert },
.{ "::", .bit_reverse }, .{ "::", .bit_reverse },
}); });
inline for (.{ "", " " }) |space| { inline for (.{ "", " " }) |space| {
inline for (operations.kvs) |kv| { inline for (comptime operations.keys(), comptime operations.values()) |str, operation| {
const str = kv.key;
const operation = kv.value;
const tokens = try bounded_tokenize(comptime std.fmt.comptimePrint("mov x {s}{s}y", .{ const tokens = try bounded_tokenize(comptime std.fmt.comptimePrint("mov x {s}{s}y", .{
str, str,
space, space,
@ -1792,7 +1788,7 @@ test "tokenize.instr.irq" {
wait: bool, wait: bool,
}; };
const modes = std.ComptimeStringMap(ClearWait, .{ const modes = std.StaticStringMap(ClearWait).initComptime(.{
.{ "", .{ .clear = false, .wait = false } }, .{ "", .{ .clear = false, .wait = false } },
.{ "set", .{ .clear = false, .wait = false } }, .{ "set", .{ .clear = false, .wait = false } },
.{ "nowait", .{ .clear = false, .wait = false } }, .{ "nowait", .{ .clear = false, .wait = false } },
@ -1800,15 +1796,15 @@ test "tokenize.instr.irq" {
.{ "clear", .{ .clear = true, .wait = false } }, .{ "clear", .{ .clear = true, .wait = false } },
}); });
inline for (modes.kvs, 0..) |kv, num| { inline for (comptime modes.keys(), comptime modes.values(), 0..) |key, value, num| {
const tokens = try bounded_tokenize(comptime std.fmt.comptimePrint("irq {s} {}", .{ const tokens = try bounded_tokenize(comptime std.fmt.comptimePrint("irq {s} {}", .{
kv.key, key,
num, num,
})); }));
try expect_instr_irq(.{ try expect_instr_irq(.{
.clear = kv.value.clear, .clear = value.clear,
.wait = kv.value.wait, .wait = value.wait,
.num = num, .num = num,
}, tokens.get(0)); }, tokens.get(0));
} }

@ -2,7 +2,7 @@
const std = @import("std"); const std = @import("std");
const assert = std.debug.assert; const assert = std.debug.assert;
const Random = std.rand.Random; const Random = std.Random;
const microzig = @import("microzig"); const microzig = @import("microzig");
const peripherals = microzig.chip.peripherals; const peripherals = microzig.chip.peripherals;
@ -20,11 +20,11 @@ const peripherals = microzig.chip.peripherals;
/// for security systems because the ROSC as entropy source can be /// for security systems because the ROSC as entropy source can be
/// compromised. However, it promises at least equal distribution. /// compromised. However, it promises at least equal distribution.
pub const Ascon = struct { pub const Ascon = struct {
state: std.rand.Ascon, state: Random.Ascon,
counter: usize = 0, counter: usize = 0,
const reseed_threshold = 4096; const reseed_threshold = 4096;
const secret_seed_length = std.rand.Ascon.secret_seed_length; const secret_seed_length = Random.Ascon.secret_seed_length;
pub fn init() @This() { pub fn init() @This() {
// Ensure that the system clocks run from the XOSC and/or PLLs // Ensure that the system clocks run from the XOSC and/or PLLs
@ -38,10 +38,10 @@ pub const Ascon = struct {
var b: [secret_seed_length]u8 = undefined; var b: [secret_seed_length]u8 = undefined;
rosc(&b); rosc(&b);
return @This(){ .state = std.rand.Ascon.init(b) }; return @This(){ .state = Random.Ascon.init(b) };
} }
/// Returns a `std.rand.Random` structure backed by the current RNG /// Returns a `std.Random` structure backed by the current RNG
pub fn random(self: *@This()) Random { pub fn random(self: *@This()) Random {
return Random.init(self, fill); return Random.init(self, fill);
} }

@ -190,7 +190,7 @@ pub const boards = struct {
.chip = chips.stm32f303vc.chip, .chip = chips.stm32f303vc.chip,
.board = .{ .board = .{
.name = "STM32F3DISCOVERY", .name = "STM32F3DISCOVERY",
.root_source_file = .{ .path = build_root ++ "/src/boards/STM32F3DISCOVERY.zig" }, .root_source_file = .{ .cwd_relative = build_root ++ "/src/boards/STM32F3DISCOVERY.zig" },
}, },
}; };
@ -199,7 +199,7 @@ pub const boards = struct {
.chip = chips.stm32f407vg.chip, .chip = chips.stm32f407vg.chip,
.board = .{ .board = .{
.name = "STM32F4DISCOVERY", .name = "STM32F4DISCOVERY",
.root_source_file = .{ .path = build_root ++ "/src/boards/STM32F4DISCOVERY.zig" }, .root_source_file = .{ .cwd_relative = build_root ++ "/src/boards/STM32F4DISCOVERY.zig" },
}, },
}; };
@ -208,7 +208,7 @@ pub const boards = struct {
.chip = chips.stm32f407vg.chip, .chip = chips.stm32f407vg.chip,
.board = .{ .board = .{
.name = "STM3240G_EVAL", .name = "STM3240G_EVAL",
.root_source_file = .{ .path = build_root ++ "/src/boards/STM3240G_EVAL.zig" }, .root_source_file = .{ .cwd_relative = build_root ++ "/src/boards/STM3240G_EVAL.zig" },
}, },
}; };
@ -217,7 +217,7 @@ pub const boards = struct {
.chip = chips.stm32f429zit6u.chip, .chip = chips.stm32f429zit6u.chip,
.board = .{ .board = .{
.name = "STM32F429IDISCOVERY", .name = "STM32F429IDISCOVERY",
.root_source_file = .{ .path = build_root ++ "/src/boards/STM32F429IDISCOVERY.zig" }, .root_source_file = .{ .cwd_relative = build_root ++ "/src/boards/STM32F429IDISCOVERY.zig" },
}, },
}; };
}; };

@ -1,6 +1,7 @@
.{ .{
.name = "microzig", .name = "microzig",
.version = "0.12.1", .version = "0.13.0",
.minimum_zig_version = "0.13.0",
.dependencies = .{ .dependencies = .{
// packages within the monorepo so that others can reach them // packages within the monorepo so that others can reach them
.build = .{ .path = "build" }, .build = .{ .path = "build" },
@ -29,8 +30,8 @@
// used for creating package tarballs // used for creating package tarballs
.boxzer = .{ .boxzer = .{
.url = "https://github.com/mattnite/boxzer/archive/74f17daa97f6861c31b30a5070136216c08eb39b.tar.gz", .url = "https://github.com/mattnite/boxzer/archive/6bd6636d780f626af1c40a27be2680e223965c8a.tar.gz",
.hash = "1220a14c01a66c023d8944dc672edd5121f98f82196fefbc09a13bcadb96e1c8e7f1", .hash = "1220432ca3323f0a7033fd84df6d0f2d66aecf4c5301b3ac70c96cca8b0938164f17",
}, },
}, },

@ -23,7 +23,7 @@ pub fn build(b: *Build) !void {
const uf2_dep = b.dependency("microzig/tools/uf2", .{}); const uf2_dep = b.dependency("microzig/tools/uf2", .{});
const build_test = b.addTest(.{ const build_test = b.addTest(.{
.root_source_file = .{ .path = "build.zig" }, .root_source_file = b.path("build.zig"),
}); });
build_test.root_module.addAnonymousImport("uf2", .{ build_test.root_module.addAnonymousImport("uf2", .{
@ -39,6 +39,9 @@ pub fn build(b: *Build) !void {
b.getInstallStep().dependOn(&install_docs.step); b.getInstallStep().dependOn(&install_docs.step);
} }
fn root() []const u8 {
return comptime (std.fs.path.dirname(@src().file) orelse ".");
}
/// Creates a new MicroZig build environment that can be used to create new firmware. /// Creates a new MicroZig build environment that can be used to create new firmware.
pub fn init(b: *Build, opts: struct { pub fn init(b: *Build, opts: struct {
dependency_name: []const u8 = "microzig/build", dependency_name: []const u8 = "microzig/build",
@ -53,7 +56,7 @@ pub fn init(b: *Build, opts: struct {
.microzig_core = core_dep, .microzig_core = core_dep,
.generate_linkerscript = mz_dep.builder.addExecutable(.{ .generate_linkerscript = mz_dep.builder.addExecutable(.{
.name = "generate-linkerscript", .name = "generate-linkerscript",
.root_source_file = .{ .path = "src/generate_linkerscript.zig" }, .root_source_file = .{ .cwd_relative = comptime root() ++ "/src/generate_linkerscript.zig" },
.target = mz_dep.builder.host, .target = mz_dep.builder.host,
}), }),
}; };

@ -4,7 +4,7 @@ const LazyPath = Build.LazyPath;
pub fn build(b: *Build) void { pub fn build(b: *Build) void {
_ = b.addModule("definitions", .{ _ = b.addModule("definitions", .{
.root_source_file = .{ .path = "build.zig" }, .root_source_file = b.path("build.zig"),
}); });
} }

@ -18,8 +18,8 @@ pub fn build(b: *std.Build) !void {
pub const cpus = struct { pub const cpus = struct {
pub const avr5 = MicroZig.Cpu{ pub const avr5 = MicroZig.Cpu{
.name = "AVR5", .name = "AVR5",
.root_source_file = .{ .path = build_root ++ "/src/cpus/avr5.zig" }, .root_source_file = .{ .cwd_relative = build_root ++ "/src/cpus/avr5.zig" },
.target = std.zig.CrossTarget{ .target = std.Target.Query{
.cpu_arch = .avr, .cpu_arch = .avr,
.cpu_model = .{ .explicit = &std.Target.avr.cpu.avr5 }, .cpu_model = .{ .explicit = &std.Target.avr.cpu.avr5 },
.os_tag = .freestanding, .os_tag = .freestanding,
@ -29,8 +29,8 @@ pub const cpus = struct {
pub const cortex_m0 = MicroZig.Cpu{ pub const cortex_m0 = MicroZig.Cpu{
.name = "ARM Cortex-M0", .name = "ARM Cortex-M0",
.root_source_file = .{ .path = build_root ++ "/src/cpus/cortex_m.zig" }, .root_source_file = .{ .cwd_relative = build_root ++ "/src/cpus/cortex_m.zig" },
.target = std.zig.CrossTarget{ .target = std.Target.Query{
.cpu_arch = .thumb, .cpu_arch = .thumb,
.cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m0 }, .cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m0 },
.os_tag = .freestanding, .os_tag = .freestanding,
@ -40,8 +40,8 @@ pub const cpus = struct {
pub const cortex_m0plus = MicroZig.Cpu{ pub const cortex_m0plus = MicroZig.Cpu{
.name = "ARM Cortex-M0+", .name = "ARM Cortex-M0+",
.root_source_file = .{ .path = build_root ++ "/src/cpus/cortex_m.zig" }, .root_source_file = .{ .cwd_relative = build_root ++ "/src/cpus/cortex_m.zig" },
.target = std.zig.CrossTarget{ .target = std.Target.Query{
.cpu_arch = .thumb, .cpu_arch = .thumb,
.cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m0plus }, .cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m0plus },
.os_tag = .freestanding, .os_tag = .freestanding,
@ -51,8 +51,8 @@ pub const cpus = struct {
pub const cortex_m3 = MicroZig.Cpu{ pub const cortex_m3 = MicroZig.Cpu{
.name = "ARM Cortex-M3", .name = "ARM Cortex-M3",
.root_source_file = .{ .path = build_root ++ "/src/cpus/cortex_m.zig" }, .root_source_file = .{ .cwd_relative = build_root ++ "/src/cpus/cortex_m.zig" },
.target = std.zig.CrossTarget{ .target = std.Target.Query{
.cpu_arch = .thumb, .cpu_arch = .thumb,
.cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m3 }, .cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m3 },
.os_tag = .freestanding, .os_tag = .freestanding,
@ -62,8 +62,8 @@ pub const cpus = struct {
pub const cortex_m4 = MicroZig.Cpu{ pub const cortex_m4 = MicroZig.Cpu{
.name = "ARM Cortex-M4", .name = "ARM Cortex-M4",
.root_source_file = .{ .path = build_root ++ "/src/cpus/cortex_m.zig" }, .root_source_file = .{ .cwd_relative = build_root ++ "/src/cpus/cortex_m.zig" },
.target = std.zig.CrossTarget{ .target = std.Target.Query{
.cpu_arch = .thumb, .cpu_arch = .thumb,
.cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m4 }, .cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m4 },
.os_tag = .freestanding, .os_tag = .freestanding,
@ -73,8 +73,8 @@ pub const cpus = struct {
pub const riscv32_imac = MicroZig.Cpu{ pub const riscv32_imac = MicroZig.Cpu{
.name = "RISC-V 32-bit", .name = "RISC-V 32-bit",
.root_source_file = .{ .path = build_root ++ "/src/cpus/riscv32.zig" }, .root_source_file = .{ .cwd_relative = build_root ++ "/src/cpus/riscv32.zig" },
.target = std.zig.CrossTarget{ .target = std.Target.Query{
.cpu_arch = .riscv32, .cpu_arch = .riscv32,
.cpu_model = .{ .explicit = &std.Target.riscv.cpu.sifive_e21 }, .cpu_model = .{ .explicit = &std.Target.riscv.cpu.sifive_e21 },
.os_tag = .freestanding, .os_tag = .freestanding,

@ -20,7 +20,7 @@ pub fn build(b: *std.Build) void {
.name = example.name, .name = example.name,
.target = example.target, .target = example.target,
.optimize = optimize, .optimize = optimize,
.root_source_file = .{ .path = example.file }, .root_source_file = b.path(example.file),
}); });
// `installFirmware()` is the MicroZig pendant to `Build.installArtifact()` // `installFirmware()` is the MicroZig pendant to `Build.installArtifact()`

@ -3,10 +3,13 @@ const MicroZig = @import("microzig/build");
const gd32 = @import("microzig/bsp/gigadevice/gd32"); const gd32 = @import("microzig/bsp/gigadevice/gd32");
const available_examples = [_]Example{ const available_examples = [_]Example{
.{ .target = gd32.chips.gd32vf103xb, .name = "gd32vf103xb", .file = "src/empty.zig" }, // TODO:
.{ .target = gd32.chips.gd32vf103x8, .name = "gd32vf103x8", .file = "src/empty.zig" }, // error: ld.lld: section '.text' will not fit in region 'flash0': overflowed by 152170 bytes
.{ .target = gd32.boards.sipeed.longan_nano, .name = "sipeed-longan_nano", .file = "src/empty.zig" }, // error: ld.lld: section '.data' will not fit in region 'flash0': overflowed by 161520 bytes
.{ .target = gd32.boards.sipeed.longan_nano, .name = "sipeed-longan_nano_blinky", .file = "src/blinky.zig" }, // .{ .target = gd32.chips.gd32vf103xb, .name = "gd32vf103xb", .file = "src/empty.zig" },
// .{ .target = gd32.chips.gd32vf103x8, .name = "gd32vf103x8", .file = "src/empty.zig" },
// .{ .target = gd32.boards.sipeed.longan_nano, .name = "sipeed-longan_nano", .file = "src/empty.zig" },
// .{ .target = gd32.boards.sipeed.longan_nano, .name = "sipeed-longan_nano_blinky", .file = "src/blinky.zig" },
}; };
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
@ -23,7 +26,7 @@ pub fn build(b: *std.Build) void {
.name = example.name, .name = example.name,
.target = example.target, .target = example.target,
.optimize = optimize, .optimize = optimize,
.root_source_file = .{ .path = example.file }, .root_source_file = b.path(example.file),
}); });
// `install_firmware()` is the MicroZig pendant to `Build.installArtifact()` // `install_firmware()` is the MicroZig pendant to `Build.installArtifact()`

@ -20,7 +20,7 @@ pub fn build(b: *std.Build) void {
.name = example.name, .name = example.name,
.target = example.target, .target = example.target,
.optimize = optimize, .optimize = optimize,
.root_source_file = .{ .path = example.file }, .root_source_file = b.path(example.file),
}); });
// `install_firmware()` is the MicroZig pendant to `Build.installArtifact()` // `install_firmware()` is the MicroZig pendant to `Build.installArtifact()`

@ -21,7 +21,7 @@ pub fn build(b: *std.Build) void {
.name = example.name, .name = example.name,
.target = example.target, .target = example.target,
.optimize = optimize, .optimize = optimize,
.root_source_file = .{ .path = example.file }, .root_source_file = b.path(example.file),
}); });
// `install_firmware()` is the MicroZig pendant to `Build.installArtifact()` // `install_firmware()` is the MicroZig pendant to `Build.installArtifact()`

@ -21,7 +21,7 @@ pub fn build(b: *Build) void {
.name = example.name, .name = example.name,
.target = example.target, .target = example.target,
.optimize = optimize, .optimize = optimize,
.root_source_file = .{ .path = example.file }, .root_source_file = b.path(example.file),
}); });
// `install_firmware()` is the MicroZig pendant to `Build.installArtifact()` // `install_firmware()` is the MicroZig pendant to `Build.installArtifact()`

@ -20,7 +20,7 @@ pub fn build(b: *std.Build) void {
.name = example.name, .name = example.name,
.target = example.target, .target = example.target,
.optimize = optimize, .optimize = optimize,
.root_source_file = .{ .path = example.file }, .root_source_file = b.path(example.file),
}); });
// `install_firmware()` is the MicroZig pendant to `Build.installArtifact()` // `install_firmware()` is the MicroZig pendant to `Build.installArtifact()`

@ -42,7 +42,7 @@ pub fn build(b: *std.Build) void {
.name = example.name, .name = example.name,
.target = example.target, .target = example.target,
.optimize = optimize, .optimize = optimize,
.root_source_file = .{ .path = example.file }, .root_source_file = b.path(example.file),
}); });
// `install_firmware()` is the MicroZig pendant to `Build.installArtifact()` // `install_firmware()` is the MicroZig pendant to `Build.installArtifact()`

@ -97,7 +97,7 @@ pub fn main() void {
}) catch unreachable; }) catch unreachable;
pio.sm_set_enabled(sm, true); pio.sm_set_enabled(sm, true);
var rng_src = std.rand.DefaultPrng.init(0x1234); var rng_src = std.Random.DefaultPrng.init(0x1234);
const rng = rng_src.random(); const rng = rng_src.random();

@ -3,7 +3,10 @@ const MicroZig = @import("microzig/build");
const stm32 = @import("microzig/bsp/stmicro/stm32"); const stm32 = @import("microzig/bsp/stmicro/stm32");
const available_examples = [_]Example{ const available_examples = [_]Example{
.{ .target = stm32.chips.stm32f103x8, .name = "stm32f103x8", .file = "src/blinky.zig" }, // error: ld.lld: section '.text' will not fit in region 'flash0': overflowed by 73532 bytes
// error: ld.lld: section '.ARM.exidx' will not fit in region 'flash0': overflowed by 74148 bytes
// error: ld.lld: section '.data' will not fit in region 'flash0': overflowed by 86028 bytes
// TODO: .{ .target = stm32.chips.stm32f103x8, .name = "stm32f103x8", .file = "src/blinky.zig" },
// TODO: .{ .target = stm32.chips.stm32f303vc, .name = "stm32f303vc", .file = "src/blinky.zig" }, // TODO: .{ .target = stm32.chips.stm32f303vc, .name = "stm32f303vc", .file = "src/blinky.zig" },
// TODO: .{ .target = stm32.chips.stm32f407vg, .name = "stm32f407vg", .file = "src/blinky.zig" }, // TODO: .{ .target = stm32.chips.stm32f407vg, .name = "stm32f407vg", .file = "src/blinky.zig" },
// TODO: .{ .target = stm32.chips.stm32f429zit6u, .name = "stm32f429zit6u", .file = "src/blinky.zig" }, // TODO: .{ .target = stm32.chips.stm32f429zit6u, .name = "stm32f429zit6u", .file = "src/blinky.zig" },
@ -27,7 +30,7 @@ pub fn build(b: *std.Build) void {
.name = example.name, .name = example.name,
.target = example.target, .target = example.target,
.optimize = optimize, .optimize = optimize,
.root_source_file = .{ .path = example.file }, .root_source_file = b.path(example.file),
}); });
// `install_firmware()` is the MicroZig pendant to `Build.installArtifact()` // `install_firmware()` is the MicroZig pendant to `Build.installArtifact()`

@ -19,11 +19,27 @@
"flake-compat_2": { "flake-compat_2": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1673956053, "lastModified": 1696426674,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-compat_3": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra", "owner": "edolstra",
"repo": "flake-compat", "repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -37,11 +53,11 @@
"systems": "systems" "systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1701680307, "lastModified": 1710146030,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725", "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -51,12 +67,51 @@
} }
}, },
"flake-utils_2": { "flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_3": {
"inputs": {
"systems": "systems_3"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_4": {
"inputs": {
"systems": "systems_4"
},
"locked": { "locked": {
"lastModified": 1659877975, "lastModified": 1705309234,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -65,13 +120,46 @@
"type": "github" "type": "github"
} }
}, },
"gitignore": {
"inputs": {
"nixpkgs": [
"zls",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"langref": {
"flake": false,
"locked": {
"narHash": "sha256-O6p2tiKD8ZMhSX+DeA/o5hhAvcPkU2J9lFys/r11peY=",
"type": "file",
"url": "https://raw.githubusercontent.com/ziglang/zig/0fb2015fd3422fc1df364995f9782dfe7255eccd/doc/langref.html.in"
},
"original": {
"type": "file",
"url": "https://raw.githubusercontent.com/ziglang/zig/0fb2015fd3422fc1df364995f9782dfe7255eccd/doc/langref.html.in"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1704766047, "lastModified": 1719957072,
"narHash": "sha256-q9tH9yvUWVBh5XpWafpCYAYf72ZyNhfmpgfR4fwM6uw=", "narHash": "sha256-gvFhEf5nszouwLAkT9nWsDzocUTqLWHuL++dvNjMp9I=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "cc2f101c016d42b728a9cb8244215a5d2d98f6df", "rev": "7144d6241f02d171d25fba3edeaf15e0f2592105",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -83,16 +171,32 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1702350026, "lastModified": 1708161998,
"narHash": "sha256-A+GNZFZdfl4JdDphYKBJ5Ef1HOiFsP18vQe9mqjmUis=", "narHash": "sha256-6KnemmUorCvlcAvGziFosAVkrlWZGIc6UNT9GUYr0jQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "84d981bae8b5e783b3b548de505b22880559515f",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1718208800,
"narHash": "sha256-US1tAChvPxT52RV8GksWZS415tTS7PV42KTc2PNDBmc=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "9463103069725474698139ab10f17a9d125da859", "rev": "cc54fb41d13736e92229c21627ea4f22199fee6b",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "NixOS",
"ref": "nixos-23.05", "ref": "nixos-24.05",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
@ -102,7 +206,8 @@
"flake-compat": "flake-compat", "flake-compat": "flake-compat",
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"zig": "zig" "zig": "zig",
"zls": "zls"
} }
}, },
"systems": { "systems": {
@ -120,6 +225,51 @@
"type": "github" "type": "github"
} }
}, },
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_3": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_4": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"zig": { "zig": {
"inputs": { "inputs": {
"flake-compat": "flake-compat_2", "flake-compat": "flake-compat_2",
@ -127,11 +277,34 @@
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
"lastModified": 1704283725, "lastModified": 1720527051,
"narHash": "sha256-sRWv8au/59BZpWpqqC8PaGDC9bUNhRIMzanF1zPnXNQ=", "narHash": "sha256-87aaUnHa8PzRlnQUR2mLn7BouthbhimExlPdlgu5C0E=",
"owner": "mitchellh",
"repo": "zig-overlay",
"rev": "7789c58ba03f3eb018e7cf60bbcdff2e1e9eb643",
"type": "github"
},
"original": {
"owner": "mitchellh",
"repo": "zig-overlay",
"type": "github"
}
},
"zig-overlay": {
"inputs": {
"flake-compat": "flake-compat_3",
"flake-utils": "flake-utils_4",
"nixpkgs": [
"zls",
"nixpkgs"
]
},
"locked": {
"lastModified": 1718539737,
"narHash": "sha256-hvQ900gSqzGnJWMRQwv65TixciIbC44iX0Nh5ENRwCU=",
"owner": "mitchellh", "owner": "mitchellh",
"repo": "zig-overlay", "repo": "zig-overlay",
"rev": "f06e268e24a71922ff8b20c94cff1d2afcbd4ab5", "rev": "6eb42ce6f85d247b1aecf854c45d80902821d0ad",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -139,6 +312,28 @@
"repo": "zig-overlay", "repo": "zig-overlay",
"type": "github" "type": "github"
} }
},
"zls": {
"inputs": {
"flake-utils": "flake-utils_3",
"gitignore": "gitignore",
"langref": "langref",
"nixpkgs": "nixpkgs_3",
"zig-overlay": "zig-overlay"
},
"locked": {
"lastModified": 1720349156,
"narHash": "sha256-eTjMZ/PEkzR+68C1hUwz9Qh/gizxwNG5PkMaDgplEZk=",
"owner": "zigtools",
"repo": "zls",
"rev": "fbd8b9a87a3cd5ab8389054815d9e3f81dfd430b",
"type": "github"
},
"original": {
"owner": "zigtools",
"repo": "zls",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

@ -8,6 +8,9 @@
# required for latest zig # required for latest zig
zig.url = "github:mitchellh/zig-overlay"; zig.url = "github:mitchellh/zig-overlay";
zls.url = "github:zigtools/zls";
# Used for shell.nix # Used for shell.nix
flake-compat = { flake-compat = {
url = github:edolstra/flake-compat; url = github:edolstra/flake-compat;
@ -26,6 +29,7 @@
# Other overlays # Other overlays
(final: prev: { (final: prev: {
zigpkgs = inputs.zig.packages.${prev.system}; zigpkgs = inputs.zig.packages.${prev.system};
zls = inputs.zls.packages.${prev.system}.zls;
}) })
]; ];
@ -84,7 +88,8 @@
rec { rec {
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
nativeBuildInputs = [ nativeBuildInputs = [
pkgs.zigpkgs."0.11.0" pkgs.zigpkgs."0.13.0"
pkgs.zls
(python3.withPackages (ps: [ (python3.withPackages (ps: [
ps.dataclasses_json ps.dataclasses_json
ps.marshmallow ps.marshmallow

@ -16,7 +16,7 @@ pub fn build(b: *Build) !void {
const regz = b.addExecutable(.{ const regz = b.addExecutable(.{
.name = "regz", .name = "regz",
.root_source_file = .{ .path = "src/main.zig" }, .root_source_file = b.path("src/main.zig"),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
@ -24,7 +24,7 @@ pub fn build(b: *Build) !void {
b.installArtifact(regz); b.installArtifact(regz);
const exported_module = b.addModule("regz", .{ const exported_module = b.addModule("regz", .{
.root_source_file = .{ .path = "src/module.zig" }, .root_source_file = b.path("src/module.zig"),
}); });
exported_module.linkLibrary(libxml2_dep.artifact("xml2")); exported_module.linkLibrary(libxml2_dep.artifact("xml2"));
@ -39,9 +39,7 @@ pub fn build(b: *Build) !void {
const contextualize_fields = b.addExecutable(.{ const contextualize_fields = b.addExecutable(.{
.name = "contextualize-fields", .name = "contextualize-fields",
.root_source_file = .{ .root_source_file = b.path("src/contextualize-fields.zig"),
.path = "src/contextualize-fields.zig",
},
.target = b.host, .target = b.host,
}); });
contextualize_fields.linkLibrary(libxml2_dep.artifact("xml2")); contextualize_fields.linkLibrary(libxml2_dep.artifact("xml2"));
@ -54,9 +52,7 @@ pub fn build(b: *Build) !void {
const characterize = b.addExecutable(.{ const characterize = b.addExecutable(.{
.name = "characterize", .name = "characterize",
.root_source_file = .{ .root_source_file = b.path("src/characterize.zig"),
.path = "src/characterize.zig",
},
.target = b.host, .target = b.host,
}); });
characterize.linkLibrary(libxml2_dep.artifact("xml2")); characterize.linkLibrary(libxml2_dep.artifact("xml2"));
@ -65,9 +61,7 @@ pub fn build(b: *Build) !void {
characterize_step.dependOn(&characterize_run.step); characterize_step.dependOn(&characterize_run.step);
const tests = b.addTest(.{ const tests = b.addTest(.{
.root_source_file = .{ .root_source_file = b.path("src/Database.zig"),
.path = "src/Database.zig",
},
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });

@ -12,8 +12,8 @@
}, },
.dependencies = .{ .dependencies = .{
.libxml2 = .{ .libxml2 = .{
.url = "https://github.com/mattnite/zig-build-libxml2/archive/fca6bbd7f73914acaea685c544d91608797546a8.tar.gz", .url = "https://github.com/mattnite/zig-build-libxml2/archive/fab68b5fb06704ef4bdaa221726493a4b6af04b5.tar.gz",
.hash = "1220c3e12fc08c12d6fc52bcc0ae8b180a69abc08212350e2708d4851879f4c814da", .hash = "122084531ab8ba877a0178fb177a61f6dc9bed56bdcdfb11ad362f352680c04d84cb",
}, },
}, },
} }

@ -763,7 +763,7 @@ pub fn add_child(
}); });
assert(db.entity_is(entity_location, child_id)); assert(db.entity_is(entity_location, child_id));
comptime var it = std.mem.tokenize(u8, entity_location, "."); comptime var it = std.mem.tokenizeScalar(u8, entity_location, '.');
// the tables are in plural form but "type.peripheral" feels better to me // the tables are in plural form but "type.peripheral" feels better to me
// for calling this function // for calling this function
_ = comptime it.next(); _ = comptime it.next();
@ -796,7 +796,7 @@ pub fn add_device_property(
// TODO: assert that entity is only found in one table // TODO: assert that entity is only found in one table
pub fn entity_is(db: Database, comptime entity_location: []const u8, id: EntityId) bool { pub fn entity_is(db: Database, comptime entity_location: []const u8, id: EntityId) bool {
comptime var it = std.mem.tokenize(u8, entity_location, "."); comptime var it = std.mem.tokenizeScalar(u8, entity_location, '.');
// the tables are in plural form but "type.peripheral" feels better to me // the tables are in plural form but "type.peripheral" feels better to me
// for calling this function // for calling this function
const group = comptime (it.next() orelse unreachable) ++ "s"; const group = comptime (it.next() orelse unreachable) ++ "s";
@ -811,7 +811,7 @@ pub fn get_entity_id_by_name(
comptime entity_location: []const u8, comptime entity_location: []const u8,
name: []const u8, name: []const u8,
) !EntityId { ) !EntityId {
comptime var tok_it = std.mem.tokenize(u8, entity_location, "."); comptime var tok_it = std.mem.tokenizeScalar(u8, entity_location, '.');
// the tables are in plural form but "type.peripheral" feels better to me // the tables are in plural form but "type.peripheral" feels better to me
// for calling this function // for calling this function
const group = comptime (tok_it.next() orelse unreachable) ++ "s"; const group = comptime (tok_it.next() orelse unreachable) ++ "s";

@ -519,7 +519,7 @@ fn assign_modes_to_entity(
return; return;
}; };
var tok_it = std.mem.tokenize(u8, mode_names, " "); var tok_it = std.mem.tokenizeScalar(u8, mode_names, ' ');
while (tok_it.next()) |mode_str| { while (tok_it.next()) |mode_str| {
for (mode_set.keys()) |mode_id| { for (mode_set.keys()) |mode_id| {
if (db.attrs.name.get(mode_id)) |name| if (db.attrs.name.get(mode_id)) |name|

@ -77,7 +77,7 @@ pub fn write_comment(allocator: Allocator, comment: []const u8, writer: anytype)
defer tokenized.deinit(); defer tokenized.deinit();
var first = true; var first = true;
var tok_it = std.mem.tokenize(u8, comment, "\n\r \t"); var tok_it = std.mem.tokenizeAny(u8, comment, "\n\r \t");
while (tok_it.next()) |token| { while (tok_it.next()) |token| {
if (!first) if (!first)
first = false first = false
@ -90,7 +90,7 @@ pub fn write_comment(allocator: Allocator, comment: []const u8, writer: anytype)
const unescaped = try std.mem.replaceOwned(u8, allocator, tokenized.items, "\\n", "\n"); const unescaped = try std.mem.replaceOwned(u8, allocator, tokenized.items, "\\n", "\n");
defer allocator.free(unescaped); defer allocator.free(unescaped);
var line_it = std.mem.tokenize(u8, unescaped, "\n"); var line_it = std.mem.tokenizeScalar(u8, unescaped, '\n');
while (line_it.next()) |line| while (line_it.next()) |line|
try writer.print("/// {s}\n", .{line}); try writer.print("/// {s}\n", .{line});
} }
@ -98,7 +98,7 @@ pub fn write_comment(allocator: Allocator, comment: []const u8, writer: anytype)
fn write_string(str: []const u8, writer: anytype) !void { fn write_string(str: []const u8, writer: anytype) !void {
if (std.mem.containsAtLeast(u8, str, 1, "\n")) { if (std.mem.containsAtLeast(u8, str, 1, "\n")) {
try writer.writeByte('\n'); try writer.writeByte('\n');
var line_it = std.mem.split(u8, str, "\n"); var line_it = std.mem.splitScalar(u8, str, '\n');
while (line_it.next()) |line| while (line_it.next()) |line|
try writer.print("\\\\{s}\n", .{line}); try writer.print("\\\\{s}\n", .{line});
} else { } else {
@ -511,7 +511,7 @@ fn write_mode_enum_and_fn(
defer components.deinit(); defer components.deinit();
const mode = db.types.modes.get(mode_id).?; const mode = db.types.modes.get(mode_id).?;
var tok_it = std.mem.tokenize(u8, mode.qualifier, "."); var tok_it = std.mem.tokenizeScalar(u8, mode.qualifier, '.');
while (tok_it.next()) |token| while (tok_it.next()) |token|
try components.append(token); try components.append(token);
@ -526,7 +526,7 @@ fn write_mode_enum_and_fn(
}); });
try writer.writeAll("switch (value) {\n"); try writer.writeAll("switch (value) {\n");
tok_it = std.mem.tokenize(u8, mode.value, " "); tok_it = std.mem.tokenizeScalar(u8, mode.value, ' ');
while (tok_it.next()) |token| { while (tok_it.next()) |token| {
const value = try std.fmt.parseInt(u64, token, 0); const value = try std.fmt.parseInt(u64, token, 0);
try writer.print("{},\n", .{value}); try writer.print("{},\n", .{value});

@ -75,7 +75,7 @@ fn entity_type_to_string(entity_type: Database.EntityType) []const u8 {
}; };
} }
const string_to_entity_type_map = std.ComptimeStringMap(Database.EntityType, .{ const string_to_entity_type_map = std.StaticStringMap(Database.EntityType).initComptime(.{
.{ "peripherals", .peripheral }, .{ "peripherals", .peripheral },
.{ "register_groups", .register_group }, .{ "register_groups", .register_group },
.{ "registers", .register }, .{ "registers", .register },
@ -166,7 +166,7 @@ fn resolve_enums(ctx: *LoadContext) !void {
fn ref_to_id(db: Database, ref: []const u8) !EntityId { fn ref_to_id(db: Database, ref: []const u8) !EntityId {
// TODO: do proper tokenization since we'll need to handle @"" fields. okay to leave for now. // TODO: do proper tokenization since we'll need to handle @"" fields. okay to leave for now.
var it = std.mem.tokenize(u8, ref, "."); var it = std.mem.tokenizeScalar(u8, ref, '.');
const first = it.next() orelse return error.Malformed; const first = it.next() orelse return error.Malformed;
return if (std.mem.eql(u8, "types", first)) blk: { return if (std.mem.eql(u8, "types", first)) blk: {
var tmp_id: ?EntityId = null; var tmp_id: ?EntityId = null;

@ -44,7 +44,7 @@ const Context = struct {
} }
}; };
const svd_boolean = std.ComptimeStringMap(bool, .{ const svd_boolean = std.StaticStringMap(bool).initComptime(.{
.{ "true", true }, .{ "true", true },
.{ "1", true }, .{ "1", true },
.{ "false", false }, .{ "false", false },
@ -680,7 +680,7 @@ const BitRange = struct {
const bit_range_opt = node.get_value("bitRange"); const bit_range_opt = node.get_value("bitRange");
if (bit_range_opt) |bit_range_str| { if (bit_range_opt) |bit_range_str| {
var it = std.mem.tokenize(u8, bit_range_str, "[:]"); var it = std.mem.tokenizeAny(u8, bit_range_str, "[:]");
const msb = try std.fmt.parseInt(u8, it.next() orelse return error.NoMsb, 0); const msb = try std.fmt.parseInt(u8, it.next() orelse return error.NoMsb, 0);
const lsb = try std.fmt.parseInt(u8, it.next() orelse return error.NoLsb, 0); const lsb = try std.fmt.parseInt(u8, it.next() orelse return error.NoLsb, 0);

@ -36,18 +36,18 @@ pub fn build(b: *std.Build) void {
const elf2uf2 = b.addExecutable(.{ const elf2uf2 = b.addExecutable(.{
.name = "elf2uf2", .name = "elf2uf2",
.root_source_file = .{ .path = "src/elf2uf2.zig" }, .root_source_file = b.path("src/elf2uf2.zig"),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
b.installArtifact(elf2uf2); b.installArtifact(elf2uf2);
_ = b.addModule("uf2", .{ _ = b.addModule("uf2", .{
.root_source_file = .{ .path = "src/uf2.zig" }, .root_source_file = b.path("src/uf2.zig"),
}); });
const main_tests = b.addTest(.{ const main_tests = b.addTest(.{
.root_source_file = .{ .path = "src/uf2.zig" }, .root_source_file = b.path("src/uf2.zig"),
}); });
const run_main_tests = b.addRunArtifact(main_tests); const run_main_tests = b.addRunArtifact(main_tests);
@ -56,7 +56,7 @@ pub fn build(b: *std.Build) void {
const gen = b.addExecutable(.{ const gen = b.addExecutable(.{
.name = "gen", .name = "gen",
.root_source_file = .{ .path = "src/gen.zig" }, .root_source_file = b.path("src/gen.zig"),
.target = b.host, .target = b.host,
}); });
const gen_run_step = b.addRunArtifact(gen); const gen_run_step = b.addRunArtifact(gen);
@ -65,7 +65,7 @@ pub fn build(b: *std.Build) void {
const example = b.addExecutable(.{ const example = b.addExecutable(.{
.name = "example", .name = "example",
.root_source_file = .{ .path = "src/example.zig" }, .root_source_file = b.path("src/example.zig"),
.target = b.host, .target = b.host,
}); });
b.installArtifact(example); b.installArtifact(example);

Loading…
Cancel
Save