diff --git a/src/3rdparty/gn/base/bind_internal.h b/src/3rdparty/gn/base/bind_internal.h
index 0dc59e6..0720e05 100644
--- a/src/3rdparty/gn/base/bind_internal.h
+++ b/src/3rdparty/gn/base/bind_internal.h
@@ -403,7 +403,7 @@ struct FunctorTraits<R (*)(Args...)> {
   }
 };
 
-#if defined(OS_WIN) && !defined(ARCH_CPU_X86_64)
+#if defined(COMPILER_MSVC) && !defined(ARCH_CPU_X86_64)
 
 // For functions.
 template <typename R, typename... Args>
@@ -431,7 +431,7 @@ struct FunctorTraits<R(__fastcall*)(Args...)> {
   }
 };
 
-#endif  // defined(OS_WIN) && !defined(ARCH_CPU_X86_64)
+#endif  // defined(COMPILER_MSVC) && !defined(ARCH_CPU_X86_64)
 
 // For methods.
 template <typename R, typename Receiver, typename... Args>
diff --git a/src/3rdparty/gn/base/files/file_enumerator.h b/src/3rdparty/gn/base/files/file_enumerator.h
index 81f757b..855a2d1 100644
--- a/src/3rdparty/gn/base/files/file_enumerator.h
+++ b/src/3rdparty/gn/base/files/file_enumerator.h
@@ -8,6 +8,7 @@
 #include <stddef.h>
 #include <stdint.h>
 
+#include <limits>
 #include <vector>
 
 #include "base/containers/stack.h"
diff --git a/src/3rdparty/gn/base/files/file_util_win.cc b/src/3rdparty/gn/base/files/file_util_win.cc
index 34d328b..87ce416 100644
--- a/src/3rdparty/gn/base/files/file_util_win.cc
+++ b/src/3rdparty/gn/base/files/file_util_win.cc
@@ -8,6 +8,7 @@
 
 #include <io.h>
 #include <psapi.h>
+#include <share.h> // for _SH_DENYNO
 #include <shellapi.h>
 #include <shlobj.h>
 #include <stddef.h>
diff --git a/src/3rdparty/gn/base/optional.h b/src/3rdparty/gn/base/optional.h
index 931305c..714e859 100644
--- a/src/3rdparty/gn/base/optional.h
+++ b/src/3rdparty/gn/base/optional.h
@@ -400,7 +400,7 @@ using RemoveCvRefT = std::remove_cv_t<std::remove_reference_t<T>>;
 // byte for its body. __declspec(empty_bases) enables the optimization.
 // cf)
 // https://blogs.msdn.microsoft.com/vcblog/2016/03/30/optimizing-the-layout-of-empty-base-classes-in-vs2015-update-2-3/
-#ifdef OS_WIN
+#ifdef _MSC_VER
 #define OPTIONAL_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
 #else
 #define OPTIONAL_DECLSPEC_EMPTY_BASES
