-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
130 lines (118 loc) · 3.72 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
123
124
125
126
127
128
129
130
const std = @import("std");
fn addDefines(c: *std.Build.Step.Compile, b: *std.Build) void {
c.root_module.addCMacro("CONFIG_BIGNUM", "1");
c.root_module.addCMacro("_GNU_SOURCE", "1");
_ = b;
}
fn addStdLib(c: *std.Build.Step.Compile, cflags: []const []const u8, root: *std.Build.Dependency) void {
if (c.rootModuleTarget().os.tag == .wasi) {
c.root_module.addCMacro("_WASI_EMULATED_PROCESS_CLOCKS", "1");
c.root_module.addCMacro("_WASI_EMULATED_SIGNAL", "1");
c.linkSystemLibrary("wasi-emulated-process-clocks");
c.linkSystemLibrary("wasi-emulated-signal");
}
c.addCSourceFiles(.{ .files = &.{"quickjs-libc.c"}, .flags = cflags, .root = root.path(".") });
}
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const include_stdlib = b.option(bool, "stdlib", "include stdlib in library") orelse true;
const csrc = b.dependency("quickjs-ng", .{});
const cflags = &.{
"-Wno-implicit-fallthrough",
"-Wno-sign-compare",
"-Wno-missing-field-initializers",
"-Wno-unused-parameter",
"-Wno-unused-but-set-variable",
"-Wno-array-bounds",
"-Wno-format-truncation",
"-funsigned-char",
"-fwrapv",
};
const libquickjs_source = &.{
"quickjs.c",
"libregexp.c",
"libunicode.c",
"cutils.c",
"libbf.c",
};
const libquickjs = b.addStaticLibrary(.{
.name = "quickjs",
.target = target,
.optimize = optimize,
});
libquickjs.addCSourceFiles(.{
.files = libquickjs_source,
.flags = cflags,
.root = csrc.path("."),
});
addDefines(libquickjs, b);
if (include_stdlib) {
addStdLib(libquickjs, cflags, csrc);
}
libquickjs.linkLibC();
b.installArtifact(libquickjs);
const qjsc = b.addExecutable(.{
.name = "qjsc",
.target = target,
.optimize = optimize,
});
qjsc.addCSourceFiles(.{
.files = &.{"qjsc.c"},
.flags = cflags,
.root = csrc.path("."),
});
qjsc.linkLibrary(libquickjs);
addDefines(qjsc, b);
if (!include_stdlib) {
addStdLib(qjsc, cflags, csrc);
}
b.installArtifact(qjsc);
const qjsc_host = b.addExecutable(.{
.name = "qjsc-host",
.target = b.graph.host,
.optimize = .Debug,
});
qjsc_host.addCSourceFiles(.{
.files = &.{"qjsc.c"},
.flags = cflags,
.root = csrc.path("."),
});
qjsc_host.addCSourceFiles(.{
.files = libquickjs_source,
.flags = cflags,
.root = csrc.path("."),
});
addStdLib(qjsc_host, cflags, csrc);
addDefines(qjsc_host, b);
qjsc_host.linkLibC();
const header = b.addTranslateC(.{
.root_source_file = csrc.path("quickjs.h"),
.target = target,
.optimize = optimize,
});
_ = b.addModule("quickjs-ng", .{ .root_source_file = header.getOutput() });
const gen_repl = b.addRunArtifact(qjsc_host);
gen_repl.addArg("-o");
const gen_repl_out = gen_repl.addOutputFileArg("repl.c");
gen_repl.addArg("-m");
gen_repl.addFileArg(csrc.path("repl.js"));
const qjs = b.addExecutable(.{ .name = "qjs", .target = target, .optimize = optimize });
qjs.addCSourceFiles(.{
.files = &.{"qjs.c"},
.flags = cflags,
.root = csrc.path("."),
});
qjs.addCSourceFiles(.{
.files = &.{"repl.c"},
.root = gen_repl_out.dirname(),
.flags = cflags,
});
if (!include_stdlib) {
addStdLib(qjs, cflags, csrc);
}
qjs.linkLibrary(libquickjs);
addDefines(qjs, b);
qjs.step.dependOn(&gen_repl.step);
b.installArtifact(qjs);
}