BUILD.gn 6.6 KB
Newer Older
1
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
2
import("//build/toolchain/cc_wrapper.gni")
3 4
import("//third_party/v8/gni/v8.gni")
import("//third_party/v8/snapshot_toolchain.gni")
5
import("//build_extra/flatbuffers/flatbuffer.gni")
R
Ryan Dahl 已提交
6
import("//build_extra/flatbuffers/rust/rust_flatbuffer.gni")
R
Ryan Dahl 已提交
7 8
import("//build_extra/deno.gni")
import("//build_extra/rust/rust.gni")
9
import("//build_extra/toolchain/validate.gni")
10

R
Ryan Dahl 已提交
11
group("default") {
R
Ryan Dahl 已提交
12 13 14
  testonly = true
  deps = [
    ":deno",
15
    ":hyper_hello",
R
Ryan Dahl 已提交
16
    ":test_cc",
R
Ryan Dahl 已提交
17
    ":test_rs",
R
Ryan Dahl 已提交
18 19 20
  ]
}

21 22 23 24 25 26 27
# Set of targets that need to be built for `cargo check` to succeed.
group("cargo_check_deps") {
  deps = [
    ":msg_rs",
  ]
}

R
Ryan Dahl 已提交
28
config("deno_config") {
29 30
  include_dirs = [ "third_party/v8" ]  # This allows us to v8/src/base/ libraries.
  configs = [ "third_party/v8:external_config" ]
R
Ryan Dahl 已提交
31 32 33
  if (is_debug) {
    defines = [ "DEBUG" ]
  }
34 35 36 37 38 39 40 41 42 43

  # 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" ]
  }
44 45 46 47 48 49 50

  if (is_clang) {
    cflags = [
      "-fcolor-diagnostics",
      "-fansi-escape-codes",
    ]
  }
R
Ryan Dahl 已提交
51 52
}

R
Ryan Dahl 已提交
53
main_extern = [
54 55 56 57
  "$rust_build:atty",
  "$rust_build:dirs",
  "$rust_build:futures",
  "$rust_build:getopts",
58
  "$rust_build:http",
T
Thomas Ghysels 已提交
59
  "$rust_build:hyper",
R
Ryan Dahl 已提交
60
  "$rust_build:hyper_rustls",
R
Ryan Dahl 已提交
61
  "$rust_build:lazy_static",
R
Ryan Dahl 已提交
62 63
  "$rust_build:libc",
  "$rust_build:log",
64 65
  "$rust_build:rand",
  "$rust_build:remove_dir_all",
R
Ryan Dahl 已提交
66
  "$rust_build:ring",
A
Andy Hayden 已提交
67
  "$rust_build:rustyline",
R
Ryan Dahl 已提交
68
  "$rust_build:tempfile",
R
Robby Madruga 已提交
69
  "$rust_build:tokio",
R
Ryan Dahl 已提交
70
  "$rust_build:tokio_executor",
71 72
  "$rust_build:tokio_fs",
  "$rust_build:tokio_io",
73
  "$rust_build:tokio_process",
R
Ryan Dahl 已提交
74
  "$rust_build:tokio_threadpool",
R
Ryan Dahl 已提交
75 76 77 78
  "$rust_build:url",
  "//build_extra/flatbuffers/rust:flatbuffers",
]

