Skip to content

Commit

Permalink
[build] Add header for externally-visible defines
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Michael Lippautz <[email protected]>
Reviewed-by: Ross McIlroy <[email protected]>
Reviewed-by: Ulan Degenbaev <[email protected]>
Cr-Commit-Position: refs/heads/master@{#72140}
  • Loading branch information
danelphick authored and Commit Bot committed Jan 18, 2021
1 parent 18534a4 commit 553def5
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 46 deletions.
169 changes: 127 additions & 42 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -409,6 +413,7 @@ config("internal_config_base") {
".",
"include",
"$target_gen_dir",
"$target_gen_dir/include",
]
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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") {
Expand All @@ -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 += [
Expand All @@ -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" ]

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -3878,6 +3962,7 @@ v8_source_set("v8_base_without_compiler") {
":cppgc_base",
":generate_bytecode_builtins_list",
":run_torque",
":v8_headers",
":v8_maybe_icu",
]

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -4600,6 +4684,7 @@ v8_source_set("cppgc_base") {
]

public_deps = [
":v8_config_headers",
":v8_cppgc_shared",
":v8_libbase",
":v8_libplatform",
Expand Down
1 change: 1 addition & 0 deletions include/cppgc/internal/caged-heap-local-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions include/v8config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/heap/cppgc/caged-heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/heap/cppgc/heap-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions src/objects/compressed-slots.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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_
Loading

0 comments on commit 553def5

Please sign in to comment.