|
| 1 | +# Copyright (c) 2013-2019 GitHub Inc. |
| 2 | +# Copyright 2019 the V8 project authors. All rights reserved. |
| 3 | +# Copyright 2023 Microsoft Inc. |
| 4 | +# Use of this source code is governed by a BSD-style license that can be |
| 5 | +# found in the LICENSE file. |
| 6 | + |
| 7 | +# This file is used by GN for building, which is NOT the build system used for |
| 8 | +# building official binaries. |
| 9 | +# Please take a look at node.gyp if you are making changes to build system. |
| 10 | + |
| 11 | +import("node.gni") |
| 12 | +import("$node_v8_path/gni/snapshot_toolchain.gni") |
| 13 | +import("$node_v8_path/gni/v8.gni") |
| 14 | + |
| 15 | +# The actual configurations are put inside a template in unofficial.gni to |
| 16 | +# prevent accidental edits from contributors. |
| 17 | +template("node_gn_build") { |
| 18 | + config("node_features") { |
| 19 | + defines = [] |
| 20 | + if (is_component_build) { |
| 21 | + defines += [ |
| 22 | + "USING_UV_SHARED", |
| 23 | + "USING_V8_SHARED", |
| 24 | + ] |
| 25 | + } |
| 26 | + if (node_use_openssl) { |
| 27 | + defines += [ "HAVE_OPENSSL=1" ] |
| 28 | + } else { |
| 29 | + defines += [ "HAVE_OPENSSL=0" ] |
| 30 | + } |
| 31 | + if (node_use_v8_platform) { |
| 32 | + defines += [ "NODE_USE_V8_PLATFORM=1" ] |
| 33 | + } else { |
| 34 | + defines += [ "NODE_USE_V8_PLATFORM=0" ] |
| 35 | + } |
| 36 | + if (node_enable_inspector) { |
| 37 | + defines += [ "HAVE_INSPECTOR=1" ] |
| 38 | + } else { |
| 39 | + defines += [ "HAVE_INSPECTOR=0" ] |
| 40 | + } |
| 41 | + if (node_use_node_code_cache) { |
| 42 | + defines += [ "NODE_USE_NODE_CODE_CACHE=1"] |
| 43 | + } |
| 44 | + if (v8_enable_i18n_support) { |
| 45 | + defines += [ "NODE_HAVE_I18N_SUPPORT=1" ] |
| 46 | + } else { |
| 47 | + defines += [ "NODE_HAVE_I18N_SUPPORT=0" ] |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + config("node_external_config") { |
| 52 | + include_dirs = [ |
| 53 | + target_gen_dir, |
| 54 | + "src", |
| 55 | + ] |
| 56 | + defines = [ |
| 57 | + "NODE_WANT_INTERNALS=1", |
| 58 | + "NODE_EMBEDDER_MODULE_VERSION=$node_module_version", |
| 59 | + ] |
| 60 | + configs = [ |
| 61 | + ":node_features", |
| 62 | + "$node_v8_path:external_config", |
| 63 | + ] |
| 64 | + } |
| 65 | + |
| 66 | + config("node_internal_config") { |
| 67 | + visibility = [ |
| 68 | + ":*", |
| 69 | + "src/inspector:*", |
| 70 | + ] |
| 71 | + configs = [ ":node_external_config" ] |
| 72 | + libs = [] |
| 73 | + cflags = [ "-Wno-microsoft-include" ] |
| 74 | + cflags_cc = [ |
| 75 | + "-Wno-deprecated-declarations", |
| 76 | + "-Wno-extra-semi", |
| 77 | + "-Wno-implicit-fallthrough", |
| 78 | + "-Wno-macro-redefined", |
| 79 | + "-Wno-return-type", |
| 80 | + "-Wno-shadow", |
| 81 | + "-Wno-sometimes-uninitialized", |
| 82 | + "-Wno-string-plus-int", |
| 83 | + "-Wno-string-conversion", |
| 84 | + "-Wno-unreachable-code", |
| 85 | + "-Wno-unreachable-code-break", |
| 86 | + "-Wno-unreachable-code-return", |
| 87 | + "-Wno-unused-label", |
| 88 | + "-Wno-unused-private-field", |
| 89 | + "-Wno-unused-variable", |
| 90 | + "-Wno-unused-function", |
| 91 | + ] |
| 92 | + |
| 93 | + if (target_cpu == "x86") { |
| 94 | + node_arch = "ia32" |
| 95 | + } else { |
| 96 | + node_arch = target_cpu |
| 97 | + } |
| 98 | + if (target_os == "win") { |
| 99 | + node_platform = "win32" |
| 100 | + } else if (target_os == "mac") { |
| 101 | + node_platform = "darwin" |
| 102 | + } else { |
| 103 | + node_platform = target_os |
| 104 | + } |
| 105 | + defines = [ |
| 106 | + "NODE_ARCH=\"$node_arch\"", |
| 107 | + "NODE_PLATFORM=\"$node_platform\"", |
| 108 | + "NODE_REPORT" |
| 109 | + ] |
| 110 | + |
| 111 | + if (is_win) { |
| 112 | + defines += [ |
| 113 | + "NOMINMAX", |
| 114 | + "_UNICODE=1", |
| 115 | + ] |
| 116 | + } else { |
| 117 | + defines += [ "__POSIX__" ] |
| 118 | + } |
| 119 | + if (node_tag != "") { |
| 120 | + defines += [ "NODE_TAG=\"$node_tag\"" ] |
| 121 | + } |
| 122 | + if (node_v8_options != "") { |
| 123 | + defines += [ "NODE_V8_OPTIONS=\"$node_v8_options\"" ] |
| 124 | + } |
| 125 | + if (node_release_urlbase != "") { |
| 126 | + defines += [ "NODE_RELEASE_URLBASE=\"$node_release_urlbase\"" ] |
| 127 | + } |
| 128 | + if (node_use_openssl) { |
| 129 | + defines += [ |
| 130 | + "NODE_OPENSSL_SYSTEM_CERT_PATH=\"$node_openssl_system_ca_path\"", |
| 131 | + ] |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + gypi_values = exec_script("./tools/gypi_to_gn.py", |
| 136 | + [ rebase_path("node.gyp"), |
| 137 | + "--replace=<@(node_builtin_shareable_builtins)=" ], |
| 138 | + "scope", |
| 139 | + [ "node.gyp" ]) |
| 140 | + |
| 141 | + source_set("libnode") { |
| 142 | + configs += [ ":node_internal_config" ] |
| 143 | + public_configs = [ |
| 144 | + ":node_external_config", |
| 145 | + "deps/googletest:googletest_config", |
| 146 | + ] |
| 147 | + public_deps = [ |
| 148 | + "deps/ada", |
| 149 | + "deps/uv", |
| 150 | + "deps/base64", |
| 151 | + "$node_v8_path", |
| 152 | + ] |
| 153 | + deps = [ |
| 154 | + ":run_node_js2c", |
| 155 | + "deps/brotli", |
| 156 | + "deps/cares", |
| 157 | + "deps/histogram", |
| 158 | + "deps/llhttp", |
| 159 | + "deps/nghttp2", |
| 160 | + "deps/ngtcp2", |
| 161 | + "deps/postject", |
| 162 | + "deps/simdutf", |
| 163 | + "deps/uvwasi", |
| 164 | + "//third_party/zlib", |
| 165 | + "$node_v8_path:v8_libplatform", |
| 166 | + ] |
| 167 | + |
| 168 | + sources = [ |
| 169 | + "$target_gen_dir/node_javascript.cc", |
| 170 | + ] + gypi_values.node_sources |
| 171 | + |
| 172 | + if (is_win) { |
| 173 | + libs = [ "psapi.lib" ] |
| 174 | + } |
| 175 | + if (is_mac) { |
| 176 | + frameworks = [ "CoreFoundation.framework" ] |
| 177 | + } |
| 178 | + |
| 179 | + if (v8_enable_i18n_support) { |
| 180 | + deps += [ "//third_party/icu" ] |
| 181 | + } |
| 182 | + if (node_use_openssl) { |
| 183 | + public_deps += [ "deps/openssl" ] |
| 184 | + sources += gypi_values.node_crypto_sources |
| 185 | + } |
| 186 | + if (node_enable_inspector) { |
| 187 | + deps += [ |
| 188 | + "src/inspector:node_protocol_generated_sources", |
| 189 | + "src/inspector:v8_inspector_compress_protocol_json", |
| 190 | + ] |
| 191 | + include_dirs = [ |
| 192 | + "$target_gen_dir/src", |
| 193 | + "$target_gen_dir/src/inspector", |
| 194 | + ] |
| 195 | + node_inspector = exec_script( |
| 196 | + "./tools/gypi_to_gn.py", |
| 197 | + [ rebase_path("src/inspector/node_inspector.gypi"), |
| 198 | + "--replace=<(SHARED_INTERMEDIATE_DIR)=$target_gen_dir" ], |
| 199 | + "scope", |
| 200 | + [ "src/inspector/node_inspector.gypi" ]) |
| 201 | + sources += node_inspector.node_inspector_sources + |
| 202 | + node_inspector.node_inspector_generated_sources |
| 203 | + } |
| 204 | + } |
| 205 | + |
| 206 | + executable(target_name) { |
| 207 | + forward_variables_from(invoker, "*") |
| 208 | + |
| 209 | + sources = [ "src/node_main.cc" ] |
| 210 | + deps = [ ":libnode" ] |
| 211 | + if (node_use_node_snapshot) { |
| 212 | + sources += [ "$target_gen_dir/node_snapshot.cc" ] |
| 213 | + deps += [ ":run_node_mksnapshot" ] |
| 214 | + if (is_clang || !is_win) { |
| 215 | + cflags_cc = [ |
| 216 | + "-Wno-c++11-narrowing", |
| 217 | + "-Wno-shadow", |
| 218 | + ] |
| 219 | + } |
| 220 | + } else { |
| 221 | + sources += [ "src/node_snapshot_stub.cc" ] |
| 222 | + } |
| 223 | + output_name = "node" |
| 224 | + } |
| 225 | + |
| 226 | + if (node_use_node_snapshot) { |
| 227 | + if (current_toolchain == v8_snapshot_toolchain) { |
| 228 | + executable("node_mksnapshot") { |
| 229 | + configs += [ ":node_internal_config" ] |
| 230 | + sources = [ |
| 231 | + "src/node_snapshot_stub.cc", |
| 232 | + "tools/snapshot/node_mksnapshot.cc", |
| 233 | + ] |
| 234 | + deps = [ ":libnode" ] |
| 235 | + } |
| 236 | + } |
| 237 | + |
| 238 | + action("run_node_mksnapshot") { |
| 239 | + deps = [ ":node_mksnapshot($v8_snapshot_toolchain)" ] |
| 240 | + script = "$node_v8_path/tools/run.py" |
| 241 | + sources = [] |
| 242 | + data = [] |
| 243 | + |
| 244 | + mksnapshot_dir = get_label_info(":node_mksnapshot($v8_snapshot_toolchain)", |
| 245 | + "root_out_dir") |
| 246 | + |
| 247 | + outputs = [ "$target_gen_dir/node_snapshot.cc" ] |
| 248 | + args = [ |
| 249 | + "./" + rebase_path(mksnapshot_dir + "/node_mksnapshot", root_build_dir), |
| 250 | + rebase_path("$target_gen_dir/node_snapshot.cc", root_build_dir), |
| 251 | + ] |
| 252 | + } |
| 253 | + } |
| 254 | + |
| 255 | + action("generate_config_gypi") { |
| 256 | + script = "tools/generate_config_gypi.py" |
| 257 | + outputs = [ "$target_gen_dir/config.gypi" ] |
| 258 | + depfile = "$target_gen_dir/$target_name.d" |
| 259 | + script_args = [ "$root_build_dir" ] |
| 260 | + script_args += outputs |
| 261 | + script_args += [ depfile ] |
| 262 | + args = rebase_path(script_args, root_build_dir) |
| 263 | + } |
| 264 | + |
| 265 | + executable("node_js2c") { |
| 266 | + deps = [ |
| 267 | + "deps/simdutf", |
| 268 | + "deps/uv", |
| 269 | + ] |
| 270 | + sources = [ |
| 271 | + "tools/js2c.cc", |
| 272 | + "tools/executable_wrapper.h", |
| 273 | + ] |
| 274 | + } |
| 275 | + |
| 276 | + action("run_node_js2c") { |
| 277 | + script = "$node_v8_path/tools/run.py" |
| 278 | + deps = [ |
| 279 | + ":node_js2c($host_toolchain)", |
| 280 | + ":generate_config_gypi", |
| 281 | + ] |
| 282 | + |
| 283 | + node_deps_files = gypi_values.deps_files + node_builtin_shareable_builtins |
| 284 | + node_library_files = exec_script("./tools/search_files.py", |
| 285 | + [ rebase_path(".", root_build_dir), |
| 286 | + rebase_path("lib", root_build_dir), |
| 287 | + "js" ], |
| 288 | + "list lines") |
| 289 | + |
| 290 | + inputs = node_library_files + |
| 291 | + node_deps_files + |
| 292 | + [ "$target_gen_dir/config.gypi" ] |
| 293 | + outputs = [ "$target_gen_dir/node_javascript.cc" ] |
| 294 | + |
| 295 | + # Get the path to node_js2c executable of the host toolchain. |
| 296 | + if (host_os == "win") { |
| 297 | + host_executable_suffix = ".exe" |
| 298 | + } else { |
| 299 | + host_executable_suffix = "" |
| 300 | + } |
| 301 | + node_js2c_path = |
| 302 | + get_label_info(":node_js2c($host_toolchain)", "root_out_dir") + "/" + |
| 303 | + get_label_info(":node_js2c($host_toolchain)", "name") + |
| 304 | + host_executable_suffix |
| 305 | + |
| 306 | + args = [ rebase_path(node_js2c_path), |
| 307 | + rebase_path("$target_gen_dir/node_javascript.cc"), |
| 308 | + "--root", rebase_path("."), |
| 309 | + "lib", rebase_path("$target_gen_dir/config.gypi") ] + |
| 310 | + node_deps_files |
| 311 | + } |
| 312 | + |
| 313 | + executable("node_cctest") { |
| 314 | + testonly = true |
| 315 | + configs += [ ":node_internal_config" ] |
| 316 | + |
| 317 | + deps = [ |
| 318 | + ":libnode", |
| 319 | + "deps/googletest", |
| 320 | + "deps/googletest:gtest_main", |
| 321 | + "deps/simdutf", |
| 322 | + ] |
| 323 | + |
| 324 | + sources = gypi_values.node_cctest_sources |
| 325 | + if (node_use_openssl) { |
| 326 | + sources += gypi_values.node_cctest_openssl_sources |
| 327 | + } |
| 328 | + if (node_enable_inspector) { |
| 329 | + sources += gypi_values.node_cctest_inspector_sources |
| 330 | + } |
| 331 | + } |
| 332 | + |
| 333 | + executable("node_embedtest") { |
| 334 | + output_name = "embedtest" |
| 335 | + testonly = true |
| 336 | + deps = [ ":libnode" ] |
| 337 | + sources = [ |
| 338 | + "src/node_snapshot_stub.cc", |
| 339 | + "test/embedding/embedtest.cc", |
| 340 | + ] |
| 341 | + } |
| 342 | + |
| 343 | + executable("overlapped_checker") { |
| 344 | + output_name = "overlapped-checker" |
| 345 | + testonly = true |
| 346 | + if (is_win) { |
| 347 | + sources = [ "test/overlapped-checker/main_win.c" ] |
| 348 | + } else { |
| 349 | + sources = [ "test/overlapped-checker/main_unix.c" ] |
| 350 | + } |
| 351 | + } |
| 352 | +} |
0 commit comments