-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.zig
92 lines (81 loc) · 2.45 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const std = @import("std");
const Builder = std.build.Builder;
const dbuild = @import("src/common/dbuild.zig");
const dcommon = @import("src/common/dcommon.zig");
pub fn build(b: *Builder) !void {
const board = try dbuild.getBoard(b);
var target = dbuild.crossTargetFor(board);
target.os_tag = .uefi;
if (target.cpu_arch.? == .riscv64) {
try buildRiscv64(b, board, target);
return;
}
const exe = b.addExecutable(bootName(b, board, target), "src/dainboot.zig");
exe.setTarget(target);
exe.setBuildMode(b.standardReleaseOptions());
try dbuild.addBuildOptions(b, exe, board);
exe.addPackagePath("dtb", "../dtb/src/dtb.zig");
exe.install();
b.default_step.dependOn(&exe.step);
}
fn buildRiscv64(b: *Builder, board: dcommon.Board, target: std.zig.CrossTarget) !void {
const crt0 = b.addAssemble("crt0-efi-riscv64", "src/crt0-efi-riscv64.S");
crt0.setTarget(std.zig.CrossTarget{
.cpu_arch = target.cpu_arch,
.os_tag = .freestanding,
});
crt0.setBuildMode(b.standardReleaseOptions());
const obj = b.addObject(bootName(b, board, target), "src/dainboot.zig");
obj.setTarget(target);
obj.setBuildMode(b.standardReleaseOptions());
try dbuild.addBuildOptions(b, obj, board);
obj.addPackagePath("dtb", "../dtb/src/dtb.zig");
const combined = b.addSystemCommand(&.{
"ld.lld",
"-nostdlib",
"-znocombreloc",
"-T",
"elf_riscv64_efi.lds",
"-shared",
"-Bsymbolic",
"-o",
"combined.o",
"-s",
});
combined.addArtifactArg(crt0);
combined.addArtifactArg(obj);
try std.fs.cwd().makePath("zig-cache/bin");
const efi = b.addSystemCommand(&.{
"llvm-objcopy",
"-j",
".header",
"-j",
".text",
"-j",
".plt",
"-j",
".sdata",
"-j",
".data",
"-j",
".dynamic",
"-j",
".dynstr",
"-j",
".dynsym",
"-j",
".rel*",
"-j",
".rela*",
"-j",
".reloc",
"--output-target=binary",
"combined.o",
"zig-cache/bin/BOOTRISCV64.qemu_riscv64.efi",
});
efi.step.dependOn(&combined.step);
b.default_step.dependOn(&efi.step);
}
fn bootName(b: *Builder, board: dcommon.Board, target: std.zig.CrossTarget) []const u8 {
return b.fmt("BOOT{s}.{s}", .{ dbuild.efiTagFor(target.cpu_arch.?), @tagName(board) });
}