forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BUILD.gn
284 lines (264 loc) · 6.01 KB
/
BUILD.gn
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
import("//third_party/v8/gni/v8.gni")
import("//third_party/v8/snapshot_toolchain.gni")
import("//build_extra/flatbuffers/flatbuffer.gni")
import("//build_extra/flatbuffers/rust/rust_flatbuffer.gni")
import("//build_extra/deno.gni")
import("//build_extra/rust/rust.gni")
group("default") {
testonly = true
deps = [
":deno",
":deno_ns",
":test_cc",
":test_rs",
]
}
config("deno_config") {
include_dirs = [ "third_party/v8" ] # This allows us to v8/src/base/ libraries.
configs = [ "third_party/v8:external_config" ]
if (is_debug) {
defines = [ "DEBUG" ]
}
# Targets built with the `rust_executable()` template automatically pick up
# these dependencies, but those built with `executable()` need them when they
# have Rust inputs. Currently, there's only one such target, `test_cc`.
if (is_mac) {
libs = [ "resolv" ]
}
if (is_win) {
libs = [ "userenv.lib" ]
}
}
main_extern = [
"$rust_build:futures",
"$rust_build:libc",
"$rust_build:log",
"$rust_build:sha1",
"$rust_build:tempfile",
"$rust_build:tokio",
"$rust_build:tokio_current_thread",
"$rust_build:url",
"//build_extra/flatbuffers/rust:flatbuffers",
":msg_rs",
]
rust_executable("deno") {
source_root = "src/main.rs"
extern = main_extern
deps = [
":libdeno",
]
}
# This target is for fast incremental development.
# When modifying the javascript runtime, this target will not go through the
# extra process of building a snapshot and instead load the bundle from disk.
# ns = no snapshot
rust_executable("deno_ns") {
source_root = "src/main.rs"
extern = main_extern
deps = [
":libdeno_nosnapshot",
]
}
rust_test("test_rs") {
source_root = "src/main.rs"
extern = main_extern
deps = [
":libdeno",
]
}
v8_executable("test_cc") {
testonly = true
sources = [
"src/test.cc",
]
deps = [
":deno_base_test",
"//testing/gtest:gtest",
]
configs = [ ":deno_config" ]
}
static_library("libdeno") {
complete_static_lib = true
sources = [
"src/from_snapshot.cc",
]
inputs = [
"$target_gen_dir/snapshot_deno.bin",
]
deps = [
":create_snapshot_deno",
":deno_bindings",
]
configs += [ ":deno_config" ]
}
# Only functionality needed for libdeno_test and snapshot_creator
# In particular no flatbuffers, no assets, no rust, no msg handlers.
# Because snapshots are slow, it's important that snapshot_creator's
# dependencies are minimal.
v8_source_set("deno_base") {
sources = [
"src/binding.cc",
"src/deno.h",
"src/file_util.cc",
"src/file_util.h",
"src/internal.h",
]
public_deps = [
"third_party/v8:v8_monolith",
]
configs = [ ":deno_config" ]
}
v8_source_set("deno_base_test") {
testonly = true
sources = [
"src/file_util_test.cc",
"src/from_snapshot.cc",
"src/libdeno_test.cc",
]
inputs = [
"$target_gen_dir/snapshot_libdeno_test.bin",
]
deps = [
":create_snapshot_libdeno_test",
":deno_base",
"//testing/gtest:gtest",
]
defines = [ "LIBDENO_TEST" ]
configs = [ ":deno_config" ]
}
v8_source_set("deno_bindings") {
deps = [
":deno_base",
]
configs = [ ":deno_config" ]
}
executable("snapshot_creator") {
sources = [
"src/snapshot_creator.cc",
]
deps = [
":deno_base",
]
configs += [ ":deno_config" ]
}
# Generates type declarations for files that need to be included
# in the runtime bundle
run_node("gen_declarations") {
out_dir = target_gen_dir
sources = [
"js/console.ts",
"js/deno.ts",
"js/globals.ts",
"js/os.ts",
"js/timers.ts",
"js/tsconfig.generated.json",
"js/util.ts",
]
outputs = [
out_dir + "/js/console.d.ts",
out_dir + "/js/deno.d.ts",
out_dir + "/js/globals.d.ts",
out_dir + "/js/os.d.ts",
out_dir + "/js/timers.d.ts",
out_dir + "/js/util.d.ts",
]
deps = [
":msg_ts",
]
args = [
"./node_modules/typescript/bin/tsc",
"-p",
rebase_path("js/tsconfig.generated.json", root_build_dir),
"--baseUrl",
rebase_path(root_build_dir),
"--outDir",
rebase_path(out_dir),
]
}
run_node("bundle") {
out_dir = "$target_gen_dir/bundle/"
sources = [
"js/assets.ts",
"js/console.ts",
"js/globals.ts",
"js/lib.globals.d.ts",
"js/main.ts",
"js/os.ts",
"js/plugins.d.ts",
"js/runtime.ts",
"js/text_encoding.ts",
"js/timers.ts",
"js/types.d.ts",
"js/util.ts",
"js/v8_source_maps.ts",
"rollup.config.js",
"src/msg.fbs",
"tsconfig.json",
]
outputs = [
out_dir + "main.js",
out_dir + "main.js.map",
]
deps = [
":gen_declarations",
":msg_ts",
]
args = [
"./node_modules/rollup/bin/rollup",
"-c",
rebase_path("rollup.config.js", root_build_dir),
"-i",
rebase_path("js/main.ts", root_build_dir),
"-o",
rebase_path(out_dir + "main.js", root_build_dir),
"--sourcemapFile",
rebase_path("."),
"--silent",
"--environment",
"BASEPATH:" + rebase_path(".", root_build_dir),
]
}
source_set("libdeno_nosnapshot") {
bundle_outputs = get_target_outputs(":bundle")
bundle_location = rebase_path(bundle_outputs[0])
bundle_rel_location = rebase_path(bundle_outputs[0], root_build_dir)
bundle_map_location = rebase_path(bundle_outputs[1])
inputs = bundle_outputs
sources = [
"src/from_filesystem.cc",
]
deps = [
":bundle",
":deno_bindings",
]
configs += [ ":deno_config" ]
defines = [
"BUNDLE_LOCATION=\"$bundle_location\"",
"BUNDLE_REL_LOCATION=\"$bundle_rel_location\"",
"BUNDLE_MAP_LOCATION=\"$bundle_map_location\"",
]
}
ts_flatbuffer("msg_ts") {
sources = [
"src/msg.fbs",
]
}
rust_flatbuffer("msg_rs") {
sources = [
"src/msg.fbs",
]
}
# Generates $target_gen_dir/snapshot_deno.bin
create_snapshot("deno") {
js = "$target_gen_dir/bundle/main.js"
source_map = "$target_gen_dir/bundle/main.js.map"
deps = [
":bundle",
]
}
# Generates $target_gen_dir/snapshot_libdeno_test.bin
create_snapshot("libdeno_test") {
testonly = true
js = "js/libdeno_test.js"
}