1

I'm following https://v8.dev/docs/embed to compile the sample program for embedding v8. I was able to complete it in Debian with no issues. I'm encountering compilation errors when building v8 on Windows.

I got the v8 source, and I tried compiling the latest master and refs/tags/9.1.193 due to the fact that the suggested refs/tags/7.1.11 in the tutorial requires VS 2017 and I have 2019. Furthermore I need the latest version of v8, not an old one.

Running gn args out.gn/x64.release.sample, I see that the args file contains this:

is_component_build = false
is_debug = false
target_cpu = "x64"
use_custom_libcxx = false
v8_monolithic = true
v8_use_external_startup_data = false

Step 4 of the tutorial, to run ninja -C out.gn/x64.release.sample v8_monolith, fails due to 3 similar compilation errors in obj/v8_base_without_compiler/debug-frames.obj, obj/v8_base_without_compiler/debug-evaluate.obj, and obj/v8_base_without_compiler/debug-coverage.obj.

This is part of the output:

FAILED: obj/v8_base_without_compiler/debug-coverage.obj
...
In file included from ../../src/debug/debug-coverage.cc:11:
../..\src/deoptimizer/deoptimizer.h(108,38): error: offset of on non-standard-layout type 'v8::internal::Deoptimizer' [-Werror,-Winvalid-offsetof]
  static int input_offset() { return offsetof(Deoptimizer, input_); }
                                     ^                     ~~~~~~
..\..\third_party\llvm-build\Release+Asserts\lib\clang\13.0.0\include\stddef.h(104,24): note: expanded from macro 'offsetof'
#define offsetof(t, d) __builtin_offsetof(t, d)
                       ^                     ~
In file included from ../../src/debug/debug-coverage.cc:11:
../..\src/deoptimizer/deoptimizer.h(110,12): error: offset of on non-standard-layout type 'v8::internal::Deoptimizer' [-Werror,-Winvalid-offsetof]
    return offsetof(Deoptimizer, output_count_);
           ^                     ~~~~~~~~~~~~~
..\..\third_party\llvm-build\Release+Asserts\lib\clang\13.0.0\include\stddef.h(104,24): note: expanded from macro 'offsetof'
#define offsetof(t, d) __builtin_offsetof(t, d)
                       ^                     ~
In file included from ../../src/debug/debug-coverage.cc:11:
../..\src/deoptimizer/deoptimizer.h(112,39): error: offset of on non-standard-layout type 'v8::internal::Deoptimizer' [-Werror,-Winvalid-offsetof]
  static int output_offset() { return offsetof(Deoptimizer, output_); }
                                      ^                     ~~~~~~~
..\..\third_party\llvm-build\Release+Asserts\lib\clang\13.0.0\include\stddef.h(104,24): note: expanded from macro 'offsetof'
#define offsetof(t, d) __builtin_offsetof(t, d)
                       ^                     ~
In file included from ../../src/debug/debug-coverage.cc:11:
../..\src/deoptimizer/deoptimizer.h(115,12): error: offset of on non-standard-layout type 'v8::internal::Deoptimizer' [-Werror,-Winvalid-offsetof]
    return offsetof(Deoptimizer, caller_frame_top_);
           ^                     ~~~~~~~~~~~~~~~~~
..\..\third_party\llvm-build\Release+Asserts\lib\clang\13.0.0\include\stddef.h(104,24): note: expanded from macro 'offsetof'
#define offsetof(t, d) __builtin_offsetof(t, d)
                       ^                     ~
4 errors generated.
[882/1736] CXX obj/torque_generated_initializers/test-torque-tq-csa.obj
ninja: build stopped: subcommand failed.

Similar errors on obj/v8_base_without_compiler/debug-frames.obj, obj/v8_base_without_compiler/debug-evaluate.obj

Is there a way to change the configuration so that I can compile v8 on Windows?

Ðаn
  • 10,934
  • 11
  • 59
  • 95
MakotoE
  • 1,814
  • 1
  • 20
  • 39

1 Answers1

1

Yes, disable the error mentioned in the message: -Winvalid-offsetof .

JDługosz
  • 5,592
  • 3
  • 24
  • 45
  • 1
    I don't think this is the best solution because that warning is critical I believe. If it was not something to be worried about the v8 devs would have specifically turned it off for that file. I added the flag `-w` in BUILD.gn to turn off all warnings, compiled the library, and was able to get the hello world example working. The right solution is something that doesn't involve changing the internal settings. – MakotoE Mar 25 '21 at 02:13
  • I think updating the source code to not do that would be much more trouble. _Why_ is it not a standard layout type? – JDługosz Mar 26 '21 at 14:34
  • 1
    this appears to be a common problem on windows. especially using Clang. there is an mail archive with someone with htis issue https://www.mail-archive.com/v8-users@googlegroups.com/msg13957.html someone mentions the flag in this answer (albeit named differently for some reason) and another one to do with loops. `-Wno-range-loop-construct` – Fornoreason1000 Oct 02 '21 at 04:40