Commit 36b44c15 authored by Victor Gomes's avatar Victor Gomes Committed by V8 LUCI CQ

[bazel] Compile V8 with bazel

Command to build: `bazel build :d8`

Caveats:
  - Needs clang
  - Only supports x64 on Linux
  - Bare V8: no Wasm and no ICU
  - Still needs GN to generate inspector files

Bug: v8:11234
Change-Id: I6d01fecff5fba5c3582995d071692e5c6c6c6310
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2960949
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75155}
parent 719e600a
# Copyright 2021 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# V8 bazel port only supports clang
build --action_env=BAZEL_COMPILER=clang
build --action_env=CC=clang
build --action_env=CXX=clang++
build --action_env=PATH
\ No newline at end of file
......@@ -105,4 +105,7 @@ turbo*.cfg
turbo*.dot
turbo*.json
v8.ignition_dispatches_table.json
bazel-bin
bazel-out
bazel-testlogs
bazel-v8
This diff is collapsed.
......@@ -12,7 +12,10 @@ per-file .gitignore=file:INFRA_OWNERS
per-file .gn=file:INFRA_OWNERS
per-file .vpython=file:INFRA_OWNERS
per-file .ycm_extra_conf.py=file:INFRA_OWNERS
per-file .bazelrc=file:COMMON_OWNERS
per-file BUILD.bazel=file:COMMON_OWNERS
per-file BUILD.gn=file:COMMON_OWNERS
per-file WORKSPACE=file:COMMON_OWNERS
per-file DEPS=file:INFRA_OWNERS
# For Test262 rolls.
per-file DEPS=mathias@chromium.org
......
# Copyright 2021 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
workspace(name = "v8")
# TODO(victorgomes): load dependencies using repo_rule?
\ No newline at end of file
# Google3 V8 owners
ahaas@chromium.org
cbruni@chromium.org
delphick@chromium.org
victorgomes@chromium.org
# Copyright 2021 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
FlagInfo = provider(fields = ["value"])
def _options_impl(ctx):
return FlagInfo(value = ctx.build_setting_value)
_create_option_flag = rule(
implementation = _options_impl,
build_setting = config.bool(flag = True),
)
_create_option_string = rule(
implementation = _options_impl,
build_setting = config.string(flag = True),
)
_create_option_int = rule(
implementation = _options_impl,
build_setting = config.int(flag = True),
)
def v8_flag(name, default = False):
_create_option_flag(name = name, build_setting_default = default)
native.config_setting(name = "is_" + name, flag_values = {name: "True"})
def v8_string(name, default = ""):
_create_option_string(name = name, build_setting_default = default)
def v8_int(name, default = 0):
_create_option_int(name = name, build_setting_default = default)
def _custom_config_impl(ctx):
defs = []
defs.append("V8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=" +
str(ctx.attr._v8_typed_array_max_size_in_heap[FlagInfo].value))
context = cc_common.create_compilation_context(defines = depset(defs))
return [CcInfo(compilation_context = context)]
v8_custom_config = rule(
implementation = _custom_config_impl,
attrs = {
"_v8_typed_array_max_size_in_heap":
attr.label(default = "//:v8_typed_array_max_size_in_heap"),
}
)
def _config_impl(ctx):
hdrs = []
# Add headers
for h in ctx.attr.hdrs:
hdrs += h[DefaultInfo].files.to_list()
defs = []
# Add conditional_defines
for f, d in ctx.attr.conditional_defines.items():
if f[FlagInfo].value:
defs.append(d)
# Add defines
for d in ctx.attr.defines:
defs.append(d)
context = cc_common.create_compilation_context(
defines = depset(
defs,
transitive = [dep[CcInfo].compilation_context.defines for dep in ctx.attr.deps],
),
headers = depset(
hdrs,
transitive = [dep[CcInfo].compilation_context.headers for dep in ctx.attr.deps],
),
)
return [CcInfo(compilation_context = context)]
v8_config = rule(
implementation = _config_impl,
attrs = {
"conditional_defines": attr.label_keyed_string_dict(),
"defines": attr.string_list(),
"deps": attr.label_list(),
"hdrs": attr.label_list(allow_files = True),
},
)
def _default_args(configs):
return struct(
deps = configs + ["//:define_flags"],
copts = [
"-fPIC",
"-Werror",
"-Wextra",
"-Wno-unused-parameter",
"-Wno-implicit-int-float-conversion",
"-Wno-deprecated-copy",
"-std=c++14",
"-isystem .",
# TODO(victorgomes): these should be passed only if x64:
"-m64",
"-march=x86-64",
"-msse3",
],
includes = ["include"],
linkopts = ["-pthread"],
)
def v8_binary(
name,
srcs,
configs = [],
deps = [],
includes = [],
copts = [],
linkopts = [],
**kwargs):
default = _default_args(configs)
native.cc_binary(
name = name,
srcs = srcs,
deps = deps + default.deps,
includes = includes + default.includes,
copts = copts + default.copts,
linkopts = linkopts + default.linkopts,
**kwargs
)
def v8_library(
name,
srcs,
configs = [],
deps = [],
includes = [],
copts = [],
linkopts = [],
**kwargs):
default = _default_args(configs)
native.cc_library(
name = name,
srcs = srcs,
deps = deps + default.deps,
includes = includes + default.includes,
copts = copts + default.copts,
linkopts = linkopts + default.linkopts,
alwayslink = 1,
linkstatic = 1,
**kwargs
)
def _torque_impl(ctx):
# Arguments
args = []
args.append("-o")
args.append(ctx.genfiles_dir.path + "/torque-generated")
args.append("-v8-root")
args.append(".")
if ctx.attr._v8_annotate_torque_ir[FlagInfo].value:
args.append("-annotate-ir")
# Sources
args += [f.path for f in ctx.files.srcs]
# Generate/declare output files
outs = []
for src in ctx.files.srcs:
root, period, ext = src.path.rpartition(".")
file = "torque-generated/" + root
outs.append(ctx.actions.declare_file(file + "-tq-csa.cc"))
outs.append(ctx.actions.declare_file(file + "-tq-csa.h"))
outs.append(ctx.actions.declare_file(file + "-tq-inl.inc"))
outs.append(ctx.actions.declare_file(file + "-tq.inc"))
outs.append(ctx.actions.declare_file(file + "-tq.cc"))
outs += [ctx.actions.declare_file("torque-generated/" + f) for f in ctx.attr.extras]
ctx.actions.run(
outputs = outs,
inputs = ctx.files.srcs,
arguments = args,
executable = ctx.executable.tool,
progress_message = "Generating Torque files",
)
return [DefaultInfo(files = depset(outs))]
v8_torque = rule(
implementation = _torque_impl,
attrs = {
"srcs": attr.label_list(allow_files = True, mandatory = True),
"extras": attr.string_list(),
"tool": attr.label(
default = "//:torque",
allow_files = True,
executable = True,
cfg = "target",
),
"_v8_annotate_torque_ir": attr.label(default = "//:v8_annotate_torque_ir"),
},
)
def _mksnapshot(ctx):
outs = [
ctx.actions.declare_file("snapshot.cc"),
ctx.actions.declare_file("embedded.S"),
]
ctx.actions.run(
outputs = outs,
inputs = [],
arguments = [
"--embedded_variant=Default",
"--startup_src", outs[0].path,
"--embedded_src", outs[1].path,
],
executable = ctx.executable.tool,
progress_message = "Running mksnapshot"
)
return [DefaultInfo(files = depset(outs))]
v8_mksnapshot = rule(
implementation = _mksnapshot,
attrs = {
"tool": attr.label(
default = "//:mksnapshot",
allow_files = True,
executable = True,
cfg = "target",
),
}
)
# Copyright 2021 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
BAZEL_OUT=$1
# Create a default GN output folder
gn gen out/inspector
# Generate inspector files
autoninja -C out/inspector src/inspector:inspector
# Create directories in bazel output folder
mkdir -p $BAZEL_OUT/include/inspector
mkdir -p $BAZEL_OUT/src/inspector/protocol
# Copy generated files to bazel output folder
cp out/inspector/gen/include/inspector/* $BAZEL_OUT/include/inspector/
cp out/inspector/gen/src/inspector/protocol/* $BAZEL_OUT/src/inspector/protocol/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment