Skip to content

Commit c8b12f2

Browse files
authored
generate embassy on the fly now (#536)
* generate embassy on the fly now * fix CI * directory fix
1 parent f0f3696 commit c8b12f2

File tree

1,767 files changed

+2074
-588600
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,767 files changed

+2074
-588600
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
with:
9090
version: ${{ env.ZIG_VERSION }}
9191
- name: Generate Code
92-
run: zig build -Dgenerate
92+
run: zig build generate
9393
working-directory: port/stmicro/stm32
9494
- name: Check for code diffs
9595
run: |

build-internals/build.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ pub const Chip = struct {
124124

125125
/// Use the provided file directly as the chip file.
126126
zig: LazyPath,
127+
128+
/// Path to embassy stm32-data directory
129+
embassy: LazyPath,
127130
},
128131

129132
/// The memory regions that are present in this chip.

build.zig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,37 @@ pub fn MicroBuild(port_select: PortSelect) type {
445445
regz_run.addFileArg(file);
446446
break :blk chips_dir.path(b, b.fmt("{s}.zig", .{target.chip.name}));
447447
},
448+
.embassy => |path| blk: {
449+
const regz_run = b.addRunArtifact(regz_exe);
450+
451+
regz_run.addArg("--microzig");
452+
regz_run.addArg("--format");
453+
regz_run.addArg(@tagName(target.chip.register_definition));
454+
455+
regz_run.addArg("--output_path"); // Write to a file
456+
457+
const chips_dir = regz_run.addOutputDirectoryArg("chips");
458+
var patches = std.ArrayList(regz.patch.Patch).init(b.allocator);
459+
460+
// From chip definition
461+
patches.appendSlice(target.chip.patches) catch @panic("OOM");
462+
463+
// From user invoking `add_firmware`
464+
patches.appendSlice(options.patches) catch @panic("OOM");
465+
466+
if (patches.items.len > 0) {
467+
// write patches to file
468+
const patch_ndjson = serialize_patches(b, patches.items);
469+
const write_file_step = b.addWriteFiles();
470+
const patch_file = write_file_step.add("patch.ndjson", patch_ndjson);
471+
472+
regz_run.addArg("--patch_path");
473+
regz_run.addFileArg(patch_file);
474+
}
475+
476+
regz_run.addDirectoryArg(path);
477+
break :blk chips_dir.path(b, b.fmt("{s}.zig", .{target.chip.name}));
478+
},
448479

449480
.zig => |src| src,
450481
};

port/stmicro/stm32/build.zig

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,28 @@ pub fn init(dep: *std.Build.Dependency) Self {
5151
}
5252

5353
pub fn build(b: *std.Build) !void {
54-
const generate = b.option(bool, "generate", "Generate chip definitions from embassy-rs/stm32-data-generated") orelse false;
54+
const stm32_data_generated = b.lazyDependency("stm32-data-generated", .{}) orelse return;
5555

56-
if (generate) {
57-
const stm32_data_generated = b.lazyDependency("stm32-data-generated", .{}) orelse return;
56+
const generate_optimize = .ReleaseSafe;
57+
const regz_dep = b.dependency("microzig/tools/regz", .{
58+
.optimize = generate_optimize,
59+
});
60+
const regz = regz_dep.module("regz");
5861

59-
const generate_optimize = .ReleaseSafe;
60-
const regz_dep = b.dependency("microzig/tools/regz", .{
61-
.optimize = generate_optimize,
62-
});
63-
const regz = regz_dep.module("regz");
62+
const generate_exe = b.addExecutable(.{
63+
.name = "generate",
64+
.root_source_file = b.path("src/generate.zig"),
65+
.target = b.graph.host,
66+
.optimize = generate_optimize,
67+
});
68+
generate_exe.root_module.addImport("regz", regz);
6469

65-
const generate_exe = b.addExecutable(.{
66-
.name = "generate",
67-
.root_source_file = b.path("src/generate.zig"),
68-
.target = b.graph.host,
69-
.optimize = generate_optimize,
70-
});
71-
generate_exe.root_module.addImport("regz", regz);
70+
const generate_run = b.addRunArtifact(generate_exe);
71+
generate_run.max_stdio_size = std.math.maxInt(usize);
72+
generate_run.addFileArg(stm32_data_generated.path("."));
7273

73-
const generate_run = b.addRunArtifact(generate_exe);
74-
generate_run.max_stdio_size = std.math.maxInt(usize);
75-
generate_run.addFileArg(stm32_data_generated.path("."));
76-
b.getInstallStep().dependOn(&generate_run.step);
77-
} else {
78-
_ = b.step("test", "Run platform agnostic unit tests");
79-
}
74+
const generate_step = b.step("generate", "Generate chips file 'src/Chips.zig'");
75+
generate_step.dependOn(&generate_run.step);
76+
77+
_ = b.step("test", "Run platform agnostic unit tests");
8078
}

port/stmicro/stm32/build.zig.zon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
.@"stm32-data-generated" = .{
99
.url = "git+https://github.com/embassy-rs/stm32-data-generated.git#5198a6e36b24f6d79c4ac91af5e61e8d54667d88",
1010
.hash = "N-V-__8AAFi8WBlOh-NikHFVBjzQE0F1KixgKjVWYnlijPNm",
11-
.lazy = true,
1211
},
1312
},
1413
.paths = .{

0 commit comments

Comments
 (0)