Skip to content
Merged
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
5 changes: 3 additions & 2 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# use_nix
use_flake
if has nix; then
use flake
fi
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.zig text=auto eol=lf
flake.lock -diff
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Setup Zig
uses: goto-bus-stop/setup-zig@v2
with:
version: 0.12.0
version: 0.13.0

- name: Build
run: zig build -Doptimize=ReleaseSmall
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup Zig
uses: goto-bus-stop/setup-zig@v2
with:
version: 0.12.0
version: 0.13.0

- name: Extract version
run: echo "MICROZIG_VERSION=$(zig build package -- get-version)" >> $GITHUB_ENV
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
zig-out/
zig-cache/
.zig-cache/
microzig-deploy/
.DS_Store
.gdbinit
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## What version of Zig to use

Zig 0.12.0
Zig 0.13.0

## Getting Started With MicroZig

Expand Down
2 changes: 1 addition & 1 deletion bsp/espressif/esp/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn path(comptime suffix: []const u8) std.Build.LazyPath {
const esp_riscv = .{
.name = "Espressif RISC-V",
.root_source_file = path("/src/cpus/espressif-riscv.zig"),
.target = std.zig.CrossTarget{
.target = std.Target.Query{
.cpu_arch = .riscv32,
.cpu_model = .{ .explicit = &std.Target.riscv.cpu.generic_rv32 },
.cpu_features_add = std.Target.riscv.featureSet(&.{
Expand Down
2 changes: 1 addition & 1 deletion bsp/microchip/atsam/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub const chips = struct {
.url = "https://www.microchip.com/en-us/product/ATSAMD51J19A",
.cpu = MicroZig.cpus.cortex_m4,
.register_definition = .{
.atdf = .{ .path = build_root ++ "/src/chips/ATSAMD51J19A.atdf" },
.atdf = .{ .cwd_relative = build_root ++ "/src/chips/ATSAMD51J19A.atdf" },
},
.memory_regions = &.{
.{ .kind = .flash, .offset = 0x00000000, .length = 512 * 1024 }, // Embedded Flash
Expand Down
10 changes: 5 additions & 5 deletions bsp/raspberrypi/rp2040/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const build_root = root();

pub fn build(b: *Build) !void {
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 test_step = b.step("test", "Run platform agnostic unit tests");
Expand Down Expand Up @@ -119,7 +119,7 @@ pub const BootROM = union(enum) {
};

const linker_script = .{
.path = build_root ++ "/rp2040.ld",
.cwd_relative = build_root ++ "/rp2040.ld",
};

const hal = .{
Expand Down Expand Up @@ -188,8 +188,8 @@ pub fn get_bootrom(mz: *MicroZig, rom: BootROM) Stage2Bootloader {
.root_source_file = null,
});
//rom_exe.linkage = .static;
rom_exe.setLinkerScript(.{ .path = build_root ++ "/src/bootroms/shared/stage2.ld" });
rom_exe.addAssemblyFile(.{ .path = rom_path });
rom_exe.setLinkerScript(.{ .cwd_relative = build_root ++ "/src/bootroms/shared/stage2.ld" });
rom_exe.addAssemblyFile(.{ .cwd_relative = rom_path });
rom_exe.entry = .{ .symbol_name = "_stage2_boot" };

break :blk rom_exe;
Expand Down
28 changes: 12 additions & 16 deletions bsp/raspberrypi/rp2040/src/hal/pio/assembler/tokenizer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
.{ "define", get_define },
.{ "origin", get_origin },
Expand Down Expand Up @@ -527,7 +527,7 @@ pub const Tokenizer = struct {

fn get_jmp(self: *Tokenizer, diags: *?Diagnostics) TokenizeError!Token.Instruction.Payload {
const Condition = Token.Instruction.Jmp.Condition;
const conditions = std.ComptimeStringMap(Condition, .{
const conditions = std.StaticStringMap(Condition).initComptime(.{
.{ "!x", .x_is_zero },
.{ "x--", .x_dec },
.{ "!y", .y_is_zero },
Expand Down Expand Up @@ -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 },
.{ "jmp", get_jmp },
.{ "wait", get_wait },
Expand Down Expand Up @@ -1588,7 +1588,7 @@ test "tokenize.instr.jmp.value" {

test "tokenize.instr.jmp.conditions" {
const Condition = Token.Instruction.Jmp.Condition;
const cases = std.ComptimeStringMap(Condition, .{
const cases = std.StaticStringMap(Condition).initComptime(.{
.{ "!x", .x_is_zero },
.{ "x--", .x_dec },
.{ "!y", .y_is_zero },
Expand All @@ -1598,9 +1598,7 @@ test "tokenize.instr.jmp.conditions" {
.{ "!osre", .osre_not_empty },
});

inline for (cases.kvs) |case| {
const op = case.key;
const cond = case.value;
inline for (comptime cases.keys(), comptime cases.values()) |op, cond| {
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));
Expand Down Expand Up @@ -1762,16 +1760,14 @@ test "tokenize.instr.mov" {
}

const Operation = Token.Instruction.Mov.Operation;
const operations = std.ComptimeStringMap(Operation, .{
const operations = std.StaticStringMap(Operation).initComptime(.{
.{ "!", .invert },
.{ "~", .invert },
.{ "::", .bit_reverse },
});

inline for (.{ "", " " }) |space| {
inline for (operations.kvs) |kv| {
const str = kv.key;
const operation = kv.value;
inline for (comptime operations.keys(), comptime operations.values()) |str, operation| {
const tokens = try bounded_tokenize(comptime std.fmt.comptimePrint("mov x {s}{s}y", .{
str,
space,
Expand All @@ -1792,23 +1788,23 @@ test "tokenize.instr.irq" {
wait: bool,
};

const modes = std.ComptimeStringMap(ClearWait, .{
const modes = std.StaticStringMap(ClearWait).initComptime(.{
.{ "", .{ .clear = false, .wait = false } },
.{ "set", .{ .clear = false, .wait = false } },
.{ "nowait", .{ .clear = false, .wait = false } },
.{ "wait", .{ .clear = false, .wait = true } },
.{ "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} {}", .{
kv.key,
key,
num,
}));

try expect_instr_irq(.{
.clear = kv.value.clear,
.wait = kv.value.wait,
.clear = value.clear,
.wait = value.wait,
.num = num,
}, tokens.get(0));
}
Expand Down
10 changes: 5 additions & 5 deletions bsp/raspberrypi/rp2040/src/hal/random.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const std = @import("std");
const assert = std.debug.assert;
const Random = std.rand.Random;
const Random = std.Random;

const microzig = @import("microzig");
const peripherals = microzig.chip.peripherals;
Expand All @@ -20,11 +20,11 @@ const peripherals = microzig.chip.peripherals;
/// for security systems because the ROSC as entropy source can be
/// compromised. However, it promises at least equal distribution.
pub const Ascon = struct {
state: std.rand.Ascon,
state: Random.Ascon,
counter: usize = 0,

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() {
// Ensure that the system clocks run from the XOSC and/or PLLs
Expand All @@ -38,10 +38,10 @@ pub const Ascon = struct {
var b: [secret_seed_length]u8 = undefined;
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 {
return Random.init(self, fill);
}
Expand Down
8 changes: 4 additions & 4 deletions bsp/stmicro/stm32/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub const boards = struct {
.chip = chips.stm32f303vc.chip,
.board = .{
.name = "STM32F3DISCOVERY",
.root_source_file = .{ .path = build_root ++ "/src/boards/STM32F3DISCOVERY.zig" },
.root_source_file = .{ .cwd_relative = build_root ++ "/src/boards/STM32F3DISCOVERY.zig" },
},
};

Expand All @@ -199,7 +199,7 @@ pub const boards = struct {
.chip = chips.stm32f407vg.chip,
.board = .{
.name = "STM32F4DISCOVERY",
.root_source_file = .{ .path = build_root ++ "/src/boards/STM32F4DISCOVERY.zig" },
.root_source_file = .{ .cwd_relative = build_root ++ "/src/boards/STM32F4DISCOVERY.zig" },
},
};

Expand All @@ -208,7 +208,7 @@ pub const boards = struct {
.chip = chips.stm32f407vg.chip,
.board = .{
.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" },
},
};

Expand All @@ -217,7 +217,7 @@ pub const boards = struct {
.chip = chips.stm32f429zit6u.chip,
.board = .{
.name = "STM32F429IDISCOVERY",
.root_source_file = .{ .path = build_root ++ "/src/boards/STM32F429IDISCOVERY.zig" },
.root_source_file = .{ .cwd_relative = build_root ++ "/src/boards/STM32F429IDISCOVERY.zig" },
},
};
};
Expand Down
7 changes: 4 additions & 3 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.{
.name = "microzig",
.version = "0.12.1",
.version = "0.13.0",
.minimum_zig_version = "0.13.0",
.dependencies = .{
// packages within the monorepo so that others can reach them
.build = .{ .path = "build" },
Expand Down Expand Up @@ -29,8 +30,8 @@

// used for creating package tarballs
.boxzer = .{
.url = "https://github.com/mattnite/boxzer/archive/74f17daa97f6861c31b30a5070136216c08eb39b.tar.gz",
.hash = "1220a14c01a66c023d8944dc672edd5121f98f82196fefbc09a13bcadb96e1c8e7f1",
.url = "https://github.com/mattnite/boxzer/archive/6bd6636d780f626af1c40a27be2680e223965c8a.tar.gz",
.hash = "1220432ca3323f0a7033fd84df6d0f2d66aecf4c5301b3ac70c96cca8b0938164f17",
},
},

Expand Down
7 changes: 5 additions & 2 deletions build/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn build(b: *Build) !void {
const uf2_dep = b.dependency("microzig/tools/uf2", .{});

const build_test = b.addTest(.{
.root_source_file = .{ .path = "build.zig" },
.root_source_file = b.path("build.zig"),
});

build_test.root_module.addAnonymousImport("uf2", .{
Expand All @@ -39,6 +39,9 @@ pub fn build(b: *Build) !void {
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.
pub fn init(b: *Build, opts: struct {
dependency_name: []const u8 = "microzig/build",
Expand All @@ -53,7 +56,7 @@ pub fn init(b: *Build, opts: struct {
.microzig_core = core_dep,
.generate_linkerscript = mz_dep.builder.addExecutable(.{
.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,
}),
};
Expand Down
2 changes: 1 addition & 1 deletion build/definitions/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const LazyPath = Build.LazyPath;

pub fn build(b: *Build) void {
_ = b.addModule("definitions", .{
.root_source_file = .{ .path = "build.zig" },
.root_source_file = b.path("build.zig"),
});
}

Expand Down
24 changes: 12 additions & 12 deletions core/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub fn build(b: *std.Build) !void {
pub const cpus = struct {
pub const avr5 = MicroZig.Cpu{
.name = "AVR5",
.root_source_file = .{ .path = build_root ++ "/src/cpus/avr5.zig" },
.target = std.zig.CrossTarget{
.root_source_file = .{ .cwd_relative = build_root ++ "/src/cpus/avr5.zig" },
.target = std.Target.Query{
.cpu_arch = .avr,
.cpu_model = .{ .explicit = &std.Target.avr.cpu.avr5 },
.os_tag = .freestanding,
Expand All @@ -29,8 +29,8 @@ pub const cpus = struct {

pub const cortex_m0 = MicroZig.Cpu{
.name = "ARM Cortex-M0",
.root_source_file = .{ .path = build_root ++ "/src/cpus/cortex_m.zig" },
.target = std.zig.CrossTarget{
.root_source_file = .{ .cwd_relative = build_root ++ "/src/cpus/cortex_m.zig" },
.target = std.Target.Query{
.cpu_arch = .thumb,
.cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m0 },
.os_tag = .freestanding,
Expand All @@ -40,8 +40,8 @@ pub const cpus = struct {

pub const cortex_m0plus = MicroZig.Cpu{
.name = "ARM Cortex-M0+",
.root_source_file = .{ .path = build_root ++ "/src/cpus/cortex_m.zig" },
.target = std.zig.CrossTarget{
.root_source_file = .{ .cwd_relative = build_root ++ "/src/cpus/cortex_m.zig" },
.target = std.Target.Query{
.cpu_arch = .thumb,
.cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m0plus },
.os_tag = .freestanding,
Expand All @@ -51,8 +51,8 @@ pub const cpus = struct {

pub const cortex_m3 = MicroZig.Cpu{
.name = "ARM Cortex-M3",
.root_source_file = .{ .path = build_root ++ "/src/cpus/cortex_m.zig" },
.target = std.zig.CrossTarget{
.root_source_file = .{ .cwd_relative = build_root ++ "/src/cpus/cortex_m.zig" },
.target = std.Target.Query{
.cpu_arch = .thumb,
.cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m3 },
.os_tag = .freestanding,
Expand All @@ -62,8 +62,8 @@ pub const cpus = struct {

pub const cortex_m4 = MicroZig.Cpu{
.name = "ARM Cortex-M4",
.root_source_file = .{ .path = build_root ++ "/src/cpus/cortex_m.zig" },
.target = std.zig.CrossTarget{
.root_source_file = .{ .cwd_relative = build_root ++ "/src/cpus/cortex_m.zig" },
.target = std.Target.Query{
.cpu_arch = .thumb,
.cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m4 },
.os_tag = .freestanding,
Expand All @@ -73,8 +73,8 @@ pub const cpus = struct {

pub const riscv32_imac = MicroZig.Cpu{
.name = "RISC-V 32-bit",
.root_source_file = .{ .path = build_root ++ "/src/cpus/riscv32.zig" },
.target = std.zig.CrossTarget{
.root_source_file = .{ .cwd_relative = build_root ++ "/src/cpus/riscv32.zig" },
.target = std.Target.Query{
.cpu_arch = .riscv32,
.cpu_model = .{ .explicit = &std.Target.riscv.cpu.sifive_e21 },
.os_tag = .freestanding,
Expand Down
2 changes: 1 addition & 1 deletion examples/espressif/esp/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn build(b: *std.Build) void {
.name = example.name,
.target = example.target,
.optimize = optimize,
.root_source_file = .{ .path = example.file },
.root_source_file = b.path(example.file),
});

// `installFirmware()` is the MicroZig pendant to `Build.installArtifact()`
Expand Down
Loading