Skip to content

Commit

Permalink
build: add GN build files
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Apr 24, 2023
1 parent 3e74590 commit ff7e849
Show file tree
Hide file tree
Showing 20 changed files with 1,532 additions and 0 deletions.
280 changes: 280 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
# Copyright (c) 2013-2019 GitHub Inc.
# Copyright 2019 the V8 project authors. All rights reserved.
# Copyright 2023 Microsoft Inc.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This file is used by GN for building, which is NOT the build system used for
# building official binaries.
# Please take a look at node.gyp if you are making changes to build system.

import("node.gni")
import("$node_v8_path/gni/snapshot_toolchain.gni")
import("$node_v8_path/gni/v8.gni")

config("node_features") {
defines = []
if (is_component_build) {
defines += [
"USING_UV_SHARED",
"USING_V8_SHARED",
]
}
if (node_use_openssl) {
defines += [ "HAVE_OPENSSL=1" ]
} else {
defines += [ "HAVE_OPENSSL=0" ]
}
if (node_use_v8_platform) {
defines += [ "NODE_USE_V8_PLATFORM=1" ]
} else {
defines += [ "NODE_USE_V8_PLATFORM=0" ]
}
if (node_enable_inspector) {
defines += [ "HAVE_INSPECTOR=1" ]
} else {
defines += [ "HAVE_INSPECTOR=0" ]
}
if (node_use_code_cache) {
defines += [ "NODE_USE_NODE_CODE_CACHE=1"]
}
if (v8_enable_i18n_support) {
defines += [ "NODE_HAVE_I18N_SUPPORT=1" ]
} else {
defines += [ "NODE_HAVE_I18N_SUPPORT=0" ]
}
}

config("node_external_config") {
include_dirs = [ "src" ]
defines = [ "NODE_WANT_INTERNALS=1" ]
configs = [
":node_features",
"$node_v8_path:external_config",
]
}

config("node_internal_config") {
visibility = [
":*",
"src/inspector:*",
]
configs = [ ":node_external_config" ]
libs = []
cflags = [ "-Wno-microsoft-include" ]
cflags_cc = [
"-Wno-deprecated-declarations",
"-Wno-extra-semi",
"-Wno-implicit-fallthrough",
"-Wno-macro-redefined",
"-Wno-return-type",
"-Wno-shadow",
"-Wno-sometimes-uninitialized",
"-Wno-string-plus-int",
"-Wno-string-conversion",
"-Wno-unreachable-code",
"-Wno-unreachable-code-break",
"-Wno-unreachable-code-return",
"-Wno-unused-label",
"-Wno-unused-private-field",
"-Wno-unused-variable",
"-Wno-unused-function",
]

if (target_cpu == "x86") {
node_arch = "ia32"
} else {
node_arch = target_cpu
}
if (target_os == "win") {
node_platform = "win32"
} else if (target_os == "mac") {
node_platform = "darwin"
} else {
node_platform = target_os
}
defines = [
"NODE_ARCH=\"$node_arch\"",
"NODE_PLATFORM=\"$node_platform\"",
"NODE_REPORT"
]

if (is_win) {
defines += [
"NOMINMAX",
"_UNICODE=1",
]
} else {
defines += [ "__POSIX__" ]
}
if (node_tag != "") {
defines += [ "NODE_TAG=\"$node_tag\"" ]
}
if (node_v8_options != "") {
defines += [ "NODE_V8_OPTIONS=\"$node_v8_options\"" ]
}
if (node_release_urlbase != "") {
defines += [ "NODE_RELEASE_URLBASE=\"$node_release_urlbase\"" ]
}
if (node_use_openssl) {
defines += [
"NODE_OPENSSL_SYSTEM_CERT_PATH=\"$node_openssl_system_ca_path\"",
]
}
}

gypi_values = exec_script("./tools/gypi_to_gn.py",
[ rebase_path("node.gyp"),
"--replace=<@(node_builtin_shareable_builtins)=" ],
"scope",
[ "node.gyp" ])