R
Ryan Dahl 已提交
79 80
ts_sources = [
  "js/assets.ts",
P
Parsa Ghadimi 已提交
81
  "js/blob.ts",
R
Ryan Dahl 已提交
82
  "js/buffer.ts",
83
  "js/chmod.ts",
R
Ryan Dahl 已提交
84 85
  "js/compiler.ts",
  "js/console.ts",
86
  "js/copy_file.ts",
R
Ryan Dahl 已提交
87
  "js/deno.ts",
S
Shiva Prasanth 已提交
88
  "js/dir.ts",
R
Ryan Dahl 已提交
89
  "js/dispatch.ts",
K
Kitson Kelly 已提交
90
  "js/dom_types.ts",
R
Ryan Dahl 已提交
91 92
  "js/errors.ts",
  "js/fetch.ts",
K
Kyra 已提交
93
  "js/file.ts",
R
Ryan Dahl 已提交
94
  "js/file_info.ts",
R
Ryan Dahl 已提交
95
  "js/files.ts",
96
  "js/flatbuffers.ts",
K
Kyra 已提交
97
  "js/form_data.ts",
R
Ryan Dahl 已提交
98
  "js/global_eval.ts",
R
Ryan Dahl 已提交
99
  "js/globals.ts",
100
  "js/headers.ts",
101
  "js/io.ts",
R
Ryan Dahl 已提交
102 103
  "js/libdeno.ts",
  "js/main.ts",
Y
Yoshiya Hinosawa 已提交
104
  "js/make_temp_dir.ts",
B
Bartek Iwańczuk 已提交
105
  "js/metrics.ts",
106
  "js/mkdir.ts",
R
Ryan Dahl 已提交
107
  "js/mock_builtin.js",
108
  "js/net.ts",
R
Ryan Dahl 已提交
109
  "js/os.ts",
110
  "js/platform.ts",
R
Ryan Dahl 已提交
111
  "js/plugins.d.ts",
112
  "js/process.ts",
113
  "js/promise_util.ts",
J
J2P 已提交
114
  "js/read_dir.ts",
115 116
  "js/read_file.ts",
  "js/read_link.ts",
R
Ryan Dahl 已提交
117 118
  "js/remove.ts",
  "js/rename.ts",
A
Andy Hayden 已提交
119
  "js/repl.ts",
120
  "js/resources.ts",
K
Kitson Kelly 已提交
121
  "js/runner.ts",
R
Ryan Dahl 已提交
122
  "js/stat.ts",
123
  "js/symlink.ts",
R
Ryan Dahl 已提交
124 125
  "js/text_encoding.ts",
  "js/timers.ts",
Z
ztplz 已提交
126
  "js/truncate.ts",
R
Ryan Dahl 已提交
127
  "js/types.ts",
K
Kyra 已提交
128
  "js/url_search_params.ts",
R
Ryan Dahl 已提交
129 130 131 132
  "js/util.ts",
  "js/v8_source_maps.ts",
  "js/write_file.ts",
  "tsconfig.json",
133 134 135 136 137

  # Listing package.json and yarn.lock as sources ensures the bundle is rebuilt
  # when npm packages are added/removed or their contents changes.
  "package.json",
  "third_party/yarn.lock",
R
Ryan Dahl 已提交
138 139
]

R
Ryan Dahl 已提交
140
rust_executable("deno") {
141
  source_root = "src/main.rs"
R
Ryan Dahl 已提交
142
  extern = main_extern
R
Ryan Dahl 已提交
143
  deps = [
R
Ryan Dahl 已提交
144
    ":deno_deps",
R
Ryan Dahl 已提交
145
  ]
146 147
}

148
source_set("snapshot") {
149
  inputs = [
R
Ryan Dahl 已提交
150 151
    "$target_gen_dir/snapshot_deno.bin",
  ]
R
Ryan Dahl 已提交
152
  deps = [
R
Ryan Dahl 已提交
153
    ":create_snapshot_deno",
R
Ryan Dahl 已提交
154 155 156
  ]
}

157 158 159 160 161
rust_executable("hyper_hello") {
  source_root = "tools/hyper_hello.rs"
  extern = [
    "$rust_build:hyper",
    "$rust_build:ring",
162
  ]
163 164 165 166 167 168
}

rust_test("test_rs") {
  source_root = "src/main.rs"
  extern = main_extern
  deps = [
R
Ryan Dahl 已提交
169
    ":deno_deps",
170 171 172
  ]
}

173
v8_executable("test_cc") {
174 175
  testonly = true
  sources = [
176 177
    "libdeno/file_util_test.cc",
    "libdeno/libdeno_test.cc",
R
Ryan Dahl 已提交
178
    "libdeno/test.cc",
R
Ryan Dahl 已提交
179
  ]
180
  deps = [
181
    ":create_snapshot_libdeno_test",
182
    ":libdeno",
183 184
    "//testing/gtest:gtest",
  ]
R
Ryan Dahl 已提交
185 186 187
  data = [
    "$target_gen_dir/snapshot_libdeno_test.bin",
  ]
B
Bert Belder 已提交
188 189
  snapshot_path = rebase_path(data[0], root_build_dir)
  defines = [ "SNAPSHOT_PATH=\"$snapshot_path\"" ]
190 191 192
  configs = [ ":deno_config" ]
}

193 194 195 196 197 198
# 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.
static_library("libdeno") {
  sources = [
R
Ryan Dahl 已提交
199
    "libdeno/api.cc",
200 201 202 203 204
    "libdeno/binding.cc",
    "libdeno/deno.h",
    "libdeno/file_util.cc",
    "libdeno/file_util.h",
    "libdeno/internal.h",
R
Ryan Dahl 已提交
205
  ]
206 207 208 209
  public_deps = [
    "third_party/v8:v8_monolith",
  ]
  configs += [ ":deno_config" ]
R
Ryan Dahl 已提交
210 211
}

