Skip to content

Commit

Permalink
add packaging to regular checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnite committed Apr 17, 2024
1 parent 5fac2a5 commit 33b2e87
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 1,098 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ jobs:

- name: Build
run: zig build -Doptimize=ReleaseSmall


- name: Unit Test BSPs
run: zig build run-bsp-tests -Doptimize=ReleaseSmall

- name: Dry run packaging
run: zig build package -- https://example.com
run: |
MICROZIG_VERSION=$(zig build package -- get-version)
zig build package -- http://localhost:8000
python3 -m http.server 8000 --directory boxzer-out > http.log &
cd tools/package-test
zig fetch --save=microzig http://localhost:8000/microzig-${MICROZIG_VERSION}.tar.gz
zig build -Doptimize=ReleaseSmall
zig build run-bsp-tests=ReleaseSmall
# clean up server
jobs -p | xargs kill
- name: Upload HTTP logs
uses: actions/upload-artifact
with:
name: http.log
path: http.log
2 changes: 1 addition & 1 deletion bsp/espressif/esp/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ pub const chips = struct {
pub const boards = struct {};

pub fn build(b: *std.Build) void {
_ = b;
_ = b.step("test", "Run platform agnostic unit tests");
}
32 changes: 1 addition & 31 deletions bsp/gigadevice/gd32/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -62,35 +62,5 @@ pub const boards = struct {
};

pub fn build(b: *Build) void {
_ = b;
// const optimize = b.standardOptimizeOption(.{});
// inline for (@typeInfo(boards).Struct.decls) |decl| {
// if (!decl.is_pub)
// continue;

// const exe = microzig.addEmbeddedExecutable(b, .{
// .name = @field(boards, decl.name).name ++ ".minimal",
// .root_source_file = .{
// .path = "test/programs/minimal.zig",
// },
// .backing = .{ .board = @field(boards, decl.name) },
// .optimize = optimize,
// });
// exe.installArtifact(b);
// }

// inline for (@typeInfo(chips).Struct.decls) |decl| {
// if (!decl.is_pub)
// continue;

// const exe = microzig.addEmbeddedExecutable(b, .{
// .name = @field(chips, decl.name).name ++ ".minimal",
// .root_source_file = .{
// .path = "test/programs/minimal.zig",
// },
// .backing = .{ .chip = @field(chips, decl.name) },
// .optimize = optimize,
// });
// exe.installArtifact(b);
// }
_ = b.step("test", "Run platform agnostic unit tests");
}
3 changes: 1 addition & 2 deletions bsp/microchip/atsam/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ const std = @import("std");
const MicroZig = @import("microzig/build");

pub fn build(b: *std.Build) void {
_ = b;
// Dummy func to make package manager happy
_ = b.step("test", "Run platform agnostic unit tests");
}

fn root() []const u8 {
Expand Down
2 changes: 1 addition & 1 deletion bsp/microchip/avr/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ pub const boards = struct {
};

pub fn build(b: *Build) void {
_ = b;
_ = b.step("test", "Run platform agnostic unit tests");
}
2 changes: 1 addition & 1 deletion bsp/nordic/nrf5x/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ pub const boards = struct {
};

pub fn build(b: *Build) void {
_ = b;
_ = b.step("test", "Run platform agnostic unit tests");
}
2 changes: 1 addition & 1 deletion bsp/nxp/lpc/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ fn postprocess(b: *std.Build, input: std.Build.LazyPath) std.Build.LazyPath {
}

pub fn build(b: *std.Build) void {
_ = b;
_ = b.step("test", "Run platform agnostic unit tests");
}
10 changes: 8 additions & 2 deletions bsp/raspberrypi/rp2040/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ fn root() []const u8 {
const build_root = root();

pub fn build(b: *Build) !void {
// TODO: hook up tests
_ = b;
const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/hal.zig" },
});
unit_tests.addIncludePath(.{ .path = "src/hal/pio/assembler" });

const unit_tests_run = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run platform agnostic unit tests");
test_step.dependOn(&unit_tests_run.step);
}

pub const chips = struct {
Expand Down
58 changes: 29 additions & 29 deletions bsp/raspberrypi/rp2040/src/hal/pio/assembler/tokenizer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ const DirectiveTag = @typeInfo(Token.Directive).Union.tag_type.?;
const PayloadTag = @typeInfo(Token.Instruction.Payload).Union.tag_type.?;

fn expect_program(expected: []const u8, actual: Token) !void {
try expectEqual(Token.Tag.program, actual.data);
try expectEqual(Token.Tag.program, @as(Token.Tag, actual.data));
try expectEqualStrings(expected, actual.data.program);
}

Expand All @@ -1173,20 +1173,20 @@ fn expect_opt_value(expected: ?Value, actual: ?Value) !void {
}

fn expect_define(expected: Token.Define, actual: Token) !void {
try expectEqual(Token.Tag.define, actual.data);
try expectEqual(Token.Tag.define, @as(Token.Tag, actual.data));

const define = actual.data.define;
try expectEqualStrings(expected.name, define.name);
try expect_value(expected.value, define.value);
}

fn expect_origin(expected: Value, actual: Token) !void {
try expectEqual(Token.Tag.origin, actual.data);
try expectEqual(Token.Tag.origin, @as(Token.Tag, actual.data));
try expect_value(expected, actual.data.origin);
}

fn expect_side_set(expected: Token.SideSet, actual: Token) !void {
try expectEqual(Token.Tag.side_set, actual.data);
try expectEqual(Token.Tag.side_set, @as(Token.Tag, actual.data));

const side_set = actual.data.side_set;
try expect_value(expected.count, side_set.count);
Expand All @@ -1195,15 +1195,15 @@ fn expect_side_set(expected: Token.SideSet, actual: Token) !void {
}

fn expect_wrap_target(actual: Token) !void {
try expectEqual(Token.Tag.wrap_target, actual.data);
try expectEqual(Token.Tag.wrap_target, @as(Token.Tag, actual.data));
}

fn expect_wrap(actual: Token) !void {
try expectEqual(Token.Tag.wrap, actual.data);
try expectEqual(Token.Tag.wrap, @as(Token.Tag, actual.data));
}

fn expect_lang_opt(expected: Token.LangOpt, actual: Token) !void {
try expectEqual(Token.Tag.lang_opt, actual.data);
try expectEqual(Token.Tag.lang_opt, @as(Token.Tag, actual.data));

const lang_opt = actual.data.lang_opt;
try expectEqualStrings(expected.lang, lang_opt.lang);
Expand All @@ -1212,12 +1212,12 @@ fn expect_lang_opt(expected: Token.LangOpt, actual: Token) !void {
}

fn expect_word(expected: Value, actual: Token) !void {
try expectEqual(Token.Tag.word, actual.data);
try expectEqual(Token.Tag.word, @as(Token.Tag, actual.data));
try expect_value(expected, actual.data.word);
}

fn expect_label(expected: Token.Label, actual: Token) !void {
try expectEqual(Token.Tag.label, actual.data);
try expectEqual(Token.Tag.label, @as(Token.Tag, actual.data));

const label = actual.data.label;
try expectEqual(expected.public, label.public);
Expand All @@ -1230,8 +1230,8 @@ const ExpectedNopInstr = struct {
};

fn expect_instr_nop(expected: ExpectedNopInstr, actual: Token) !void {
try expectEqual(Token.Tag.instruction, actual.data);
try expectEqual(PayloadTag.nop, actual.data.instruction.payload);
try expectEqual(Token.Tag.instruction, @as(Token.Tag, actual.data));
try expectEqual(PayloadTag.nop, @as(PayloadTag, actual.data.instruction.payload));

const instr = actual.data.instruction;
try expect_opt_value(expected.delay, instr.delay);
Expand All @@ -1246,8 +1246,8 @@ const ExpectedSetInstr = struct {
};

fn expect_instr_set(expected: ExpectedSetInstr, actual: Token) !void {
try expectEqual(Token.Tag.instruction, actual.data);
try expectEqual(PayloadTag.set, actual.data.instruction.payload);
try expectEqual(Token.Tag.instruction, @as(Token.Tag, actual.data));
try expectEqual(PayloadTag.set, @as(PayloadTag, actual.data.instruction.payload));

const instr = actual.data.instruction;
try expect_opt_value(expected.delay, instr.delay);
Expand All @@ -1266,8 +1266,8 @@ const ExpectedJmpInstr = struct {
};

fn expect_instr_jmp(expected: ExpectedJmpInstr, actual: Token) !void {
try expectEqual(Token.Tag.instruction, actual.data);
try expectEqual(PayloadTag.jmp, actual.data.instruction.payload);
try expectEqual(Token.Tag.instruction, @as(Token.Tag, actual.data));
try expectEqual(PayloadTag.jmp, @as(PayloadTag, actual.data.instruction.payload));

const instr = actual.data.instruction;
try expect_opt_value(expected.delay, instr.delay);
Expand All @@ -1289,8 +1289,8 @@ const ExpectedWaitInstr = struct {
};

fn expect_instr_wait(expected: ExpectedWaitInstr, actual: Token) !void {
try expectEqual(Token.Tag.instruction, actual.data);
try expectEqual(PayloadTag.wait, actual.data.instruction.payload);
try expectEqual(Token.Tag.instruction, @as(Token.Tag, actual.data));
try expectEqual(PayloadTag.wait, @as(PayloadTag, actual.data.instruction.payload));

const instr = actual.data.instruction;
try expect_opt_value(expected.delay, instr.delay);
Expand All @@ -1310,8 +1310,8 @@ const ExpectedInInstr = struct {
};

fn expect_instr_in(expected: ExpectedInInstr, actual: Token) !void {
try expectEqual(Token.Tag.instruction, actual.data);
try expectEqual(PayloadTag.in, actual.data.instruction.payload);
try expectEqual(Token.Tag.instruction, @as(Token.Tag, actual.data));
try expectEqual(PayloadTag.in, @as(PayloadTag, actual.data.instruction.payload));

const instr = actual.data.instruction;
try expect_opt_value(expected.delay, instr.delay);
Expand All @@ -1330,8 +1330,8 @@ const ExpectedOutInstr = struct {
};

fn expect_instr_out(expected: ExpectedOutInstr, actual: Token) !void {
try expectEqual(Token.Tag.instruction, actual.data);
try expectEqual(PayloadTag.out, actual.data.instruction.payload);
try expectEqual(Token.Tag.instruction, @as(Token.Tag, actual.data));
try expectEqual(PayloadTag.out, @as(PayloadTag, actual.data.instruction.payload));

const instr = actual.data.instruction;
try expect_opt_value(expected.delay, instr.delay);
Expand All @@ -1350,8 +1350,8 @@ const ExpectedPushInstr = struct {
};

fn expect_instr_push(expected: ExpectedPushInstr, actual: Token) !void {
try expectEqual(Token.Tag.instruction, actual.data);
try expectEqual(PayloadTag.push, actual.data.instruction.payload);
try expectEqual(Token.Tag.instruction, @as(Token.Tag, actual.data));
try expectEqual(PayloadTag.push, @as(PayloadTag, actual.data.instruction.payload));

const instr = actual.data.instruction;
try expect_opt_value(expected.delay, instr.delay);
Expand All @@ -1370,8 +1370,8 @@ const ExpectedPullInstr = struct {
};

fn expect_instr_pull(expected: ExpectedPullInstr, actual: Token) !void {
try expectEqual(Token.Tag.instruction, actual.data);
try expectEqual(PayloadTag.pull, actual.data.instruction.payload);
try expectEqual(Token.Tag.instruction, @as(Token.Tag, actual.data));
try expectEqual(PayloadTag.pull, @as(PayloadTag, actual.data.instruction.payload));

const instr = actual.data.instruction;
try expect_opt_value(expected.delay, instr.delay);
Expand All @@ -1391,8 +1391,8 @@ const ExpectedMovInstr = struct {
};

fn expect_instr_mov(expected: ExpectedMovInstr, actual: Token) !void {
try expectEqual(Token.Tag.instruction, actual.data);
try expectEqual(PayloadTag.mov, actual.data.instruction.payload);
try expectEqual(Token.Tag.instruction, @as(Token.Tag, actual.data));
try expectEqual(PayloadTag.mov, @as(PayloadTag, actual.data.instruction.payload));

const instr = actual.data.instruction;
try expect_opt_value(expected.delay, instr.delay);
Expand All @@ -1414,8 +1414,8 @@ const ExpectedIrqInstr = struct {
};

fn expect_instr_irq(expected: ExpectedIrqInstr, actual: Token) !void {
try expectEqual(Token.Tag.instruction, actual.data);
try expectEqual(PayloadTag.irq, actual.data.instruction.payload);
try expectEqual(Token.Tag.instruction, @as(Token.Tag, actual.data));
try expectEqual(PayloadTag.irq, @as(PayloadTag, actual.data.instruction.payload));

const instr = actual.data.instruction;
try expect_opt_value(expected.delay, instr.delay);
Expand Down
3 changes: 1 addition & 2 deletions bsp/stmicro/stm32/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const build_root = root();
const KiB = 1024;

pub fn build(b: *std.Build) !void {
_ = b;
// Dummy func to make package manager happy
_ = b.step("test", "Run platform agnostic unit tests");
}

pub const chips = struct {
Expand Down
6 changes: 6 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ pub fn build(b: *Build) void {
const parts_db = generate_parts_db(b) catch @panic("OOM");
const parts_db_json = b.addInstallFile(parts_db, "parts-db.json");
package_step.dependOn(&parts_db_json.step);

const test_bsps_step = b.step("run-bsp-tests", "Run all platform agnostic tests for BSPs");
inline for (bsps) |bsp| {
const bsp_dep = b.dependency(bsp[0], .{});
test_bsps_step.dependOn(&bsp_dep.builder.top_level_steps.get("test").?.step);
}
}

const PartsDb = struct {
Expand Down
8 changes: 4 additions & 4 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
.version = "0.0.0",
.dependencies = .{
// packages within the monorepo so that others can reach them
.@"build" = .{ .path = "build" },
.build = .{ .path = "build" },
.@"build/definitions" = .{ .path = "build/definitions" },
.@"core" = .{ .path = "core" },
.core = .{ .path = "core" },
.@"tools/regz" = .{ .path = "tools/regz" },
.@"tools/uf2" = .{ .path = "tools/uf2" },
.@"bsp/nordic/nrf5x" = .{ .path = "bsp/nordic/nrf5x" },
Expand All @@ -29,8 +29,8 @@

// used for creating package tarballs
.boxzer = .{
.url = "https://github.com/mattnite/boxzer/archive/b9f08b4c9b1db709af03763ace69761a6482238c.tar.gz",
.hash = "12204fdd9914a6d99abb55366b3a664395a6038d7e6308178c0664158eff9418e188",
.url = "https://github.com/mattnite/boxzer/archive/bb34035d894e8188769b172ce99b5e2c553bcf24.tar.gz",
.hash = "12202844b4808399d7ae9f7857418012c46c73882f607cfa0ad69de19a7d556f1995",
},
},

Expand Down
14 changes: 4 additions & 10 deletions build/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,9 @@ pub const Firmware = struct {
/// Adds a regular dependency to your application.
pub fn add_app_import(fw: *Firmware, name: []const u8, module: *std.Build.Module, options: AppDependencyOptions) void {
if (options.depend_on_microzig) {
module.dependencies.put("microzig", fw.modules.microzig) catch @panic("OOM");
module.addImport("microzig", fw.modules.microzig);
}
fw.modules.app.dependencies.put(name, module) catch @panic("OOM");
fw.modules.app.addImport(name, module);
}

pub fn add_include_path(fw: *Firmware, path: LazyPath) void {
Expand All @@ -500,14 +500,8 @@ pub const Firmware = struct {
fw.artifact.addCSourceFile(source);
}

pub fn add_options(fw: *Firmware, module_name: []const u8, options: *std.Build.OptionsStep) void {
fw.artifact.addOptions(module_name, options);
fw.modules.app.dependencies.put(
module_name,
fw.host_build.createModule(.{
.root_source_file = options.getOutput(),
}),
) catch @panic("OOM");
pub fn add_options(fw: *Firmware, module_name: []const u8, options: *std.Build.Step.Options) void {
fw.modules.app.addOptions(module_name, options);
}

pub fn add_object_file(fw: *Firmware, source: LazyPath) void {
Expand Down
Loading

0 comments on commit 33b2e87

Please sign in to comment.