Repository navigation
Expand file tree
/
Copy pathbuild.zig
More file actions
123 lines (107 loc) · 2.96 KB
/
Copy pathbuild.zig
File metadata and controls
123 lines (107 loc) · 2.96 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
117
118
119
120
121
122
123
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Option to enable internal test instrumentation (ltests.h)
const enable_tests = b.option(bool, "tests", "Enable internal Lua test instrumentation (ltests.h)") orelse false;
const lua_lib = buildLua(b, target, optimize, enable_tests);
b.installArtifact(lua_lib);
const lua_exe = buildInterpreter(b, target, optimize, lua_lib);
b.installArtifact(lua_exe);
// `zig build run` launches the interpreter
const run_cmd = b.addRunArtifact(lua_exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| run_cmd.addArgs(args);
b.step("run", "Run the Lua interpreter").dependOn(&run_cmd.step);
}
const core_sources = [_][]const u8{
"lapi.c",
"lcode.c",
"lctype.c",
"ldebug.c",
"ldo.c",
"ldump.c",
"lfunc.c",
"lgc.c",
"llex.c",
"lmem.c",
"lobject.c",
"lopcodes.c",
"lparser.c",
"lstate.c",
"lstring.c",
"ltable.c",
"ltm.c",
"lundump.c",
"lvm.c",
"lzio.c",
"kulua_record.c",
};
const lib_sources = [_][]const u8{
"lauxlib.c",
"lbaselib.c",
"lcorolib.c",
"ldblib.c",
"linit.c",
"liolib.c",
"lmathlib.c",
"loadlib.c",
"loslib.c",
"lstrlib.c",
"ltablib.c",
"lutf8lib.c",
};
// -ffp-contract=off prevents FMA contraction for deterministic float results
const c_flags: []const []const u8 = &.{
"-std=c99",
"-Wall",
"-Wextra", "-Wno-unused-parameter",
"-ffp-contract=off",
};
const c_flags_tests: []const []const u8 = &.{
"-std=c99",
"-Wall",
"-Wextra", "-Wno-unused-parameter",
"-ffp-contract=off",
"-DLUA_USER_H=\"ltests.h\"",
};
fn buildLua(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
enable_tests: bool,
) *std.Build.Step.Compile {
const lib = b.addLibrary(.{
.name = "lua",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
const flags = if (enable_tests) c_flags_tests else c_flags;
lib.addCSourceFiles(.{ .files = &core_sources, .flags = flags });
lib.addCSourceFiles(.{ .files = &lib_sources, .flags = flags });
if (enable_tests) {
lib.addCSourceFiles(.{ .files = &.{"ltests.c"}, .flags = flags });
}
return lib;
}
fn buildInterpreter(
b: *std.Build,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
lua_lib: *std.Build.Step.Compile,
) *std.Build.Step.Compile {
const exe = b.addExecutable(.{
.name = "lua",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
exe.addCSourceFiles(.{ .files = &.{"lua.c"}, .flags = c_flags });
exe.linkLibrary(lua_lib);
return exe;
}