source_set("libnode") {
configs += [ ":node_internal_config" ]
public_configs = [
":node_external_config",
"deps/googletest:googletest_config",
]
public_deps = [
"deps/ada",
"deps/uv",
"deps/base64",
"$node_v8_path",
]
deps = [
":node_js2c",
"deps/brotli",
"deps/cares",
"deps/histogram",
"deps/llhttp",
"deps/nghttp2",
"deps/ngtcp2",
"deps/postject",
"deps/simdutf",
"deps/uvwasi",
"//third_party/zlib",
"$node_v8_path:v8_libplatform",
]

sources = gypi_values.node_sources + [ "$target_gen_dir/node_javascript.cc" ]

if (is_win) {
libs = [ "psapi.lib" ]
}
if (is_mac) {
frameworks = [ "CoreFoundation.framework" ]
}

if (v8_enable_i18n_support) {
deps += [ "//third_party/icu" ]
}
if (node_use_openssl) {
public_deps += [ "deps/openssl" ]
sources += gypi_values.node_crypto_sources
}
if (node_enable_inspector) {
deps += [
"src/inspector:node_protocol_generated_sources",
"src/inspector:v8_inspector_compress_protocol_json",
]
include_dirs = [
"$target_gen_dir",
"$target_gen_dir/src",
"$target_gen_dir/src/inspector",
]
node_inspector = exec_script(
"./tools/gypi_to_gn.py",
[ rebase_path("src/inspector/node_inspector.gypi"),
"--replace=<(SHARED_INTERMEDIATE_DIR)=$target_gen_dir" ],
"scope",
[ "src/inspector/node_inspector.gypi" ])
sources += node_inspector.node_inspector_sources +
node_inspector.node_inspector_generated_sources
}
}

executable("node") {
sources = [ "src/node_main.cc" ]
deps = [ ":libnode" ]
if (node_use_node_snapshot) {
sources += [ "$target_gen_dir/node_snapshot.cc" ]
deps += [ ":run_node_mksnapshot" ]
if (is_clang || !is_win) {
cflags_cc = [
"-Wno-c++11-narrowing",
"-Wno-shadow",
]
}
} else {
sources += [ "src/node_snapshot_stub.cc" ]
}
output_name = "node"
}

if (node_use_node_snapshot) {
if (current_toolchain == v8_snapshot_toolchain) {
executable("node_mksnapshot") {
configs += [ ":node_internal_config" ]
sources = [
"src/node_snapshot_stub.cc",
"tools/snapshot/node_mksnapshot.cc",
]
deps = [ ":libnode" ]
}
}

action("run_node_mksnapshot") {
deps = [ ":node_mksnapshot($v8_snapshot_toolchain)" ]
script = "$node_v8_path/tools/run.py"
sources = []
data = []

mksnapshot_dir = get_label_info(":node_mksnapshot($v8_snapshot_toolchain)",
"root_out_dir")

outputs = [ "$target_gen_dir/node_snapshot.cc" ]
args = [
"./" + rebase_path(mksnapshot_dir + "/node_mksnapshot", root_build_dir),
rebase_path("$target_gen_dir/node_snapshot.cc", root_build_dir),
]
}
}

action("generate_config_gypi") {
script = "./tools/generate_config_gypi.py"
outputs = [ "$target_gen_dir/config.gypi" ]
depfile = "$target_gen_dir/$target_name.d"
script_args = [ "$root_build_dir" ]
script_args += outputs
script_args += [ depfile ]
args = rebase_path(script_args, root_build_dir)
}

action("node_js2c") {
script = "tools/js2c.py"
deps = [ ":generate_config_gypi" ]

# TODO(zcbenz): These files are defined in configure.py.
node_deps_files = gypi_values.deps_files + [
"deps/cjs-module-lexer/lexer.js",
"deps/cjs-module-lexer/dist/lexer.js",
"deps/undici/undici.js",
]

node_library_files = exec_script("./tools/search_files.py",
[ rebase_path(".", root_build_dir),
rebase_path("lib", root_build_dir),
"js" ],
"list lines")

inputs = node_library_files +
node_deps_files +
[ "$target_gen_dir/config.gypi" ]
outputs = [ "$target_gen_dir/node_javascript.cc" ]

args = [ "--target", rebase_path("$target_gen_dir/node_javascript.cc") ] +
[ "--directory", "lib" ] +
[ "--root", rebase_path(".") ] +
[ rebase_path("$target_gen_dir/config.gypi") ] +
node_deps_files
}
29 changes: 29 additions & 0 deletions deps/ada/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2023 Microsoft Inc.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This file is used by GN for building, which is NOT the build system used for
# building official binaries.
# Please edit the gyp files if you are making changes to build system.

import("../../node.gni")
import("$node_v8_path/gni/v8.gni")

config("ada_config") {
include_dirs = [ "." ]
}

gypi_values = exec_script("../../tools/gypi_to_gn.py",
[ rebase_path("ada.gyp") ],
"scope",
[ "ada.gyp" ])

source_set("ada") {
public_configs = [ ":ada_config" ]
sources = gypi_values.ada_sources
if (is_clang || !is_win) {
cflags_cc = [
"-Wno-unreachable-code-break",
]
}
}

0 comments on commit ff7e849

Please sign in to comment.