Repository: nodejs/node
Pull request: [v22.x backport] tools: extract target abseil to abseil.gyp

Both V8 and perfetto depends on abseil. When perfetto support is enabled, V8 also depends on perfetto.

In order to share abseil between perfetto and V8 targets, and avoid cycle dependencies between `v8.gyp` and `perfetto.gyp`, this extracts target `abseil` from `v8.gyp` to an independent file `abseil.gyp`.

PR-URL: https://github.com/nodejs/node/pull/57289
Refs: https://github.com/nodejs/diagnostics/issues/654
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>

<!--
Before submitting a pull request, please read:

- the CONTRIBUTING guide at https://github.com/nodejs/node/blob/HEAD/CONTRIBUTING.md
- the commit message formatting guidelines at
  https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines

For code changes:
1. Include tests for any bug fixes or new features.
2. Update documentation if relevant.
3. Ensure that `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes.

If you believe this PR should be highlighted in the Node.js CHANGELOG
please add the `notable-change` label.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->


Changed files:
filename: node.gyp
patch: @@ -840,6 +840,7 @@
         'deps/googletest/googletest.gyp:gtest_prod',
         'deps/histogram/histogram.gyp:histogram',
         'deps/nbytes/nbytes.gyp:nbytes',
+        'tools/v8_gypfiles/abseil.gyp:abseil',
         'node_js2c#host',
       ],
 
@@ -1162,6 +1163,7 @@
         'deps/googletest/googletest.gyp:gtest_main',
         'deps/histogram/histogram.gyp:histogram',
         'deps/nbytes/nbytes.gyp:nbytes',
+        'tools/v8_gypfiles/abseil.gyp:abseil',
       ],
 
       'includes': [

filename: src/node.cc
patch: @@ -119,6 +119,8 @@
 #include <unistd.h>        // STDIN_FILENO, STDERR_FILENO
 #endif
 
+#include "absl/synchronization/mutex.h"
+
 // ========== global C++ headers ==========
 
 #include <cerrno>
@@ -1258,6 +1260,11 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args,
 
   if (!(flags & ProcessInitializationFlags::kNoInitializeV8)) {
     V8::Initialize();
+
+    // Disable absl deadlock detection in V8 as it reports false-positive cases.
+    // TODO(legendecas): Replace this global disablement with case suppressions.
+    // https://github.com/nodejs/node-v8/issues/301
+    absl::SetMutexDeadlockDetectionMode(absl::OnDeadlockCycle::kIgnore);
   }
 
   if (!(flags & ProcessInitializationFlags::kNoInitializeCppgc)) {

filename: test/cctest/node_test_fixture.cc
patch: @@ -1,4 +1,5 @@
 #include "node_test_fixture.h"
+#include "absl/synchronization/mutex.h"
 #include "cppgc/platform.h"
 
 ArrayBufferUniquePtr NodeZeroIsolateTestFixture::allocator{nullptr, nullptr};
@@ -31,6 +32,11 @@ void NodeTestEnvironment::SetUp() {
   v8::V8::SetFlagsFromString("--no-freeze-flags-after-init");
 
   v8::V8::Initialize();
+
+  // Disable absl deadlock detection in V8 as it reports false-positive cases.
+  // TODO(legendecas): Replace this global disablement with case suppressions.
+  // https://github.com/nodejs/node-v8/issues/301
+  absl::SetMutexDeadlockDetectionMode(absl::OnDeadlockCycle::kIgnore);
 }
 
 void NodeTestEnvironment::TearDown() {

filename: tools/v8_gypfiles/abseil.gyp
patch: @@ -267,6 +267,8 @@
         '<(ABSEIL_ROOT)/absl/synchronization/internal/waiter.h',
         '<(ABSEIL_ROOT)/absl/synchronization/internal/waiter_base.h',
         '<(ABSEIL_ROOT)/absl/synchronization/internal/waiter_base.cc',
+        '<(ABSEIL_ROOT)/absl/synchronization/internal/win32_waiter.h',
+        '<(ABSEIL_ROOT)/absl/synchronization/internal/win32_waiter.cc',
         '<(ABSEIL_ROOT)/absl/synchronization/mutex.h',
         '<(ABSEIL_ROOT)/absl/synchronization/mutex.cc',
         '<(ABSEIL_ROOT)/absl/time/civil_time.h',