Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements to --build-v8-with-gn #58

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,12 @@ parser.add_option('--build-v8-with-gn',
dest='build_v8_with_gn',
default=False,
help='build V8 using GN instead of gyp')
parser.add_option('--build-v8-with-gn-use-goma',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this also include --build-v8-with-gn? Otherwise both flags would have to be passed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm. Done.

action='store_true',
dest='build_v8_with_gn_use_goma',
default=False,
help='For Googlers: Enable use_goma=true for building v8')


# Create compile_commands.json in out/Debug and out/Release.
parser.add_option('-C',
Expand Down Expand Up @@ -1054,6 +1060,7 @@ def configure_v8(o):
print('Fetching dependencies to build V8 with GN')
options.build_v8_with_gn = FetchDeps(v8_path)
o['variables']['build_v8_with_gn'] = b(options.build_v8_with_gn)
o['variables']['build_v8_with_gn_use_goma'] = b(options.build_v8_with_gn_use_goma)


def configure_openssl(o):
Expand Down
37 changes: 32 additions & 5 deletions deps/v8/gypfiles/v8-monolithic.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@
},
'actions': [
{
'action_name': 'build_with_gn',
'action_name': 'build_with_gn_generate_build_files',
# No need to list full set of inputs because after the initial
# generation, ninja (run by the next action), will check to see
# if build.ninja is stale.
'inputs': [
'../tools//node/build_gn.py',
'../tools/node/build_gn.py',
],
'outputs': [
'<(INTERMEDIATE_DIR)/gn/obj/libv8_monolith.a',
'<(INTERMEDIATE_DIR)/gn/args.gn',
'<(INTERMEDIATE_DIR)/gn/build.ninja',
],
'action': [
'../tools//node/build_gn.py',
'python',
'../tools/node/build_gn.py',
'--mode', '<(CONFIGURATION_NAME)',
'--v8_path', '../',
'--build_path', '<(INTERMEDIATE_DIR)/gn',
Expand All @@ -49,7 +52,31 @@
'--flag', 'v8_optimized_debug=<(v8_optimized_debug)',
'--flag', 'v8_enable_disassembler=<(v8_enable_disassembler)',
'--flag', 'v8_postmortem_support=<(v8_postmortem_support)',
'--flag', 'use_goma=<(build_v8_with_gn_use_goma)',
],
},
{
'action_name': 'build_with_gn',
'inputs': [
'../tools/node/build_gn.py',
'<(INTERMEDIATE_DIR)/gn/build.ninja',
],
# Specify a non-existent output to make the target permanently dirty.
# Alternatively, a depfile could be used, but then two dirty checks
# would run: one by outer the build tool, and one by build_gn.py.
'outputs': [
'<(v8_base)',
'does-not-exist',
],
'action': [
'python',
'../tools/node/build_gn.py',
'--build_path', '<(INTERMEDIATE_DIR)/gn',
'--v8_path', '../',
'--build',
],
# Allows sub-ninja's build progress to be printed.
'ninja_use_console': 1,
},
],
},
Expand Down
55 changes: 32 additions & 23 deletions deps/v8/tools/node/build_gn.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def FindGn(options):
return os.path.join(options.v8_path, "buildtools", os_path, "gn")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is directly copied over from V8 upstream (e.g. using v8/tools/update_node.py <v8-path> <node-path>), so changes to this should land in V8 upstream.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


def GenerateBuildFiles(options):
print "Setting GN args."
gn = FindGn(options)
gn_args = []
gn_args.extend(GN_ARGS)
Expand All @@ -56,47 +55,57 @@ def GenerateBuildFiles(options):
flag = flag.replace("target_cpu=ia32", "target_cpu=\"x86\"")
gn_args.append(flag)
if options.mode == "DEBUG":
gn_args.append("is_debug = true")
gn_args.append("is_debug=true")
else:
gn_args.append("is_debug = false")
gn_args.append("is_debug=false")

if not os.path.isdir(options.build_path):
os.makedirs(options.build_path)
with open(os.path.join(options.build_path, "args.gn"), "w") as args_file:
args_file.write("\n".join(gn_args))
subprocess.check_call([gn, "gen", "-C", options.build_path],
cwd=options.v8_path)
args = [gn, "gen", options.build_path, "-q",
"--args=" + ' '.join(gn_args)]
subprocess.check_call(args, cwd=options.v8_path)

def Build(options):
print "Building."
depot_tools = node_common.EnsureDepotTools(options.v8_path, False)
ninja = os.path.join(depot_tools, "ninja")
subprocess.check_call([ninja, "-v", "-C", options.build_path, BUILD_TARGET],
cwd=options.v8_path)
if sys.platform == 'win32':
# Required because there is an extension-less file called "ninja".
ninja += '.exe'
args = [ninja, "-C", options.build_path, BUILD_TARGET]

with open(os.path.join(options.build_path, 'args.gn')) as f:
if 'use_goma = true' in f.read():
args += ["-j500"]

subprocess.check_call(args, cwd=options.v8_path)

def ParseOptions(args):
parser = argparse.ArgumentParser(
description="Build %s with GN" % BUILD_TARGET)
parser.add_argument("--mode", help="Build mode (Release/Debug)")
parser.add_argument("--v8_path", help="Path to V8")
parser.add_argument("--build_path", help="Path to build result")
parser.add_argument("--v8_path", help="Path to V8", required=True)
parser.add_argument("--build_path", help="Path to build result",
required=True)
parser.add_argument("--flag", help="Translate GYP flag to GN",
action="append")
parser.add_argument("--host_os", help="Current operating system")
parser.add_argument("--build", help="Run ninja as opposed to gn gen.",
action="store_true")
options = parser.parse_args(args)

assert options.host_os
assert options.mode == "Debug" or options.mode == "Release"
options.build_path = os.path.abspath(options.build_path)

assert options.v8_path
options.v8_path = os.path.abspath(options.v8_path)
assert os.path.isdir(options.v8_path)
if not options.build:
assert options.host_os
assert options.mode == "Debug" or options.mode == "Release"

options.v8_path = os.path.abspath(options.v8_path)
assert os.path.isdir(options.v8_path)

assert options.build_path
options.build_path = os.path.abspath(options.build_path)
return options


if __name__ == "__main__":
options = ParseOptions(sys.argv[1:])
GenerateBuildFiles(options)
Build(options)
if not options.build:
GenerateBuildFiles(options)
else:
Build(options)