From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <sattard@salesforce.com>
Date: Wed, 13 Jul 2022 13:56:12 -0700
Subject: build: ensure native module compilation fails if not using a new
 enough builder

This should not be upstreamed, it is a quality-of-life patch for downstream module builders.

diff --git a/common.gypi b/common.gypi
index f3e0047fea1319034bf8b05b8d54d8a4ef181b4b..be0289ea7df50d7c2cb002c6343b75014729c923 100644
--- a/common.gypi
+++ b/common.gypi
@@ -79,6 +79,8 @@
     # TODO(refack): make v8-perfetto happen
     'v8_use_perfetto': 0,
 
+    'using_electron_config_gypi%': 0,
+
     ##### end V8 defaults #####
 
     # When building native modules using 'npm install' with the system npm,
@@ -282,6 +284,7 @@
       'V8_DEPRECATION_WARNINGS',
       'V8_IMMINENT_DEPRECATION_WARNINGS',
       '_GLIBCXX_USE_CXX11_ABI=1',
+      'ELECTRON_ENSURE_CONFIG_GYPI',
     ],
 
     # Forcibly disable -Werror.  We support a wide range of compilers, it's
@@ -388,6 +391,11 @@
           }],
         ],
       }],
+      ['using_electron_config_gypi == 1', {
+        'defines': [
+          'USING_ELECTRON_CONFIG_GYPI',
+        ],
+      }],
       ['v8_enable_pointer_compression == 1', {
         'defines': [
           'V8_COMPRESS_POINTERS',
diff --git a/configure.py b/configure.py
index 03ccbae0a1a837a382b98b828990d5a511f7a9d7..b5c747971a10b549007a8a3247aa5bd8058f311f 100755
--- a/configure.py
+++ b/configure.py
@@ -1529,6 +1529,7 @@ def configure_library(lib, output, pkgname=None):
 
 
 def configure_v8(o):
+  o['variables']['using_electron_config_gypi'] = 1
   o['variables']['v8_enable_webassembly'] = 1
   o['variables']['v8_enable_javascript_promise_hooks'] = 1
   o['variables']['v8_enable_lite_mode'] = 1 if options.v8_lite_mode else 0
diff --git a/src/node.h b/src/node.h
index 4b9b416e77b07407eae7b9587705b74ad3e6f211..deefda5c684c062f3c707fbdee30878a74d5dbb0 100644
--- a/src/node.h
+++ b/src/node.h
@@ -22,6 +22,12 @@
 #ifndef SRC_NODE_H_
 #define SRC_NODE_H_
 
+#ifdef ELECTRON_ENSURE_CONFIG_GYPI
+#ifndef USING_ELECTRON_CONFIG_GYPI
+#error "It looks like you are building this native module without using the right config.gypi.  This normally means that you need to update electron-rebuild (>=3.2.8) or node-gyp (>=9.0.0) if you're building modules directly."
+#endif
+#endif
+
 #ifdef _WIN32
 # ifndef BUILDING_NODE_EXTENSION
 #  define NODE_EXTERN __declspec(dllexport)
