forked from wasm3/wasm3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zig
84 lines (77 loc) · 2.43 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
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const libm3_only = b.option(bool, "libm3", "Build libwasm3 only") orelse false;
const libwasm3 = b.addStaticLibrary(.{
.name = "m3",
.target = target,
.optimize = optimize,
});
libwasm3.root_module.sanitize_c = false; // fno-sanitize=undefined
libwasm3.defineCMacro("d_m3HasTracer", null);
if (libwasm3.rootModuleTarget().isWasm()) {
if (libwasm3.rootModuleTarget().os.tag == .wasi) {
libwasm3.defineCMacro("d_m3HasWASI", null);
libwasm3.linkSystemLibrary("wasi-emulated-process-clocks");
}
}
libwasm3.addIncludePath(b.path("source"));
libwasm3.addCSourceFiles(.{
.files = &.{
"source/m3_api_libc.c",
"source/extensions/m3_extensions.c",
"source/m3_api_meta_wasi.c",
"source/m3_api_tracer.c",
"source/m3_api_uvwasi.c",
"source/m3_api_wasi.c",
"source/m3_bind.c",
"source/m3_code.c",
"source/m3_compile.c",
"source/m3_core.c",
"source/m3_env.c",
"source/m3_exec.c",
"source/m3_function.c",
"source/m3_info.c",
"source/m3_module.c",
"source/m3_parse.c",
},
.flags = if (libwasm3.rootModuleTarget().isWasm())
&cflags ++ [_][]const u8{
"-Xclang",
"-target-feature",
"-Xclang",
"+tail-call",
}
else
&cflags,
});
libwasm3.linkSystemLibrary("m");
libwasm3.linkLibC();
if (!libm3_only) {
const wasm3 = b.addExecutable(.{
.name = "wasm3",
.target = target,
.optimize = optimize,
});
for (libwasm3.root_module.include_dirs.items) |dir| {
wasm3.addIncludePath(dir.path);
}
wasm3.addCSourceFile(.{
.file = .{ .cwd_relative = "platforms/app/main.c" },
.flags = &cflags,
});
wasm3.linkLibrary(libwasm3);
b.installArtifact(wasm3);
} else b.installArtifact(libwasm3);
}
const cflags = [_][]const u8{
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wparentheses",
"-Wundef",
"-Wpointer-arith",
"-Wstrict-aliasing=2",
"-std=gnu11",
};