forked from Rexicon226/osmium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
122 lines (100 loc) · 4.22 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright (c) 2024, David Rubin <[email protected]>
//
// SPDX-License-Identifier: GPL-3.0-only
const std = @import("std");
const cases = @import("tests/cases.zig");
pub fn build(b: *std.Build) !void {
const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{});
const exe = b.addExecutable(.{
.name = "osmium",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const exe_install = b.addInstallArtifact(exe, .{
.dest_dir = .{ .override = .{ .custom = "." } },
});
b.getInstallStep().dependOn(&exe_install.step);
const trace = b.option(
bool,
"trace",
"Enables tracing of the compiler using the default backend (spall)",
) orelse false;
const backend: TraceBackend = bend: {
if (trace) {
break :bend b.option(
TraceBackend,
"trace-backend",
"Switch between what backend to use. None is default.",
) orelse .None;
}
break :bend .None;
};
const use_llvm = b.option(bool, "use-llvm", "Uses llvm to compile Osmium. Default true.") orelse true;
exe.use_llvm = use_llvm;
exe.use_lld = use_llvm;
const enable_logging = b.option(bool, "log", "Enable debug logging.") orelse false;
const enable_debug_extensions = b.option(
bool,
"debug-extensions",
"Enable commands and options useful for debugging the compiler",
) orelse (optimize == .Debug);
const enable_debug = b.option(bool, "debug", "Builds a VM debugger into the program") orelse false;
const exe_options = b.addOptions();
exe_options.addOption(bool, "trace", trace);
exe_options.addOption(TraceBackend, "backend", backend);
exe_options.addOption(bool, "enable_logging", enable_logging);
exe_options.addOption(usize, "src_file_trimlen", std.fs.path.dirname(std.fs.path.dirname(@src().file).?).?.len);
exe_options.addOption(bool, "enable_debug_extensions", enable_debug_extensions);
exe_options.addOption(bool, "build_debug", enable_debug);
exe.root_module.addOptions("options", exe_options);
exe_options.addOption([]const u8, "lib_path", b.fmt("{s}/python/Lib", .{b.install_path}));
const tracer_dep = b.dependency("tracer", .{ .optimize = optimize, .target = target });
const libgc_dep = b.dependency("libgc", .{ .optimize = optimize, .target = target });
const cpython_dep = b.dependency("cpython", .{ .optimize = optimize, .target = target });
exe.root_module.addImport("tracer", tracer_dep.module("tracer"));
exe.root_module.addImport("gc", libgc_dep.module("gc"));
exe.root_module.addImport("cpython", cpython_dep.module("cpython"));
if (enable_debug) {
if (b.lazyDependency("libvaxis", .{ .optimize = optimize, .target = target })) |libvaxis| {
exe.root_module.addImport("vaxis", libvaxis.module("vaxis"));
}
}
const libpython_install = b.addInstallDirectory(.{
.source_dir = cpython_dep.builder.dependency("python", .{}).path("Lib"),
.install_dir = .{ .custom = "python" },
.install_subdir = "Lib",
});
exe.step.dependOn(&libpython_install.step);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| run_cmd.addArgs(args);
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const opcode_step = b.step("opcode", "Generate opcodes");
generateOpCode(b, opcode_step);
const test_step = b.step("test", "Test Osmium");
try cases.addCases(b, target, test_step, exe, cpython_dep.artifact("cpython"));
test_step.dependOn(&libpython_install.step);
}
const TraceBackend = enum {
Spall,
Chrome,
None,
};
fn generateOpCode(
b: *std.Build,
step: *std.Build.Step,
) void {
const translator = b.addExecutable(.{
.name = "opcode2zig",
.root_source_file = b.path("tools/opcode2zig.zig"),
.target = b.graph.host,
.optimize = .ReleaseFast,
});
const run_cmd = b.addRunArtifact(translator);
run_cmd.addArg("vendor/opcode.h");
run_cmd.addArg("src/compiler/opcodes.zig");
step.dependOn(&run_cmd.step);
}