-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
85 lines (74 loc) · 3.14 KB
/
build.zig
File metadata and controls
85 lines (74 loc) · 3.14 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
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardOptimizeOption(.{});
const exe_name: []const u8 = b.option([]const u8, "artifact_name", "Use a custom name for the output executable")
orelse if (mode == .Debug) "limp-debug" else b.fmt("limp-{t}-{t}", .{ target.result.cpu.arch, target.result.os.tag });
const version: std.SemanticVersion = std.SemanticVersion.parse(zon.version) catch @panic("bad version string");
const lua_extraspace = b.fmt("{}", .{ @sizeOf(Temp_Allocator) });
const lua_translate_c = b.addTranslateC(.{
.root_source_file = b.path("lua/headers.h"),
.target = target,
.optimize = .Debug, // translate-c fails on windows for ReleaseSafe
.link_libc = true,
});
lua_translate_c.defineCMacro("LUA_EXTRASPACE", lua_extraspace);
const exe = b.addExecutable(.{
.name = exe_name,
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = mode,
.link_libc = true,
.imports = &.{
.{ .name = "Temp_Allocator", .module = b.dependency("Temp_Allocator", .{}).module("Temp_Allocator") },
.{ .name = "sx", .module = b.dependency("sx", .{}).module("sx") },
.{ .name = "zon", .module = b.createModule(.{ .root_source_file = b.path("build.zig.zon") }), },
.{ .name = "lua_c", .module = lua_translate_c.createModule() },
},
}),
.version = version,
});
exe.root_module.addIncludePath(b.path("lua/"));
exe.root_module.addCMacro("LUA_EXTRASPACE", lua_extraspace);
const lua_c_files = [_][]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",
"lauxlib.c", "lbaselib.c", "lcorolib.c", "ldblib.c",
"liolib.c", "lmathlib.c", "loadlib.c", "loslib.c",
"lstrlib.c", "ltablib.c", "lutf8lib.c", "linit.c",
};
const c_flags = [_][]const u8{
"-std=c99",
"-fno-strict-aliasing",
"-O2",
"-Wall",
"-Wextra",
};
inline for (lua_c_files) |c_file| {
exe.root_module.addCSourceFile(.{
.file = b.path("lua/" ++ c_file),
.flags = &c_flags,
});
}
b.installArtifact(exe);
var run = b.addRunArtifact(exe);
run.step.dependOn(b.getInstallStep());
b.step("run", "run limp").dependOn(&run.step);
if (b.args) |args| {
run.addArgs(args);
}
const tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = mode,
}),
});
b.step("test", "test limp").dependOn(&b.addRunArtifact(tests).step);
}
const zon = @import("build.zig.zon");
const Temp_Allocator = @import("Temp_Allocator").Temp_Allocator;
const std = @import("std");