R
Ryan Dahl 已提交
212 213 214 215 216 217 218 219 220 221
static_library("deno_deps") {
  complete_static_lib = true
  public_deps = [
    ":libdeno",
    ":msg_rs",
    ":snapshot",
  ]
  configs += [ ":deno_config" ]
}

R
Ryan Dahl 已提交
222 223
executable("snapshot_creator") {
  sources = [
224
    "libdeno/snapshot_creator.cc",
R
Ryan Dahl 已提交
225 226
  ]
  deps = [
227
    ":libdeno",
R
Ryan Dahl 已提交
228
  ]
R
Ryan Dahl 已提交
229
  configs += [ ":deno_config" ]
R
Ryan Dahl 已提交
230 231
}

232 233 234
# Generates the core TypeScript type library for deno that will be
# included in the runtime bundle
run_node("deno_runtime_declaration") {
K
Kitson Kelly 已提交
235
  out_dir = target_gen_dir
R
Ryan Dahl 已提交
236
  sources = ts_sources
K
Kitson Kelly 已提交
237
  outputs = [
238
    "$out_dir/lib/lib.deno_runtime.d.ts",
K
Kitson Kelly 已提交
239 240 241 242 243
  ]
  deps = [
    ":msg_ts",
  ]
  args = [
244
    rebase_path("node_modules/ts-node/dist/bin.js", root_build_dir),
245 246 247 248 249 250
    "--project",
    rebase_path("tools/ts_library_builder/tsconfig.json"),
    rebase_path("tools/ts_library_builder/main.ts", root_build_dir),
    "--basePath",
    rebase_path(".", root_build_dir),
    "--buildPath",
251
    rebase_path(root_build_dir, root_build_dir),
252
    "--outFile",
253 254
    rebase_path("$out_dir/lib/lib.deno_runtime.d.ts", root_build_dir),
    "--silent",
K
Kitson Kelly 已提交
255
  ]
256 257 258
  if (is_debug) {
    args += [ "--debug" ]
  }
K
Kitson Kelly 已提交
259 260
}

R
Ryan Dahl 已提交
261
run_node("bundle") {
262
  out_dir = "$target_gen_dir/bundle/"
263
  outputs = [
264
    out_dir + "main.js",
K
Kitson Kelly 已提交
265
    out_dir + "main.js.map",
R
Ryan Dahl 已提交
266
  ]
267
  depfile = out_dir + "main.d"
R
Ryan Dahl 已提交
268
  deps = [
269
    ":deno_runtime_declaration",
K
Kitson Kelly 已提交
270
    ":msg_ts",
271
  ]
R
Ryan Dahl 已提交
272
  args = [
273
    rebase_path("third_party/node_modules/rollup/bin/rollup", root_build_dir),
K
Kitson Kelly 已提交
274 275 276
    "-c",
    rebase_path("rollup.config.js", root_build_dir),
    "-i",
Y
Yoshiya Hinosawa 已提交
277
    rebase_path("js/main.ts", root_build_dir),
K
Kitson Kelly 已提交
278 279
    "-o",
    rebase_path(out_dir + "main.js", root_build_dir),
280 281
    "--sourcemapFile",
    rebase_path("."),
K
Kitson Kelly 已提交
282
    "--silent",
R
Ryan Dahl 已提交
283 284
  ]
}
285

R
Ryan Dahl 已提交
286 287 288 289
ts_flatbuffer("msg_ts") {
  sources = [
    "src/msg.fbs",
  ]
290 291
}

R
Ryan Dahl 已提交
292 293 294 295 296 297
rust_flatbuffer("msg_rs") {
  sources = [
    "src/msg.fbs",
  ]
}

298
# Generates $target_gen_dir/snapshot_deno.bin
299
create_snapshot("deno") {
R
Ryan Dahl 已提交
300
  js = "$target_gen_dir/bundle/main.js"
R
Ryan Dahl 已提交
301
  source_map = "$target_gen_dir/bundle/main.js.map"
302
  deps = [
R
Ryan Dahl 已提交
303
    ":bundle",
304 305
  ]
}
R
Ryan Dahl 已提交
306

307 308
# Generates $target_gen_dir/snapshot_libdeno_test.bin
create_snapshot("libdeno_test") {
R
Ryan Dahl 已提交
309
  testonly = true
310
  js = "libdeno/libdeno_test.js"
R
Ryan Dahl 已提交
311
}