Commit 553def5f authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[build] Add header for externally-visible defines

Adds a v8-gn.h file containing defines that are used in the
externally-visible headers files like v8.h. This must be included by
include/v8config.h which includes it if the GN flag
v8_generate_external_defines_header is on. (Currently off by default).

To enable the v8config.h file to be included without the other v8
headers (as required by cppgc), this moves it into its own header set
which sets up the include path correctly.

Also updates some headers to ensure v8config.h is included before using
externally-visible defines.

Bug: v8:11292
Change-Id: I5be634f4adfbef144bf684071461d64f1cb30899
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2608212
Commit-Queue: Dan Elphick <delphick@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72140}
parent 18534a42
......@@ -285,6 +285,10 @@ declare_args() {
# Experimental feature for always keeping prototypes in dict/"slow" mode
# Sets -DV8_DICT_MODE_PROTOTYPES
v8_dict_mode_prototypes = false
# If enabled then macro definitions that are used in externally visible
# header files are placed in a separate header file v8-gn.h.
v8_generate_external_defines_header = false
}
# Derived defaults.
......@@ -409,6 +413,7 @@ config("internal_config_base") {
".",
"include",
"$target_gen_dir",
"$target_gen_dir/include",
]
}
......@@ -458,6 +463,7 @@ config("libbase_config") {
if (is_android && current_toolchain != host_toolchain) {
libs += [ "log" ]
}
include_dirs = [ "$target_gen_dir/include" ]
}
# Standalone cppgc cannot be built within chrome or with perfetto.
......@@ -510,55 +516,99 @@ config("external_startup_data") {
}
}
# List of defines that can appear in externally visible header files and that
# are controlled by args.gn.
external_v8_defines = [
"V8_ENABLE_CHECKS",
"V8_COMPRESS_POINTERS",
"V8_31BIT_SMIS_ON_64BIT_ARCH",
"V8_COMPRESS_ZONES",
"V8_HEAP_SANDBOX",
"V8_DEPRECATION_WARNINGS",
"V8_IMMINENT_DEPRECATION_WARNINGS",
"V8_NO_ARGUMENTS_ADAPTOR",
"V8_USE_PERFETTO",
]
enabled_external_v8_defines = []
if (v8_enable_v8_checks) {
enabled_external_v8_defines += [ "V8_ENABLE_CHECKS" ]
}
if (v8_enable_pointer_compression) {
enabled_external_v8_defines += [ "V8_COMPRESS_POINTERS" ]
}
if (v8_enable_pointer_compression || v8_enable_31bit_smis_on_64bit_arch) {
enabled_external_v8_defines += [ "V8_31BIT_SMIS_ON_64BIT_ARCH" ]
}
if (v8_enable_zone_compression) {
enabled_external_v8_defines += [ "V8_COMPRESS_ZONES" ]
}
if (v8_enable_heap_sandbox) {
enabled_external_v8_defines += [ "V8_HEAP_SANDBOX" ]
}
if (v8_deprecation_warnings) {
enabled_external_v8_defines += [ "V8_DEPRECATION_WARNINGS" ]
}
if (v8_imminent_deprecation_warnings) {
enabled_external_v8_defines += [ "V8_IMMINENT_DEPRECATION_WARNINGS" ]
}
if (v8_use_perfetto) {
enabled_external_v8_defines += [ "V8_USE_PERFETTO" ]
}
disabled_external_v8_defines = external_v8_defines - enabled_external_v8_defines
# Put defines that are used in public headers here; public headers are
# defined in "v8_headers" and are included by embedders of V8.
config("v8_header_features") {
visibility = [ ":*" ]
defines = []
if (v8_enable_v8_checks) {
defines += [ "V8_ENABLE_CHECKS" ] # Used in "include/v8.h".
}
if (v8_enable_pointer_compression) {
defines += [ "V8_COMPRESS_POINTERS" ]
}
if (v8_enable_pointer_compression || v8_enable_31bit_smis_on_64bit_arch) {
defines += [ "V8_31BIT_SMIS_ON_64BIT_ARCH" ]
}
if (v8_enable_zone_compression) {
defines += [ "V8_COMPRESS_ZONES" ]
}
if (v8_enable_heap_sandbox) {
defines += [ "V8_HEAP_SANDBOX" ]
}
if (v8_deprecation_warnings) {
defines += [ "V8_DEPRECATION_WARNINGS" ]
}
if (v8_imminent_deprecation_warnings) {
defines += [ "V8_IMMINENT_DEPRECATION_WARNINGS" ]
}
if (v8_use_perfetto) {
defines += [ "V8_USE_PERFETTO" ]
if (v8_generate_external_defines_header) {
defines = [ "V8_GN_HEADER" ]
} else {
defines = enabled_external_v8_defines
}
}
# List of defines that can appear in externally visible cppgc header files and
# that are controlled by args.gn.
external_cppgc_defines = [
"CPPGC_SUPPORTS_OBJECT_NAMES",
"CPPGC_CAGED_HEAP",
"CPPGC_YOUNG_GENERATION",
]
enabled_external_cppgc_defines = []
if (cppgc_enable_object_names) {
enabled_external_cppgc_defines += [ "CPPGC_SUPPORTS_OBJECT_NAMES" ]
}
if (cppgc_enable_caged_heap) {
enabled_external_cppgc_defines += [ "CPPGC_CAGED_HEAP" ]
}
if (cppgc_enable_young_generation) {
enabled_external_cppgc_defines += [ "CPPGC_YOUNG_GENERATION" ]
}
disabled_external_cppgc_defines =
external_cppgc_defines - enabled_external_cppgc_defines
config("cppgc_header_features") {
visibility = [ ":*" ]
defines = []
if (cppgc_enable_object_names) {
defines += [ "CPPGC_SUPPORTS_OBJECT_NAMES" ]
}
if (cppgc_enable_caged_heap) {
defines += [ "CPPGC_CAGED_HEAP" ]
}
if (cppgc_enable_young_generation) {
defines += [ "CPPGC_YOUNG_GENERATION" ]
if (v8_generate_external_defines_header) {
defines = [ "V8_GN_HEADER" ]
} else {
defines = enabled_external_cppgc_defines
}
}
enabled_external_defines =
enabled_external_v8_defines + enabled_external_cppgc_defines
disabled_external_defines =
disabled_external_v8_defines + disabled_external_cppgc_defines
# Put defines here that are only used in our internal files and NEVER in
# external headers that embedders (such as chromium and node) might include.
config("features") {
......@@ -1991,6 +2041,18 @@ v8_header_set("v8_version") {
]
}
v8_header_set("v8_config_headers") {
configs = [ ":internal_config" ]
sources = [ "include/v8config.h" ]
deps = []
if (v8_generate_external_defines_header) {
sources += [ "$target_gen_dir/include/v8-gn.h" ]
deps += [ ":gen_v8_gn" ]
}
}
# This is split out to be a non-code containing target that the Chromium browser
# can depend upon to get basic v8 types.
v8_header_set("v8_headers") {
......@@ -2002,7 +2064,6 @@ v8_header_set("v8_headers") {
"include/v8-fast-api-calls.h",
"include/v8-internal.h",
"include/v8.h",
"include/v8config.h",
]
sources += [
......@@ -2013,9 +2074,37 @@ v8_header_set("v8_headers") {
"include/v8-wasm-trap-handler-win.h",
]
public_deps = [ ":v8_config_headers" ]
deps = [ ":v8_version" ]
}
if (v8_generate_external_defines_header) {
action("gen_v8_gn") {
visibility = [ ":*" ]
script = "tools/gen-v8-gn.py"
outputs = [ "$target_gen_dir/include/v8-gn.h" ]
args = [
"-o",
rebase_path("$target_gen_dir/include/v8-gn.h", root_build_dir),
]
foreach(define, enabled_external_defines) {
args += [
"-p",
define,
]
}
foreach(define, disabled_external_defines) {
args += [
"-n",
define,
]
}
}
}
v8_header_set("v8_wrappers") {
configs = [ ":internal_config" ]
......@@ -2346,19 +2435,14 @@ v8_source_set("v8_base_without_compiler") {
### gcmole(all) ###
"$target_gen_dir/builtins-generated/bytecodes-builtins-list.h",
"include/cppgc/common.h",
"include/v8-cppgc.h",
"include/v8-fast-api-calls.h",
"include/v8-inspector-protocol.h",
"include/v8-inspector.h",
"include/v8-internal.h",
"include/v8-metrics.h",
"include/v8-platform.h",
"include/v8-profiler.h",
"include/v8-unwinder-state.h",
"include/v8-util.h",
"include/v8-wasm-trap-handler-posix.h",
"include/v8.h",
"include/v8config.h",
"src/api/api-arguments-inl.h",
"src/api/api-arguments.cc",
"src/api/api-arguments.h",
......@@ -3878,6 +3962,7 @@ v8_source_set("v8_base_without_compiler") {
":cppgc_base",
":generate_bytecode_builtins_list",
":run_torque",
":v8_headers",
":v8_maybe_icu",
]
......@@ -4504,7 +4589,6 @@ v8_source_set("cppgc_base") {
"include/cppgc/trace-trait.h",
"include/cppgc/type-traits.h",
"include/cppgc/visitor.h",
"include/v8config.h",
"src/heap/cppgc/allocation.cc",
"src/heap/cppgc/compaction-worklists.cc",
"src/heap/cppgc/compaction-worklists.h",
......@@ -4600,6 +4684,7 @@ v8_source_set("cppgc_base") {
]
public_deps = [
":v8_config_headers",
":v8_cppgc_shared",
":v8_libbase",
":v8_libplatform",
......
......@@ -10,6 +10,7 @@
#include "cppgc/internal/api-constants.h"
#include "cppgc/internal/logging.h"
#include "cppgc/platform.h"
#include "v8config.h" // NOLINT(build/include_directory)
namespace cppgc {
namespace internal {
......
......@@ -5,6 +5,14 @@
#ifndef V8CONFIG_H_
#define V8CONFIG_H_
#ifdef V8_GN_HEADER
#if __cplusplus >= 201703L && !__has_include("v8-gn.h")
#error Missing v8-gn.h. The configuration for v8 is missing from the include \
path. Add it with -I<path> to the command line
#endif
#include "v8-gn.h" // NOLINT(build/include_directory)
#endif
// clang-format off
// Platform headers for feature detection below.
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "v8config.h" // NOLINT(build/include_directory)
#if !defined(CPPGC_CAGED_HEAP)
#error "Must be compiled with caged heap enabled"
#endif
......
......@@ -17,6 +17,7 @@
#include "src/heap/cppgc/object-allocator.h"
#include "src/heap/cppgc/raw-heap.h"
#include "src/heap/cppgc/sweeper.h"
#include "v8config.h" // NOLINT(build/include_directory)
#if defined(CPPGC_CAGED_HEAP)
#include "src/heap/cppgc/caged-heap.h"
......
......@@ -5,13 +5,13 @@
#ifndef V8_OBJECTS_COMPRESSED_SLOTS_H_
#define V8_OBJECTS_COMPRESSED_SLOTS_H_
#ifdef V8_COMPRESS_POINTERS
#include "include/v8config.h"
#include "src/objects/slots.h"
namespace v8 {
namespace internal {
#ifdef V8_COMPRESS_POINTERS
// A CompressedObjectSlot instance describes a kTaggedSize-sized field ("slot")
// holding a compressed tagged pointer (smi or heap object).
// Its address() is the address of the slot.
......@@ -141,9 +141,9 @@ class OffHeapCompressedObjectSlot
inline void Release_CompareAndSwap(Object old, Object target) const;
};
#endif // V8_COMPRESS_POINTERS
} // namespace internal
} // namespace v8
#endif // V8_COMPRESS_POINTERS
#endif // V8_OBJECTS_COMPRESSED_SLOTS_H_
#!/usr/bin/env python
# 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.
import argparse
from io import BytesIO
import os
import sys
def parse_args():
global args
parser = argparse.ArgumentParser()
parser.add_argument('-o', '--output', type=str, action='store',
help='Location of header file to generate')
parser.add_argument('-p', '--positive-define', type=str, action='append',
help='Externally visibile positive definition')
parser.add_argument('-n', '--negative-define', type=str, action='append',
help='Externally visibile negative definition')
args = parser.parse_args()
def generate_positive_definition(out, define):
out.write('''
#ifndef {define}
#define {define} 1
#else
#if {define} != 1
#error {define} defined but not set to 1
#endif
#endif // {define}
'''.format(define=define))
def generate_negative_definition(out, define):
out.write('''
#ifdef {define}
#error {define} is defined but is disabled by V8's GN build arguments
#endif // {define}
'''.format(define=define))
def generate_header(out):
out.write('''// AUTOMATICALLY GENERATED. DO NOT EDIT.\n
// The following definitions were used when V8 itself was built, but also appear
// in the externally-visible header files and so must be included by any
// embedder. This will be done automatically if V8_GN_HEADER is defined.
// Ready-compiled distributions of V8 will need to provide this generated header
// along with the other headers in include.
// This header must be stand-alone because it is used across targets without
// introducing dependencies. It should only be included via v8config.h.
''')
if args.positive_define:
for define in args.positive_define:
generate_positive_definition(out, define)
if args.negative_define:
for define in args.negative_define:
generate_negative_definition(out, define)
def main():
parse_args()
header_stream = BytesIO("")
generate_header(header_stream)
contents = header_stream.getvalue()
if args.output:
# Check if the contents has changed before writing so we don't cause build
# churn.
old_contents = None
if os.path.exists(args.output):
with open(args.output, 'r') as f:
old_contents = f.read()
if old_contents != contents:
with open(args.output, 'w') as f:
f.write(contents)
else:
print(contents)
if __name__ == '__main__':
main()
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