-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
101 lines (84 loc) · 3.08 KB
/
build.zig
File metadata and controls
101 lines (84 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const std = @import("std");
pub const Board = enum {
blackpill,
uaefi,
uaefi_pro,
};
pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const board = b.option(Board, "board", "Target board") orelse .blackpill;
const cpu_model = switch (board) {
.blackpill, .uaefi => &std.Target.arm.cpu.cortex_m4,
.uaefi_pro => &std.Target.arm.cpu.cortex_m7,
};
const target = b.resolveTargetQuery(.{
.cpu_arch = .thumb,
.cpu_model = .{ .explicit = cpu_model },
.os_tag = .freestanding,
.abi = .eabihf,
});
const board_source = switch (board) {
.blackpill => b.path("src/board/blackpill/board.zig"),
.uaefi => b.path("src/board/uaefi/board.zig"),
.uaefi_pro => b.path("src/board/uaefi_pro/board.zig"),
};
const linker_script = switch (board) {
.blackpill => b.path("linker/stm32f401.ld"),
.uaefi => b.path("linker/stm32f407.ld"),
.uaefi_pro => b.path("linker/stm32f767.ld"),
};
const hal_module = b.createModule(.{
.root_source_file = b.path("src/hal/hal.zig"),
.target = target,
.optimize = optimize,
});
const board_module = b.createModule(.{
.root_source_file = board_source,
.target = target,
.optimize = optimize,
});
board_module.addImport("hal", hal_module);
const engine_module = b.createModule(.{
.root_source_file = b.path("src/engine/engine.zig"),
.target = target,
.optimize = optimize,
});
const elf = b.addExecutable(.{
.name = "zigefi.elf",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
});
elf.root_module.addImport("board", board_module);
elf.root_module.addImport("hal", hal_module);
elf.root_module.addImport("engine", engine_module);
elf.setLinkerScript(linker_script);
b.installArtifact(elf);
// Generate raw .bin for flashing
const bin = b.addObjCopy(elf.getEmittedBin(), .{
.format = .bin,
});
bin.step.dependOn(&elf.step);
const install_bin = b.addInstallBinFile(bin.getOutput(), "zigefi.bin");
const bin_step = b.step("bin", "Generate raw binary for flashing");
bin_step.dependOn(&install_bin.step);
// Flash step (st-flash)
const flash_cmd = b.addSystemCommand(&.{
"st-flash", "write", "zig-out/bin/zigefi.bin", "0x08000000",
});
flash_cmd.step.dependOn(&install_bin.step);
const flash_step = b.step("flash", "Flash firmware via st-flash");
flash_step.dependOn(&flash_cmd.step);
// Unit tests — engine modules run on host (native target)
const engine_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/engine/engine.zig"),
.target = b.graph.host,
}),
});
const run_tests = b.addRunArtifact(engine_tests);
const test_step = b.step("test", "Run engine module unit tests");
test_step.dependOn(&run_tests.step);
}