-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
116 lines (93 loc) · 3.76 KB
/
Copy pathbuild.zig
File metadata and controls
116 lines (93 loc) · 3.76 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
114
115
116
const std = @import("std");
const Modules = struct {
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
const Module = struct {
name: []const u8,
mod: *std.Build.Module,
fn addImport(lhs: *const Module, rhs: *const Module) void {
lhs.mod.addImport(rhs.name, rhs.mod);
}
};
fn init(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) Modules {
return .{
.b = b,
.target = target,
.optimize = optimize,
};
}
fn create(self: Modules, name: []const u8, source_file: []const u8) Module {
return .{
.name = name,
.mod = self.b.createModule(.{
.target = self.target,
.optimize = self.optimize,
.root_source_file = self.b.path(source_file),
}),
};
}
};
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const stdlib_path = b.getInstallPath(.lib, "");
const options = b.addOptions();
options.addOption([]const u8, "stdlib_path", stdlib_path);
const options_mod = options.createModule();
const modules = Modules.init(b, target, optimize);
const zag_mod = modules.create("zag", "src/main.zig");
const exe = b.addExecutable(.{
.name = "zag",
.root_module = zag_mod.mod,
});
const utils_mod = modules.create("utils", "src/utils.zig");
const lexer_mod = modules.create("Lexer", "src/Lexer.zig");
const parser_mod = modules.create("Parser", "src/parser/Parser.zig");
const ast_mod = modules.create("ast", "src/ast/ast.zig");
const compiler_mod = modules.create("Compiler", "src/compiler/Compiler.zig");
zag_mod.mod.addImport("build_options", options_mod);
compiler_mod.mod.addImport("build_options", options_mod);
zag_mod.addImport(&lexer_mod);
zag_mod.addImport(&parser_mod);
zag_mod.addImport(&compiler_mod);
zag_mod.addImport(&utils_mod);
parser_mod.addImport(&utils_mod);
parser_mod.addImport(&ast_mod);
lexer_mod.addImport(&utils_mod);
compiler_mod.addImport(&utils_mod);
compiler_mod.addImport(&lexer_mod);
compiler_mod.addImport(&ast_mod);
parser_mod.addImport(&lexer_mod);
ast_mod.addImport(&utils_mod);
ast_mod.addImport(&lexer_mod);
compiler_mod.addImport(&parser_mod);
const cli = b.dependency("cli", .{});
const cli_mod = cli.module("cli");
exe.root_module.addImport("cli", cli_mod);
const pretty = b.dependency("pretty", .{});
const pretty_mod = pretty.module("pretty");
exe.root_module.addImport("pretty", pretty_mod);
compiler_mod.mod.addImport("pretty", pretty_mod);
const install_bin = b.step("install-bin", "Install the zag compiler to the system bin directory");
const install_exe = b.addInstallArtifact(exe, .{});
install_bin.dependOn(&install_exe.step);
const install_stdlib = b.step("install-stdlib", "Copy the Zag standard library to the system directory");
const copy = b.addInstallDirectory(.{
.source_dir = b.path("lib"), // stdlib .zag files live in lib/ in the repo
.install_dir = .lib,
.install_subdir = "",
});
install_stdlib.dependOn(©.step);
const install_all = b.getInstallStep();
install_all.dependOn(install_bin);
install_all.dependOn(install_stdlib);
b.installArtifact(exe);
const run_step = b.step("run", "Run the app");
const run_cmd = b.addRunArtifact(exe);
run_step.dependOn(&run_cmd.step);
run_cmd.step.dependOn(install_all);
if (b.args) |args| run_cmd.addArgs(args);
const check = b.step("check", "Check if zag compiles");
check.dependOn(&exe.step);
}