diff --git a/src/3rdparty/gn/base/template_util.h b/src/3rdparty/gn/base/template_util.h
index dda9587..12f6385 100644
--- a/src/3rdparty/gn/base/template_util.h
+++ b/src/3rdparty/gn/base/template_util.h
@@ -119,7 +119,7 @@ struct is_trivially_copyable {
 // TODO(danakj): Remove this when android builders are all using a newer version
 // of gcc, or the android ndk is updated to a newer libc++ that does this for
 // us.
-#if _GNUC_VER >= 501
+#if _GNUC_VER >= 501 || defined(__clang__)
   static constexpr bool value = __is_trivially_copyable(T);
 #else
   static constexpr bool value =
diff --git a/src/3rdparty/gn/base/win/windows_types.h b/src/3rdparty/gn/base/win/windows_types.h
index d076c44..93031fb 100644
--- a/src/3rdparty/gn/base/win/windows_types.h
+++ b/src/3rdparty/gn/base/win/windows_types.h
@@ -12,6 +12,7 @@
 #include <concurrencysal.h>
 #include <sal.h>
 #include <specstrings.h>
+#include <stdint.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -21,8 +22,8 @@ extern "C" {
 
 typedef unsigned long DWORD;
 typedef long LONG;
-typedef __int64 LONGLONG;
-typedef unsigned __int64 ULONGLONG;
+typedef int64_t LONGLONG;
+typedef uint64_t ULONGLONG;
 
 #define VOID void
 typedef char CHAR;
@@ -43,11 +44,11 @@ typedef WORD UWORD;
 typedef WORD ATOM;
 
 #if defined(_WIN64)
-typedef __int64 INT_PTR, *PINT_PTR;
-typedef unsigned __int64 UINT_PTR, *PUINT_PTR;
+typedef int64_t INT_PTR, *PINT_PTR;
+typedef uint64_t UINT_PTR, *PUINT_PTR;
 
-typedef __int64 LONG_PTR, *PLONG_PTR;
-typedef unsigned __int64 ULONG_PTR, *PULONG_PTR;
+typedef int64_t LONG_PTR, *PLONG_PTR;
+typedef uint64_t ULONG_PTR, *PULONG_PTR;
 #else
 typedef __w64 int INT_PTR, *PINT_PTR;
 typedef __w64 unsigned int UINT_PTR, *PUINT_PTR;
@@ -125,11 +126,28 @@ struct CHROME_CONDITION_VARIABLE {
 // Work around there being two slightly different definitions in the SDK.
 #define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)
 #endif
+#ifndef TLS_OUT_OF_INDEXES
 #define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
+#endif
 #define HTNOWHERE 0
 #define MAX_PATH 260
 #define CS_GLOBALCLASS 0x4000
 
+#ifndef _MSC_VER
+#undef ERROR_SUCCESS
+#undef ERROR_FILE_NOT_FOUND
+#undef ERROR_ACCESS_DENIED
+#undef ERROR_INVALID_HANDLE
+#undef ERROR_SHARING_VIOLATION
+#undef ERROR_LOCK_VIOLATION
+#undef REG_BINARY
+#undef HKEY_CLASSES_ROOT
+#undef HKEY_LOCAL_MACHINE
+#undef HKEY_CURRENT_USER
+#undef READ_CONTROL
+#undef SYNCHRONIZE
+#endif
+
 #define ERROR_SUCCESS 0L
 #define ERROR_FILE_NOT_FOUND 2L
 #define ERROR_ACCESS_DENIED 5L
@@ -138,10 +156,16 @@ struct CHROME_CONDITION_VARIABLE {
 #define ERROR_LOCK_VIOLATION 33L
 #define REG_BINARY ( 3ul )
 
+#ifndef STATUS_PENDING
 #define STATUS_PENDING ((DWORD   )0x00000103L)
+#endif
 #define STILL_ACTIVE STATUS_PENDING
+#ifndef SUCCEEDED
 #define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
+#endif
+#ifndef FAILED
 #define FAILED(hr) (((HRESULT)(hr)) < 0)
+#endif
 
 #define HKEY_CLASSES_ROOT (( HKEY ) (ULONG_PTR)((LONG)0x80000000) )
 #define HKEY_LOCAL_MACHINE (( HKEY ) (ULONG_PTR)((LONG)0x80000002) )
@@ -161,7 +185,9 @@ struct CHROME_CONDITION_VARIABLE {
 
 #define STANDARD_RIGHTS_READ (READ_CONTROL)
 #define STANDARD_RIGHTS_WRITE (READ_CONTROL)
+#ifndef STANDARD_RIGHTS_ALL
 #define STANDARD_RIGHTS_ALL (0x001F0000L)
+#endif
 
 #define KEY_READ                ((STANDARD_RIGHTS_READ       |\
                                   KEY_QUERY_VALUE            |\
@@ -189,16 +215,24 @@ struct CHROME_CONDITION_VARIABLE {
 
 // Define some macros needed when prototyping Windows functions.
 
+#ifndef DECLSPEC_IMPORT
 #define DECLSPEC_IMPORT __declspec(dllimport)
+#endif
 #define WINBASEAPI DECLSPEC_IMPORT
 #define WINUSERAPI DECLSPEC_IMPORT
 #define WINAPI __stdcall
+#ifndef CALLBACK
 #define CALLBACK __stdcall
+#endif
 
 // clang-format on
 
 // Needed for optimal lock performance.
+#ifdef _MSC_VER
 WINBASEAPI _Releases_exclusive_lock_(*SRWLock) VOID WINAPI
+#else
+VOID WINAPI
+#endif
     ReleaseSRWLockExclusive(_Inout_ PSRWLOCK SRWLock);
 
 // Needed to support protobuf's GetMessage macro magic.
@@ -226,6 +260,33 @@ WINBASEAPI VOID WINAPI SetLastError(_In_ DWORD dwErrCode);
 // ensures that the same renaming will happen everywhere. Includes of this file
 // can be added wherever needed to ensure this consistent renaming.
 
+#ifndef _MSC_VER
+#undef CopyFile
+#undef CreateDirectory
+#undef CreateEvent
+#undef CreateFile
+#undef CreateService
+#undef DeleteFile
+#undef DispatchMessage
+#undef DrawText
+#undef GetComputerName
+#undef GetCurrentDirectory
+#undef GetCurrentTime
+#undef GetFileAttributes
+#undef GetMessage
+#undef GetUserName
+#undef LoadIcon
+#undef LoadImage
+#undef PostMessage
+#undef ReplaceFile
+#undef ReportEvent
+#undef SendMessage
+#undef SendMessageCallback
+#undef SetCurrentDirectory
+#undef StartService
+#undef StrCat
+#endif
+
 #define CopyFile CopyFileW
 #define CreateDirectory CreateDirectoryW
 #define CreateEvent CreateEventW
diff --git a/b/src/3rdparty/gn/build/build_mingw.ninja.template b/src/3rdparty/gn/build/build_mingw.ninja.template
new file mode 100644
index 0000000..27339a7
--- /dev/null
+++ b/src/3rdparty/gn/build/build_mingw.ninja.template
@@ -0,0 +1,13 @@
+rule cxx
+  command = $cxx -MMD -MF $out.d $includes $cflags -c $in -o $out
+  description = CXX $out
+  depfile = $out.d
+  deps = gcc
+
+rule alink_thin
+  command = $ar rcsT $out $in
+  description = AR $out
+
+rule link
+  command = $ld $ldflags -o $out -Wl,--start-group $in $libs -Wl,--end-group $solibs
+  description = LINK $out
diff --git a/src/3rdparty/gn/build/gen.py b/src/3rdparty/gn/build/gen.py
index 8c646be..95b7a55 100755
--- a/src/3rdparty/gn/build/gen.py
+++ b/src/3rdparty/gn/build/gen.py
@@ -34,7 +34,10 @@ class Platform(object):
     elif self._platform.startswith('mingw'):
       self._platform = 'mingw'
     elif self._platform.startswith('win'):
-      self._platform = 'msvc'
+      if 'MSC' in sys.version:
+        self._platform = 'msvc'
+      else:
+        self._platform = 'mingw'
     elif self._platform.startswith('aix'):
       self._platform = 'aix'
     elif self._platform.startswith('fuchsia'):
@@ -46,7 +49,7 @@ class Platform(object):
 
   @staticmethod
   def known_platforms():
-    return ['linux', 'darwin', 'msvc', 'aix', 'fuchsia', 'freebsd', 'openbsd']
+    return ['linux', 'darwin', 'mingw', 'msvc', 'aix', 'fuchsia', 'freebsd', 'openbsd']
 
   def platform(self):
     return self._platform
@@ -134,7 +137,7 @@ def GenerateLastCommitPosition(host, header):
   describe_output = subprocess.check_output(
       ['git', 'describe', 'HEAD', '--match', ROOT_TAG], shell=host.is_windows(),
       cwd=REPO_ROOT)
-  mo = re.match(ROOT_TAG + '-(\d+)-g([0-9a-f]+)', describe_output.decode())
+  mo = re.match(ROOT_TAG + '-(\\d+)-g([0-9a-f]+)', describe_output.decode())
   if not mo:
     raise ValueError(
         'Unexpected output from git describe when generating version header')
@@ -184,6 +187,7 @@ def WriteGenericNinja(path, static_libraries, executables,
 
   template_filename = os.path.join(SCRIPT_DIR, {
       'msvc': 'build_win.ninja.template',
+      'mingw': 'build_mingw.ninja.template',
       'darwin': 'build_mac.ninja.template',
       'linux': 'build_linux.ninja.template',
       'freebsd': 'build_linux.ninja.template',
@@ -194,10 +198,14 @@ def WriteGenericNinja(path, static_libraries, executables,
   with open(template_filename) as f:
     ninja_template = f.read()
 
-  if platform.is_windows():
+  if platform.is_msvc():
     executable_ext = '.exe'
     library_ext = '.lib'
     object_ext = '.obj'
+  elif platform.is_mingw():
+    executable_ext = '.exe'
+    library_ext = '.a'
+    object_ext = '.obj'
   else:
     executable_ext = ''
     library_ext = '.a'
@@ -301,6 +309,9 @@ def WriteGNNinja(path, platform, host, options):
   ld = options.ld
   ar = options.ar
 
+  if platform.is_mingw():
+    ld = options.cxx
+
   if not ar:
      if platform.is_msvc():
         ar = os.environ.get('AR', 'lib.exe')
@@ -327,7 +338,8 @@ def WriteGNNinja(path, platform, host, options):
       # or data item into its own section so --gc-sections can eliminate any
       # unused functions and data items.
       cflags.extend(['-fdata-sections', '-ffunction-sections'])
-      ldflags.extend(['-fdata-sections', '-ffunction-sections'])
+      if not platform.is_mingw():
+        ldflags.extend(['-fdata-sections', '-ffunction-sections'])
       if platform.is_darwin():
         ldflags.append('-Wl,-dead_strip')
       elif not platform.is_aix():
@@ -358,6 +370,20 @@ def WriteGNNinja(path, platform, host, options):
     ])
     cflags_cc.extend(['-std=c++14', '-Wno-c++11-narrowing'])
 
+    if platform.is_mingw():
+      cflags.remove('-pthread')
+      cflags.extend([
+          '-DNOMINMAX',
+          '-DUNICODE',
+          '-DWIN32_LEAN_AND_MEAN',
+          '-DWINVER=0x0A00',
+          '-D_CRT_SECURE_NO_DEPRECATE',
+          '-D_SCL_SECURE_NO_DEPRECATE',
+          '-D_UNICODE',
+          '-D_WIN32_WINNT=0x0A00',
+          '-D_HAS_EXCEPTIONS=0',
+      ])
+
     if platform.is_linux():
       ldflags.append('-Wl,--as-needed')
 
@@ -714,17 +740,17 @@ def WriteGNNinja(path, platform, host, options):
     ])
 
     libs.extend([
-        'advapi32.lib',
-        'dbghelp.lib',
-        'kernel32.lib',
-        'ole32.lib',
-        'shell32.lib',
-        'user32.lib',
-        'userenv.lib',
-        'version.lib',
-        'winmm.lib',
-        'ws2_32.lib',
-        'Shlwapi.lib',
+        '-ladvapi32',
+        '-ldbghelp',
+        '-lkernel32',
+        '-lole32',
+        '-lshell32',
+        '-luser32',
+        '-luserenv',
+        '-lversion',
+        '-lwinmm',
+        '-lws2_32',
+        '-lshlwapi',
     ])
 
   # we just build static libraries that GN needs
@@ -737,9 +763,9 @@ def WriteGNNinja(path, platform, host, options):
 
 def windows_target_build_arch():
     target_arch = os.environ.get('Platform')
-    if target_arch in ['x64', 'x86']: return target_arch
+    if target_arch in ['arm64', 'x64', 'x86']: return target_arch
 
-    if platform.machine().lower() in ['x86_64', 'amd64']: return 'x64'
+    if platform.machine().lower() in ['x86_64', 'amd64', 'arm64']: return 'x64'
     return 'x86'
 
 if __name__ == '__main__':
diff --git a/src/3rdparty/gn/tools/gn/ninja_binary_target_writer.cc b/src/3rdparty/gn/tools/gn/ninja_binary_target_writer.cc
index db69186..76ab8f1 100644
--- a/src/3rdparty/gn/tools/gn/ninja_binary_target_writer.cc
+++ b/src/3rdparty/gn/tools/gn/ninja_binary_target_writer.cc
@@ -278,7 +278,11 @@ void NinjaBinaryTargetWriter::WriteLinkerFlags(
   }
 
   if (optional_def_file) {
+#ifdef _MSC_VER
     out_ << " /DEF:";
+#else
+    out_ << " ";
+#endif
     path_output_.WriteFile(out, *optional_def_file);
   }
 }
diff --git a/src/3rdparty/gn/util/sys_info.cc b/src/3rdparty/gn/util/sys_info.cc
index 5fefc9b..c6ea8b3 100644
--- a/src/3rdparty/gn/util/sys_info.cc
+++ b/src/3rdparty/gn/util/sys_info.cc
@@ -40,6 +40,8 @@ std::string OperatingSystemArchitecture() {
       return "x86";
     case PROCESSOR_ARCHITECTURE_AMD64:
       return "x86_64";
+    case PROCESSOR_ARCHITECTURE_ARM64:
+      return "arm64";
     case PROCESSOR_ARCHITECTURE_IA64:
       return "ia64";
   }
diff --git a/src/3rdparty/gn/util/worker_pool.cc b/src/3rdparty/gn/util/worker_pool.cc
index 60bcfbf..5b2cb26 100644
--- a/src/3rdparty/gn/util/worker_pool.cc
+++ b/src/3rdparty/gn/util/worker_pool.cc
@@ -32,7 +32,7 @@ void ProcessorGroupSetter::SetProcessorGroup(std::thread* thread) {
   if (num_groups_ <= 1)
     return;
 
-  const HANDLE thread_handle = thread->native_handle();
+  const HANDLE thread_handle = reinterpret_cast<void*>(thread->native_handle());
   ::GetThreadGroupAffinity(thread_handle, &group_affinity_);
   group_affinity_.Group = group_;
   const bool success =
