-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
68 lines (59 loc) · 1.96 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
const std = @import("std");
const Builder = std.build.Builder;
pub fn build(b: *Builder) !void {
const uno = std.zig.CrossTarget{
.cpu_arch = .avr,
.cpu_model = .{ .explicit = &std.Target.avr.cpu.atmega328p },
.os_tag = .freestanding,
.abi = .none,
};
const exe = b.addExecutable("avr-arduino-zig", "src/start.zig");
const ld = std.build.FileSource{ .path = "avr.ld" };
exe.setTarget(uno);
exe.setBuildMode(.ReleaseSafe);
exe.bundle_compiler_rt = false;
exe.setLinkerScriptPath(ld);
exe.install();
const tty = b.option(
[]const u8,
"tty",
"Specify the port to which the Arduino is connected (defaults to /dev/ttyACM0)",
) orelse "/dev/ttyACM0";
const bin_path = b.getInstallPath(exe.install_step.?.dest_dir, exe.out_filename);
const flash_command = blk: {
var tmp = std.ArrayList(u8).init(b.allocator);
try tmp.appendSlice("-Uflash:w:");
try tmp.appendSlice(bin_path);
try tmp.appendSlice(":e");
break :blk tmp.toOwnedSlice();
};
const upload = b.step("upload", "Upload the code to an Arduino device using avrdude");
const avrdude = b.addSystemCommand(&.{
"avrdude",
"-carduino",
"-patmega328p",
"-D",
"-P",
tty,
flash_command,
"-v",
"-v",
});
upload.dependOn(&avrdude.step);
avrdude.step.dependOn(&exe.install_step.?.step);
const objdump = b.step("objdump", "Show dissassembly of the code using avr-objdump");
const avr_objdump = b.addSystemCommand(&.{
"avr-objdump",
"-dh",
bin_path,
});
objdump.dependOn(&avr_objdump.step);
avr_objdump.step.dependOn(&exe.install_step.?.step);
const monitor = b.step("monitor", "Opens a monitor to the serial output");
const screen = b.addSystemCommand(&.{
"tio",
tty,
});
monitor.dependOn(&screen.step);
b.default_step.dependOn(&exe.step);
}