-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
113 lines (97 loc) · 3.49 KB
/
build.zig
File metadata and controls
113 lines (97 loc) · 3.49 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
102
103
104
105
106
107
108
109
110
111
112
113
const std = @import("std");
const fs = std.fs;
const mem = std.mem;
const ArrayList = std.ArrayList;
const Dir = fs.Dir;
const IterableDir = fs.IterableDir;
const Target = std.Target;
const Feature = Target.Cpu.Feature;
const CrossTarget = std.zig.CrossTarget;
const features = Target.x86.Feature;
var manager = std.heap.GeneralPurposeAllocator(.{}){};
var heap = manager.allocator();
const cp_cmd_str = [_][]const u8{ "cp", "zig-out/bin/BOOTX64.efi", "uefi/shared/EFI/BOOT/BOOTX64.EFI" };
const run_cmd_str = [_][]const u8{
"qemu-system-x86_64",
"-L",
"uefi/debug",
"-drive",
"file=fat:rw:uefi/shared,format=raw",
"-machine",
"q35,smm=on,accel=kvm",
"-pflash",
"uefi/OVMF.fd",
};
pub fn build(b: *std.Build) void {
var disabled_features = Feature.Set.empty;
var enabled_features = Feature.Set.empty;
disabled_features.addFeature(@intFromEnum(features.mmx));
disabled_features.addFeature(@intFromEnum(features.sse));
disabled_features.addFeature(@intFromEnum(features.sse2));
disabled_features.addFeature(@intFromEnum(features.avx));
disabled_features.addFeature(@intFromEnum(features.avx2));
enabled_features.addFeature(@intFromEnum(features.soft_float));
const target = CrossTarget{
.cpu_arch = Target.Cpu.Arch.x86_64,
.os_tag = Target.Os.Tag.uefi,
.abi = Target.Abi.none,
.cpu_features_sub = disabled_features,
.cpu_features_add = enabled_features,
};
const optimize = .ReleaseFast;
const stub = b.addStaticLibrary(.{
.name = "libstub.a",
.root_source_file = .{ .path = "src/stub.zig" },
.target = target,
.optimize = optimize,
});
b.installArtifact(stub);
const exe = b.addExecutable(.{
.name = "BOOTX64",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
exe.step.dependOn(&stub.step);
exe.linkLibrary(stub);
b.installArtifact(exe);
const cp_cmd = b.addSystemCommand(&cp_cmd_str);
const run_cmd = b.addSystemCommand(&run_cmd_str);
const run_step = b.step("run", "run msfrog run");
cp_cmd.step.dependOn(b.getInstallStep());
run_cmd.step.dependOn(&cp_cmd.step);
run_step.dependOn(&run_cmd.step);
}
fn files(path: []const u8, ext: []const u8) !ArrayList([]const u8) {
var file_list = ArrayList([]const u8).init(heap);
var directory = try fs.cwd().openIterableDir(path, .{});
defer directory.close();
var it = directory.iterate();
while (try it.next()) |entry| {
switch (entry.kind) {
.file => {
if (mem.eql(u8, ext, fs.path.extension(entry.name))) {
const file_path = try fs.path.join(heap, &[_][]const u8{
path,
entry.name,
});
try file_list.append(file_path);
}
},
.directory => {
const directory_path = try fs.path.join(heap, &[_][]const u8{
path,
entry.name,
});
const recursive = try files(directory_path, ext);
try file_list.appendSlice(recursive.items);
recursive.deinit();
heap.free(directory_path);
},
else => {},
}
}
return file_list;
}