This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.zig
70 lines (57 loc) · 2.06 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
const std = @import("std");
const Dependency = std.Build.Dependency;
const CompileStep = std.Build.CompileStep;
const FileSource = std.Build.FileSource;
const uf2 = @import("src/uf2.zig");
pub const FamilyId = uf2.FamilyId;
pub fn from_elf(dep: *Dependency, exe: *CompileStep, opts: uf2.Options) FileSource {
std.debug.assert(!opts.bundle_source); // TODO: bundle source in UF2 File
const b = dep.builder;
const elf2uf2 = dep.artifact("elf2uf2");
const run = b.addRunArtifact(elf2uf2);
// family id
if (opts.family_id) |family_id| {
inline for (@typeInfo(uf2.FamilyId).Enum.fields) |field| {
if (@field(uf2.FamilyId, field.name) == family_id) {
run.addArgs(&.{ "--family-id", field.name });
}
}
}
// elf file
run.addArg("--elf-path");
run.addArtifactArg(exe);
// output file
return run.addPrefixedOutputFileArg("--output-path", "test.uf2");
}
pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const elf2uf2 = b.addExecutable(.{
.name = "elf2uf2",
.root_source_file = .{ .path = "src/elf2uf2.zig" },
.target = target,
.optimize = optimize,
});
b.installArtifact(elf2uf2);
_ = b.addModule("uf2", .{
.source_file = .{ .path = "src/uf2.zig" },
});
const main_tests = b.addTest(.{
.root_source_file = .{ .path = "src/uf2.zig" },
});
const run_main_tests = b.addRunArtifact(main_tests);
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&run_main_tests.step);
const gen = b.addExecutable(.{
.name = "gen",
.root_source_file = .{ .path = "src/gen.zig" },
});
const gen_run_step = b.addRunArtifact(gen);
const gen_step = b.step("gen", "Generate family id enum");
gen_step.dependOn(&gen_run_step.step);
const example = b.addExecutable(.{
.name = "example",
.root_source_file = .{ .path = "src/example.zig" },
});
b.installArtifact(example);
}