-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkg.zig
79 lines (71 loc) · 3.1 KB
/
pkg.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
72
73
74
75
76
77
78
79
const std = @import("std");
pub fn Pkg(comptime path: []const u8) type {
const ChipMapped = struct {
build_func: fn (*std.build.Builder, *std.build.LibExeObjStep) anyerror!void,
processor: []const u8,
};
const chip_map = std.ComptimeStringMap(ChipMapped, .{
.{ "atmega32u4", .{
.build_func = @import("src/chips/atmega32u4/build.zig").build(path),
.processor = "avr5",
} },
.{ "gd32f310", .{
.build_func = @import("src/chips/gd32f310/build.zig").build(path),
.processor = "cortex-m",
} },
});
return struct {
var zbed = std.build.Pkg{
.name = "zbed",
.source = .{ .path = path ++ "/src/zbed.zig" },
};
/// Adds zbed to a step
pub fn addTo(b: *std.build.Builder, step: *std.build.LibExeObjStep, chip: []const u8) !void {
const processor = chip_map.get(chip).?.processor;
zbed.dependencies = &[_]std.build.Pkg{
std.build.Pkg{
.name = "zbed_chip",
.source = .{ .path = try std.fs.path.join(b.allocator, &[_][]const u8{ path, "/src/chips/", chip, "/chip.zig" }) },
.dependencies = &[_]std.build.Pkg{
.{
.name = "zbed",
.source = .{ .path = path ++ "/src/zbed.zig" },
},
.{
.name = "zbed_processor",
.source = .{ .path = try std.fs.path.join(b.allocator, &[_][]const u8{ path, "/src/processors/", processor, "/processor.zig" }) },
.dependencies = &[_]std.build.Pkg{
.{
.name = "zbed",
.source = .{ .path = path ++ "/src/zbed.zig" },
},
},
},
},
},
.{
.name = "zbed_processor",
.source = .{ .path = try std.fs.path.join(b.allocator, &[_][]const u8{ path, "/src/processors/", processor, "/processor.zig" }) },
.dependencies = &[_]std.build.Pkg{
.{
.name = "zbed",
.source = .{ .path = path ++ "/src/zbed.zig" },
},
.{
.name = "zbed_chip",
.source = .{ .path = try std.fs.path.join(b.allocator, &[_][]const u8{ path, "/src/chips/", chip, "/chip.zig" }) },
},
},
},
};
step.addPackage(zbed);
// Set some defaults on the step
step.strip = false;
step.single_threaded = true;
step.bundle_compiler_rt = true;
step.link_gc_sections = true;
// Add the chip-specific build function
try chip_map.get(chip).?.build_func(b, step);
}
};
}