forked from lightpanda-io/zig-v8-fork
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.zig
More file actions
154 lines (127 loc) · 5.03 KB
/
build.zig
File metadata and controls
154 lines (127 loc) · 5.03 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
const std = @import("std");
const LazyPath = std.Build.LazyPath;
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
var build_opts = b.addOptions();
build_opts.addOption(
bool,
"inspector_subtype",
b.option(bool, "inspector_subtype", "Export default valueSubtype and descriptionForValueSubtype") orelse true,
);
// the module we export as a library
const v8_module = b.addModule("v8", .{
.root_source_file = b.path("src/v8.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.link_libcpp = true,
});
v8_module.addIncludePath(b.path("src"));
v8_module.addImport("default_exports", build_opts.createModule());
const root_path = LazyPath{ .cwd_relative = "." };
const build_path = LazyPath{ .cwd_relative = "./v8/" };
const build_module = b.createModule(.{
.root_source_file = b.path("src/main_build.zig"),
.target = target,
.optimize = optimize,
});
{
// Get V8
const get_v8 = b.addExecutable(.{
.name = "get-v8",
.root_module = build_module,
});
const mkdir_v8_dir = blk: {
var mkdir_v8_dir = b.addSystemCommand(&.{ "mkdir", "-p" });
mkdir_v8_dir.addDirectoryArg(build_path);
mkdir_v8_dir.setCwd(root_path);
break :blk mkdir_v8_dir;
};
const cp_build_files = blk: {
// trailing slash for rsync src is important, but Zig really doesn't
// want to add it, so this is what I came up with.
const build_tools = b.path("build-tools");
const build_tools_path = b.fmt("{f}/", .{build_tools.getPath3(b, null)});
var cp_build_files = b.addSystemCommand(&.{ "rsync", "-r", build_tools_path, "v8" });
cp_build_files.setCwd(root_path);
cp_build_files.step.dependOn(&mkdir_v8_dir.step);
break :blk cp_build_files;
};
const run_get_tools = blk: {
var run_get_tools = b.addSystemCommand(&.{ "/bin/bash", "get_tools.sh" });
run_get_tools.setCwd(build_path);
run_get_tools.step.dependOn(&cp_build_files.step);
break :blk run_get_tools;
};
const run_v8_source = blk: {
var run_v8_source = b.addSystemCommand(&.{ "/bin/bash", "get_v8.sh" });
run_v8_source.setCwd(build_path);
run_v8_source.step.dependOn(&run_get_tools.step);
break :blk run_v8_source;
};
get_v8.step.dependOn(&run_v8_source.step);
// as an installation step
b.installArtifact(get_v8);
// as a command
const run_cmd = b.addRunArtifact(get_v8);
// step
const run_step = b.step("get-v8", "Get v8 source + compilation tools");
run_step.dependOn(&run_cmd.step);
}
{
// build V8
const build_v8 = b.addExecutable(.{
.name = "build-v8",
.root_module = build_module,
});
const run_build = blk: {
var run_build = b.addSystemCommand(&.{ "/bin/bash", "build_v8.sh" });
run_build.addDirectoryArg(b.path("src"));
run_build.addArg(if (optimize == .Debug) "debug" else "release");
run_build.setCwd(build_path);
break :blk run_build;
};
build_v8.step.dependOn(&run_build.step);
// as an installation step
b.installArtifact(build_v8);
// as a command
const run_cmd = b.addRunArtifact(build_v8);
// step
const run_step = b.step("build-v8", "Build v8");
run_step.dependOn(&run_cmd.step);
}
{
const test_module = b.createModule(.{
.root_source_file = b.path("src/v8.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.link_libcpp = true,
});
// test
const tests = b.addTest(.{
.root_module = test_module,
});
tests.root_module.addImport("default_exports", build_opts.createModule());
const release_dir = if (optimize == .Debug) "debug" else "release";
const os = switch (target.result.os.tag) {
.linux => "linux",
.macos => "macos",
else => return error.UnsupportedPlatform,
};
tests.addObjectFile(b.path(b.fmt("v8/out/{s}/{s}/obj/zig/libc_v8.a", .{ os, release_dir })));
tests.addIncludePath(b.path("src"));
switch (target.result.os.tag) {
.macos => {
// v8 has a dependency, abseil-cpp, which, on Mac, uses CoreFoundation
tests.addSystemFrameworkPath(.{ .cwd_relative = "/System/Library/Frameworks" });
tests.linkFramework("CoreFoundation");
},
else => {},
}
const run_tests = b.addRunArtifact(tests);
const tests_step = b.step("test", "Run unit tests");
tests_step.dependOn(&run_tests.step);
}
}