-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
71 lines (60 loc) · 2.36 KB
/
build.zig
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
const std = @import("std");
const stm32f4 = std.zig.CrossTarget{
.cpu_arch = .thumb,
.cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m3 },
.os_tag = .freestanding,
.abi = .eabi,
};
const examples = [_]Example{
.{ .name = "stm32-app", .target = stm32f4, .root_file = "src/app_main.zig", .linker_script = "src/chip/link_app.lds" },
.{ .name = "stm32-zboot", .target = stm32f4, .root_file = "src/main.zig", .linker_script = "src/chip/link.lds" },
};
pub fn build(b: *std.Build) void {
const optimize = .ReleaseSmall;
const zboot_tool = b.addExecutable(.{
.name = "zboot",
.optimize = .ReleaseSmall,
.target = b.host,
.root_source_file = b.path("zboot.zig"),
});
for (examples) |example| {
const elf = b.addExecutable(.{
.name = b.fmt("{s}{s}", .{ example.name, ".elf" }),
.root_source_file = b.path(example.root_file),
.target = b.resolveTargetQuery(stm32f4),
.optimize = optimize,
.strip = false, // do not strip debug symbols
});
elf.setLinkerScript(b.path(example.linker_script));
elf.addCSourceFile(.{ .file = b.path("src/chip/start.s"), .flags = &.{} });
// Copy the elf to the output directory.
const copy_elf = b.addInstallArtifact(elf, .{});
b.default_step.dependOn(©_elf.step);
// Convert the hex from the elf
const hex = b.addObjCopy(elf.getEmittedBin(), .{ .format = .hex });
hex.step.dependOn(&elf.step);
// Copy the hex to the output directory
const copy_hex = b.addInstallBinFile(
hex.getOutput(),
b.fmt("{s}{s}", .{ example.name, ".hex" }),
);
b.default_step.dependOn(©_hex.step);
// Convert the bin form the elf
const bin = b.addObjCopy(elf.getEmittedBin(), .{ .format = .bin });
bin.step.dependOn(&elf.step);
// Copy the bin to the output directory
const copy_bin = b.addInstallBinFile(
bin.getOutput(),
b.fmt("{s}{s}", .{ example.name, ".bin" }),
);
b.default_step.dependOn(©_bin.step);
zboot_tool.step.dependOn(©_bin.step);
}
b.installArtifact(zboot_tool);
}
const Example = struct {
target: std.zig.CrossTarget,
name: []const u8,
root_file: []const u8,
linker_script: []const u8,
};