diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b4e6cbe01..5018ed4c7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: # We use macos-11 over macos-latest because macos-latest defaults to Catalina(10.15) and not Big Sur(11.0) # We can switch to macos-latest whenever Big Sur becomes the default # See https://github.com/actions/virtual-environments#available-environments - platform: [ubuntu-latest, macos-11, windows-latest] + platform: [ubuntu-latest, macos-11] runs-on: ${{ matrix.platform }} steps: @@ -26,10 +26,6 @@ jobs: go-version: ${{ matrix.go-version }} - name: Checkout uses: actions/checkout@v2 - - name: Add MINGW to PATH - if: matrix.platform == 'windows-latest' - run: echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH - shell: bash - name: Go Test env: CGO_CXXFLAGS: "-Werror" @@ -45,16 +41,10 @@ jobs: - name: Add GOPATH to GITHUB_ENV run: echo "GOPATH=$(go env GOPATH)" >>"$GITHUB_ENV" - name: Scan and upload FOSSA data (Linux/Mac) - if: env.FOSSA_API_KEY != '' && github.ref == 'refs/heads/master' && matrix.platform != 'windows-latest' + if: env.FOSSA_API_KEY != '' && github.ref == 'refs/heads/master' run: | curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/master/install.sh | sudo bash fossa analyze env: FOSSA_API_KEY: ${{ secrets.FOSSA_API_KEY }} - - name: Scan and upload FOSSA data (Windows) - if: env.FOSSA_API_KEY != '' && github.ref == 'refs/heads/master' && matrix.platform == 'windows-latest' - run: | - Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/fossas/fossa-cli/master/install.ps1')) - C:\ProgramData\fossa-cli\fossa.exe analyze - env: - FOSSA_API_KEY: ${{ secrets.FOSSA_API_KEY }} + diff --git a/.github/workflows/v8build.yml b/.github/workflows/v8build.yml index 10c6480f7..bb7951e9e 100644 --- a/.github/workflows/v8build.yml +++ b/.github/workflows/v8build.yml @@ -14,13 +14,11 @@ jobs: # # We need xcode 12.4 or newer to cross compile between arm64/amd64 # https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md#xcode - platform: [ubuntu-18.04, macos-11, windows-latest] + platform: [ubuntu-18.04, macos-11] arch: [x86_64, arm64] exclude: - platform: ubuntu-18.04 arch: arm64 - - platform: windows-latest - arch: arm64 runs-on: ${{ matrix.platform }} steps: - name: Checkout @@ -37,16 +35,6 @@ jobs: - name: Build V8 macOS if: matrix.platform == 'macos-11' run: cd deps && ./build.py --arch ${{ matrix.arch }} - - name: Add MSYS2 to PATH - if: matrix.platform == 'windows-latest' - run: echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH - shell: bash - - name: Build V8 windows - if: matrix.platform == 'windows-latest' - run: cd deps; python build.py --no-clang --arch ${{ matrix.arch }} - env: - MSYSTEM: MINGW64 - DEPOT_TOOLS_WIN_TOOLCHAIN: 0 - name: Create PR uses: peter-evans/create-pull-request@v3 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index e1c5ae571..e0a21c2c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ to run a pre-compiled script in new contexts. - Removed error return value from Context.Isolate() which never fails - Removed error return value from NewObjectTemplate and NewFunctionTemplate. Panic if given a nil argument. - Function Call accepts receiver as first argument. +- Removed Windows support until its build issues are addressed. ### Fixed - Add some missing error propagation diff --git a/README.md b/README.md index 914883118..2b10506fb 100644 --- a/README.md +++ b/README.md @@ -192,21 +192,20 @@ please join the [**#v8go**](https://gophers.slack.com/channels/v8go) channel on ### Windows -In order to build a project using v8go on Windows, Go requires a gcc compiler to be installed. +There used to be Windows binary support. For further information see, [PR #234](https://github.com/rogchap/v8go/pull/234). -To set this up: -1. Install MSYS2 (https://www.msys2.org/) -2. Add the Mingw-w64 bin to your PATH environment variable (`C:\msys64\mingw64\bin` by default) -3. Open MSYS2 MSYS and execute `pacman -S mingw-w64-x86_64-toolchain` - -V8 requires 64-bit on Windows, therefore it will not work on 32-bit systems. +The v8go library would welcome contributions from anyone able to get an external windows +build of the V8 library linking with v8go, using the version of V8 checked out in the +`deps/v8` git submodule, and documentation of the process involved. This process will likely +involve passing a linker flag when building v8go (e.g. using the `CGO_LDFLAGS` environment +variable. ## V8 dependency V8 version: **9.0.257.18** (April 2021) In order to make `v8go` usable as a standard Go package, prebuilt static libraries of V8 -are included for Linux, macOS and Windows ie. you *should not* require to build V8 yourself. +are included for Linux and macOS. you *should not* require to build V8 yourself. Due to security concerns of binary blobs hiding malicious code, the V8 binary is built via CI *ONLY*. @@ -247,7 +246,7 @@ The next steps are: 1) The build is not yet triggered automatically. To trigger it manually, go to the [V8 Build](https://github.com/rogchap/v8go/actions?query=workflow%3A%22V8+Build%22) Github Action, Select "Run workflow", and select your pushed branch eg. `v8_upgrade/`. -1) Once built, this should open 3 PRs against your branch to add the `libv8.a` for Linux, macOS and Windows; merge +1) Once built, this should open 3 PRs against your branch to add the `libv8.a` for Linux (for x86_64) and macOS for x86_64 and arm64; merge these PRs into your branch. You are now ready to raise the PR against `master` with the latest version of V8. ### Flushing after C/C++ standard library printing for debugging diff --git a/cgo.go b/cgo.go index 142be8e38..36d603e04 100644 --- a/cgo.go +++ b/cgo.go @@ -11,7 +11,6 @@ package v8go // #cgo darwin,amd64 LDFLAGS: -L${SRCDIR}/deps/darwin_x86_64 // #cgo darwin,arm64 LDFLAGS: -L${SRCDIR}/deps/darwin_arm64 // #cgo linux LDFLAGS: -L${SRCDIR}/deps/linux_x86_64 -// #cgo windows LDFLAGS: -L${SRCDIR}/deps/windows_x86_64 -static -ldbghelp -lssp -lwinmm -lz import "C" // These imports forces `go mod vendor` to pull in all the folders that @@ -22,5 +21,4 @@ import ( _ "rogchap.com/v8go/deps/darwin_x86_64" _ "rogchap.com/v8go/deps/include" _ "rogchap.com/v8go/deps/linux_x86_64" - _ "rogchap.com/v8go/deps/windows_x86_64" ) diff --git a/deps/windows_x86_64/.gitattributes b/deps/windows_x86_64/.gitattributes deleted file mode 100644 index edc44c6a7..000000000 --- a/deps/windows_x86_64/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -*.patch text eol=lf -*.gn text eol=lf diff --git a/deps/windows_x86_64/0000-add-mingw-main-code-changes.patch b/deps/windows_x86_64/0000-add-mingw-main-code-changes.patch deleted file mode 100644 index e95fdd3e9..000000000 --- a/deps/windows_x86_64/0000-add-mingw-main-code-changes.patch +++ /dev/null @@ -1,882 +0,0 @@ -diff --git a/BUILD.gn b/BUILD.gn -index a9ab6783fa..54305731a4 100644 ---- a/BUILD.gn -+++ b/BUILD.gn -@@ -444,6 +444,11 @@ config("internal_config") { - if (is_component_build) { - defines += [ "BUILDING_V8_SHARED" ] - } -+ # Newer versions of gcc don't seem to trigger this warning, -+ # so remove this once it is no longer necesary -+ if(is_linux && !is_clang){ -+ cflags = ["-Wno-invalid-offsetof"] -+ } - } - - # Should be applied to all targets that write trace events. -@@ -942,17 +947,25 @@ config("toolchain") { - if (v8_current_cpu == "x86") { - defines += [ "V8_TARGET_ARCH_IA32" ] - if (is_win) { -- # Ensure no surprising artifacts from 80bit double math with x86. -- cflags += [ "/arch:SSE2" ] -+ if(!is_mingw){ -+ # Ensure no surprising artifacts from 80bit double math with x86. -+ cflags += [ "/arch:SSE2" ] -+ } else { -+ cflags += [ "-msse2" ] -+ } - } - } - if (v8_current_cpu == "x64") { - defines += [ "V8_TARGET_ARCH_X64" ] - if (is_win) { -- # Increase the initial stack size. The default is 1MB, this is 2MB. This -- # applies only to executables and shared libraries produced by V8 since -- # ldflags are not pushed to dependants. -- ldflags += [ "/STACK:2097152" ] -+ if(!is_mingw){ -+ # Increase the initial stack size. The default is 1MB, this is 2MB. This -+ # applies only to executables and shared libraries produced by V8 since -+ # ldflags are not pushed to dependants. -+ ldflags += [ "/STACK:2097152" ] -+ } else { -+ ldflags += [ "-Wl,--stack,2097152" ] -+ } - } - } - if (is_android && v8_android_log_stdout) { -@@ -1008,7 +1021,7 @@ config("toolchain") { - } - - if (v8_no_inline) { -- if (is_win) { -+ if (is_win && !is_mingw) { - cflags += [ "/Ob0" ] - } else { - cflags += [ -@@ -1032,7 +1045,7 @@ config("toolchain") { - } - } - -- if (is_win) { -+ if (is_win && !is_mingw) { - cflags += [ - "/wd4245", # Conversion with signed/unsigned mismatch. - "/wd4267", # Conversion with possible loss of data. -@@ -1054,11 +1067,11 @@ config("toolchain") { - ] - } - -- if (!is_clang && is_win) { -+ if (!is_clang && !is_mingw && is_win) { - cflags += [ "/wd4506" ] # Benign "no definition for inline function" - } - -- if (!is_clang && !is_win) { -+ if (!is_clang && (!is_win || is_mingw)) { - cflags += [ - # Disable gcc warnings for optimizations based on the assumption that - # signed overflow does not occur. Generates false positives (see -@@ -4499,17 +4512,25 @@ v8_component("v8_libbase") { - - defines += [ "_CRT_RAND_S" ] # for rand_s() - -- libs = [ -- "dbghelp.lib", -- "winmm.lib", -- "ws2_32.lib", -- ] -+ if(!is_mingw){ -+ libs = [ -+ "dbghelp.lib", -+ "winmm.lib", -+ "ws2_32.lib", -+ ] - -- if (v8_enable_system_instrumentation) { -- libs += [ "advapi32.lib" ] # Needed for TraceLoggingProvider.h -- } -+ if (v8_enable_system_instrumentation) { -+ libs += [ "advapi32.lib" ] # Needed for TraceLoggingProvider.h -+ } - -- data_deps += [ "//build/win:runtime_libs" ] -+ data_deps += [ "//build/win:runtime_libs" ] -+ } else { -+ libs = [ -+ "dbghelp", -+ "winmm", -+ "ws2_32", -+ ] -+ } - } - - if (v8_current_cpu == "mips" || v8_current_cpu == "mips64") { -@@ -4606,7 +4627,7 @@ v8_component("v8_libplatform") { - # TODO(skyostil): Switch TraceEventListener to protozero. - "//third_party/perfetto/protos/perfetto/trace:lite", - ] -- } else if (is_win) { -+ } else if (is_win && !is_mingw) { - sources -= [ "src/libplatform/tracing/recorder-default.cc" ] - sources += [ "src/libplatform/tracing/recorder-win.cc" ] - } -@@ -4652,7 +4673,7 @@ v8_source_set("v8_cppgc_shared") { - "src/heap/cppgc/sanitizers.h", - ] - -- if (is_clang || !is_win) { -+ if (is_clang || is_mingw || is_linux) { - if (current_cpu == "x64") { - sources += [ "src/heap/base/asm/x64/push_registers_asm.cc" ] - } else if (current_cpu == "x86") { -@@ -4672,7 +4693,7 @@ v8_source_set("v8_cppgc_shared") { - } else if (current_cpu == "riscv64") { - sources += [ "src/heap/base/asm/riscv64/push_registers_asm.cc" ] - } -- } else if (is_win) { -+ } else if (is_win && !is_mingw) { - if (current_cpu == "x64") { - sources += [ "src/heap/base/asm/x64/push_registers_masm.S" ] - } else if (current_cpu == "x86") { -@@ -4976,6 +4997,12 @@ if (current_toolchain == v8_snapshot_toolchain) { - - configs = [ ":internal_config" ] - -+ if(is_mingw) { -+ configs += [ -+ "//build/config/compiler:strip_debug", -+ ] -+ } -+ - deps = [ - ":v8_base_without_compiler", - ":v8_compiler_for_mksnapshot", -@@ -5202,10 +5229,18 @@ if (is_component_build) { - - public_deps = [ - ":v8_base", -+ ":v8_initializers", - ":v8_snapshot", - ] - -- configs = [ ":internal_config" ] -+ configs = [ -+ ":internal_config", -+ ] -+ if(is_mingw) { -+ configs += [ -+ "//build/config/compiler:strip_debug", -+ ] -+ } - - public_configs = [ ":external_config" ] - } -@@ -5225,7 +5260,16 @@ if (is_component_build) { - ":v8_snapshot", - ] - -- configs = [ ":internal_config" ] -+ configs = [ -+ ":internal_config", -+ ] -+ if(is_mingw) { -+ configs += [ -+ "//build/config/win:export_all_symbols", -+ "//build/config/compiler:strip_debug", -+ ] -+ } -+ - - public_configs = [ ":external_config" ] - } -diff --git a/include/cppgc/default-platform.h b/include/cppgc/default-platform.h -index 2ccdeddd83..c5ae1e581b 100644 ---- a/include/cppgc/default-platform.h -+++ b/include/cppgc/default-platform.h -@@ -18,7 +18,7 @@ namespace cppgc { - * Platform provided by cppgc. Uses V8's DefaultPlatform provided by - * libplatform internally. Exception: `GetForegroundTaskRunner()`, see below. - */ --class V8_EXPORT DefaultPlatform : public Platform { -+class DefaultPlatform : public Platform { - public: - /** - * Use this method instead of 'cppgc::InitializeProcess' when using -diff --git a/include/v8.h b/include/v8.h -index 7cb19bbede..b7b16d004c 100644 ---- a/include/v8.h -+++ b/include/v8.h -@@ -31,6 +31,11 @@ - #include "v8-version.h" // NOLINT(build/include_directory) - #include "v8config.h" // NOLINT(build/include_directory) - -+#if defined(__MINGW32__) || defined(__MINGW64__) -+// MinGW header files do not implicitly include windows.h -+struct _EXCEPTION_POINTERS; -+#endif -+ - // We reserve the V8_* prefix for macros defined in V8 public API and - // assume there are no name conflicts with the embedder's code. - -diff --git a/include/v8config.h b/include/v8config.h -index acd34d7a1f..ba4c75b71e 100644 ---- a/include/v8config.h -+++ b/include/v8config.h -@@ -129,7 +129,7 @@ path. Add it with -I to the command line - #elif defined(__QNXNTO__) - # define V8_OS_POSIX 1 - # define V8_OS_QNX 1 --#elif defined(_WIN32) -+#elif defined(_WIN32) || defined(__MINGW32__) || defined(__MINGW64__) - # define V8_OS_WIN 1 - #endif - -diff --git a/src/base/bits.h b/src/base/bits.h -index b137f73936..3bb4ceb7b6 100644 ---- a/src/base/bits.h -+++ b/src/base/bits.h -@@ -12,8 +12,10 @@ - #include "src/base/macros.h" - #if V8_CC_MSVC - #include -+#elif defined(__MINGW32__) -+#include - #endif --#if V8_OS_WIN32 -+#if V8_OS_WIN - #include "src/base/win32-headers.h" - #endif - -diff --git a/src/base/export-template.h b/src/base/export-template.h -index 861cfe4027..90c41f7097 100644 ---- a/src/base/export-template.h -+++ b/src/base/export-template.h -@@ -153,7 +153,12 @@ - - EXPORT_TEMPLATE_TEST(DEFAULT, ); - EXPORT_TEMPLATE_TEST(DEFAULT, __attribute__((visibility("default")))); -+#if defined(__MINGW32__) || defined(__MINGW64__) -+// On MingW MSVC_HACK breaks. -+EXPORT_TEMPLATE_TEST(DEFAULT, __declspec(dllexport)); -+#else - EXPORT_TEMPLATE_TEST(MSVC_HACK, __declspec(dllexport)); -+#endif - EXPORT_TEMPLATE_TEST(DEFAULT, __declspec(dllimport)); - - #undef EXPORT_TEMPLATE_TEST -diff --git a/src/base/platform/platform-win32.cc b/src/base/platform/platform-win32.cc -index 7f6c0e97d2..a0eedf5511 100644 ---- a/src/base/platform/platform-win32.cc -+++ b/src/base/platform/platform-win32.cc -@@ -4,21 +4,14 @@ - - // Platform-specific code for Win32. - --// Secure API functions are not available using MinGW with msvcrt.dll --// on Windows XP. Make sure MINGW_HAS_SECURE_API is not defined to --// disable definition of secure API functions in standard headers that --// would conflict with our own implementation. --#ifdef __MINGW32__ --#include <_mingw.h> --#ifdef MINGW_HAS_SECURE_API --#undef MINGW_HAS_SECURE_API --#endif // MINGW_HAS_SECURE_API --#endif // __MINGW32__ -- - #include - - #include "src/base/win32-headers.h" - -+#if defined(__MINGW32__) || defined(__MINGW64__) -+// REMOVE ONCE mingw functions.h file is fixed -+#undef __deref -+#endif - #include "src/base/bits.h" - #include "src/base/lazy-instance.h" - #include "src/base/macros.h" -@@ -33,71 +26,6 @@ - #include // NOLINT - #endif // defined(_MSC_VER) - --// Extra functions for MinGW. Most of these are the _s functions which are in --// the Microsoft Visual Studio C++ CRT. --#ifdef __MINGW32__ -- -- --#ifndef __MINGW64_VERSION_MAJOR -- --#define _TRUNCATE 0 --#define STRUNCATE 80 -- --inline void MemoryFence() { -- int barrier = 0; -- __asm__ __volatile__("xchgl %%eax,%0 ":"=r" (barrier)); --} -- --#endif // __MINGW64_VERSION_MAJOR -- -- --int localtime_s(tm* out_tm, const time_t* time) { -- tm* posix_local_time_struct = localtime_r(time, out_tm); -- if (posix_local_time_struct == nullptr) return 1; -- return 0; --} -- -- --int fopen_s(FILE** pFile, const char* filename, const char* mode) { -- *pFile = fopen(filename, mode); -- return *pFile != nullptr ? 0 : 1; --} -- --int _vsnprintf_s(char* buffer, size_t sizeOfBuffer, size_t count, -- const char* format, va_list argptr) { -- DCHECK(count == _TRUNCATE); -- return _vsnprintf(buffer, sizeOfBuffer, format, argptr); --} -- -- --int strncpy_s(char* dest, size_t dest_size, const char* source, size_t count) { -- CHECK(source != nullptr); -- CHECK(dest != nullptr); -- CHECK_GT(dest_size, 0); -- -- if (count == _TRUNCATE) { -- while (dest_size > 0 && *source != 0) { -- *(dest++) = *(source++); -- --dest_size; -- } -- if (dest_size == 0) { -- *(dest - 1) = 0; -- return STRUNCATE; -- } -- } else { -- while (dest_size > 0 && count > 0 && *source != 0) { -- *(dest++) = *(source++); -- --dest_size; -- --count; -- } -- } -- CHECK_GT(dest_size, 0); -- *dest = 0; -- return 0; --} -- --#endif // __MINGW32__ -- - namespace v8 { - namespace base { - -diff --git a/src/base/platform/time.cc b/src/base/platform/time.cc -index c399c52cb2..c0f80761eb 100644 ---- a/src/base/platform/time.cc -+++ b/src/base/platform/time.cc -@@ -787,13 +787,13 @@ ThreadTicks ThreadTicks::Now() { - #endif - #elif V8_OS_MACOSX - return ThreadTicks(ComputeThreadTicks()); --#elif(defined(_POSIX_THREAD_CPUTIME) && (_POSIX_THREAD_CPUTIME >= 0)) || \ -- defined(V8_OS_ANDROID) -- return ThreadTicks(ClockNow(CLOCK_THREAD_CPUTIME_ID)); - #elif V8_OS_SOLARIS - return ThreadTicks(gethrvtime() / Time::kNanosecondsPerMicrosecond); - #elif V8_OS_WIN - return ThreadTicks::GetForThread(::GetCurrentThread()); -+#elif(defined(_POSIX_THREAD_CPUTIME) && (_POSIX_THREAD_CPUTIME >= 0)) || \ -+ defined(V8_OS_ANDROID) -+ return ThreadTicks(ClockNow(CLOCK_THREAD_CPUTIME_ID)); - #else - UNREACHABLE(); - #endif -diff --git a/src/base/win32-headers.h b/src/base/win32-headers.h -index 82555463c0..08c67bc13a 100644 ---- a/src/base/win32-headers.h -+++ b/src/base/win32-headers.h -@@ -38,17 +38,9 @@ - #include // For timeGetTime(). - #include // For raise(). - #include // For LocalOffset() implementation. --#ifdef __MINGW32__ --// Require Windows XP or higher when compiling with MinGW. This is for MinGW --// header files to expose getaddrinfo. --#undef _WIN32_WINNT --#define _WIN32_WINNT 0x501 --#endif // __MINGW32__ --#if !defined(__MINGW32__) || defined(__MINGW64_VERSION_MAJOR) - #include // For SymLoadModule64 and al. - #include // For STRUNCATE - #include // For IsWindows8OrGreater(). --#endif // !defined(__MINGW32__) || defined(__MINGW64_VERSION_MAJOR) - #include // For INT_MAX and al. - #include // For Module32First and al. - -@@ -56,9 +48,7 @@ - // makes it impossible to have them elsewhere. - #include - #include --#ifndef __MINGW32__ - #include --#endif // __MINGW32__ - #include // For _beginthreadex(). - #include - -@@ -80,5 +70,5 @@ - #undef RotateLeft32 - #undef RotateRight64 - #undef RotateLeft64 -- -+#undef __deref - #endif // V8_BASE_WIN32_HEADERS_H_ -diff --git a/src/codegen/code-stub-assembler.h b/src/codegen/code-stub-assembler.h -index 03af2cc5e2..bb19092c54 100644 ---- a/src/codegen/code-stub-assembler.h -+++ b/src/codegen/code-stub-assembler.h -@@ -301,7 +301,7 @@ enum class PrimitiveType { kBoolean, kNumber, kString, kSymbol }; - // it's possible to add JavaScript-specific useful CodeAssembler "macros" - // without modifying files in the compiler directory (and requiring a review - // from a compiler directory OWNER). --class V8_EXPORT_PRIVATE CodeStubAssembler -+class V8_EXPORT CodeStubAssembler - : public compiler::CodeAssembler, - public TorqueGeneratedExportedMacrosAssembler { - public: -diff --git a/src/codegen/handler-table.cc b/src/codegen/handler-table.cc -index 8aec047d13..c409d55f0e 100644 ---- a/src/codegen/handler-table.cc -+++ b/src/codegen/handler-table.cc -@@ -219,6 +219,12 @@ int HandlerTable::LookupReturn(int pc_offset) { - difference_type operator-(const Iterator& other) const { - return index - other.index; - } -+#ifdef _GLIBCXX_DEBUG -+ bool operator<=(const Iterator& other) const -+ { -+ return index <= other.index; -+ } -+#endif - HandlerTable* table; - int index; - }; -diff --git a/src/common/globals.h b/src/common/globals.h -index d9d502aa51..ea7e54e21d 100644 ---- a/src/common/globals.h -+++ b/src/common/globals.h -@@ -1348,7 +1348,7 @@ class BinaryOperationFeedback { - // This is distinct from BinaryOperationFeedback on purpose, because the - // feedback that matters differs greatly as well as the way it is consumed. - class CompareOperationFeedback { -- enum { -+ enum : uint32_t { - kSignedSmallFlag = 1 << 0, - kOtherNumberFlag = 1 << 1, - kBooleanFlag = 1 << 2, -@@ -1362,7 +1362,7 @@ class CompareOperationFeedback { - }; - - public: -- enum Type { -+ enum Type : uint32_t { - kNone = 0, - - kBoolean = kBooleanFlag, -@@ -1375,7 +1375,7 @@ class CompareOperationFeedback { - kNumberOrOddball = kNumber | kOddball, - - kInternalizedString = kInternalizedStringFlag, -- kString = kInternalizedString | kOtherStringFlag, -+ kString = kInternalizedString | kOtherNumberFlag, - - kReceiver = kReceiverFlag, - kReceiverOrNullOrUndefined = kReceiver | kNullOrUndefined, -diff --git a/src/compiler/node-cache.h b/src/compiler/node-cache.h -index 8e1d3d4eae..c55d8329de 100644 ---- a/src/compiler/node-cache.h -+++ b/src/compiler/node-cache.h -@@ -29,7 +29,7 @@ class Node; - // nodes such as constants, parameters, etc. - template , - typename Pred = std::equal_to > --class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) NodeCache final { -+class V8_EXPORT_PRIVATE NodeCache final { - public: - explicit NodeCache(Zone* zone) : map_(zone) {} - ~NodeCache() = default; -diff --git a/src/heap/paged-spaces-inl.h b/src/heap/paged-spaces-inl.h -index e135e30efc..0c055247bc 100644 ---- a/src/heap/paged-spaces-inl.h -+++ b/src/heap/paged-spaces-inl.h -@@ -19,7 +19,7 @@ namespace internal { - // ----------------------------------------------------------------------------- - // PagedSpaceObjectIterator - --HeapObject PagedSpaceObjectIterator::Next() { -+inline HeapObject PagedSpaceObjectIterator::Next() { - do { - HeapObject next_obj = FromCurrentPage(); - if (!next_obj.is_null()) return next_obj; -diff --git a/src/heap/paged-spaces.h b/src/heap/paged-spaces.h -index 5168f0f053..ae5c22d1f3 100644 ---- a/src/heap/paged-spaces.h -+++ b/src/heap/paged-spaces.h -@@ -45,7 +45,7 @@ class V8_EXPORT_PRIVATE PagedSpaceObjectIterator : public ObjectIterator { - // Advance to the next object, skipping free spaces and other fillers and - // skipping the special garbage section of which there is one per space. - // Returns nullptr when the iteration has ended. -- inline HeapObject Next() override; -+ HeapObject Next() override; - - private: - // Fast (inlined) path of next(). -diff --git a/src/objects/feedback-vector.cc b/src/objects/feedback-vector.cc -index a77ea5d265..0cddb92a02 100644 ---- a/src/objects/feedback-vector.cc -+++ b/src/objects/feedback-vector.cc -@@ -114,9 +114,9 @@ Handle FeedbackMetadata::New(LocalIsolate* isolate, - return metadata; - } - --template Handle FeedbackMetadata::New( -+template V8_EXPORT Handle FeedbackMetadata::New( - Isolate* isolate, const FeedbackVectorSpec* spec); --template Handle FeedbackMetadata::New( -+template V8_EXPORT Handle FeedbackMetadata::New( - LocalIsolate* isolate, const FeedbackVectorSpec* spec); - - bool FeedbackMetadata::SpecDiffersFrom( -diff --git a/src/objects/fixed-array-inl.h b/src/objects/fixed-array-inl.h -index 8c0412dcb6..599a6be8c8 100644 ---- a/src/objects/fixed-array-inl.h -+++ b/src/objects/fixed-array-inl.h -@@ -88,7 +88,7 @@ bool FixedArray::is_the_hole(Isolate* isolate, int index) { - return get(isolate, index).IsTheHole(isolate); - } - --void FixedArray::set(int index, Smi value) { -+inline V8_EXPORT_PRIVATE void FixedArray::set(int index, Smi value) { - DCHECK_NE(map(), GetReadOnlyRoots().fixed_cow_array_map()); - DCHECK_LT(static_cast(index), static_cast(length())); - DCHECK(Object(value).IsSmi()); -diff --git a/src/objects/fixed-array.h b/src/objects/fixed-array.h -index 53b4cbb22b..8dd24df399 100644 ---- a/src/objects/fixed-array.h -+++ b/src/objects/fixed-array.h -@@ -130,7 +130,7 @@ class FixedArray - inline bool is_the_hole(Isolate* isolate, int index); - - // Setter that doesn't need write barrier. -- inline void set(int index, Smi value); -+ inline V8_EXPORT_PRIVATE void set(int index, Smi value); - // Setter with explicit barrier mode. - inline void set(int index, Object value, WriteBarrierMode mode); - -diff --git a/src/objects/ordered-hash-table.h b/src/objects/ordered-hash-table.h -index ca1d29d2fd..7758da72d3 100644 ---- a/src/objects/ordered-hash-table.h -+++ b/src/objects/ordered-hash-table.h -@@ -7,8 +7,12 @@ - - #include "src/base/export-template.h" - #include "src/common/globals.h" -+#if defined(_M_IX86) && defined(_MSC_VER) -+#include "src/objects/fixed-array-inl.h" -+#else - #include "src/objects/fixed-array.h" - #include "src/objects/internal-index.h" -+#endif - #include "src/objects/js-objects.h" - #include "src/objects/smi.h" - #include "src/roots/roots.h" -diff --git a/src/profiler/heap-snapshot-generator.cc b/src/profiler/heap-snapshot-generator.cc -index 436dbe7797..6db3de346d 100644 ---- a/src/profiler/heap-snapshot-generator.cc -+++ b/src/profiler/heap-snapshot-generator.cc -@@ -191,7 +191,7 @@ HeapSnapshot::HeapSnapshot(HeapProfiler* profiler, bool global_objects_as_roots) - STATIC_ASSERT(kSystemPointerSize != 4 || sizeof(HeapGraphEdge) == 12); - STATIC_ASSERT(kSystemPointerSize != 8 || sizeof(HeapGraphEdge) == 24); - STATIC_ASSERT(kSystemPointerSize != 4 || sizeof(HeapEntry) == 32); --#if V8_CC_MSVC -+#if V8_CC_MSVC || defined(__MINGW32__) || defined(__MINGW64__) - STATIC_ASSERT(kSystemPointerSize != 8 || sizeof(HeapEntry) == 48); - #else // !V8_CC_MSVC - STATIC_ASSERT(kSystemPointerSize != 8 || sizeof(HeapEntry) == 40); -diff --git a/src/snapshot/snapshot-utils.cc b/src/snapshot/snapshot-utils.cc -index eb2372372c..7defadb4b1 100644 ---- a/src/snapshot/snapshot-utils.cc -+++ b/src/snapshot/snapshot-utils.cc -@@ -5,7 +5,7 @@ - #include "src/snapshot/snapshot-utils.h" - - #include "src/sanitizer/msan.h" --#include "third_party/zlib/zlib.h" -+#include "zlib.h" - - namespace v8 { - namespace internal { -diff --git a/src/trap-handler/handler-inside-win.cc b/src/trap-handler/handler-inside-win.cc -index e5ce133a6b..110efe78de 100644 ---- a/src/trap-handler/handler-inside-win.cc -+++ b/src/trap-handler/handler-inside-win.cc -@@ -25,7 +25,7 @@ - - #include "src/trap-handler/handler-inside-win.h" - --#include -+#include "src/base/win32-headers.h" - - #include "src/trap-handler/trap-handler-internal.h" - #include "src/trap-handler/trap-handler.h" -diff --git a/src/trap-handler/handler-inside-win.h b/src/trap-handler/handler-inside-win.h -index 6db28149e7..6d0219c79f 100644 ---- a/src/trap-handler/handler-inside-win.h -+++ b/src/trap-handler/handler-inside-win.h -@@ -5,7 +5,7 @@ - #ifndef V8_TRAP_HANDLER_HANDLER_INSIDE_WIN_H_ - #define V8_TRAP_HANDLER_HANDLER_INSIDE_WIN_H_ - --#include -+#include "src/base/win32-headers.h" - - #include "src/base/macros.h" - -diff --git a/src/trap-handler/handler-outside-win.cc b/src/trap-handler/handler-outside-win.cc -index 09673c8ccc..2d221a802d 100644 ---- a/src/trap-handler/handler-outside-win.cc -+++ b/src/trap-handler/handler-outside-win.cc -@@ -19,7 +19,7 @@ - // - // For the code that runs in the trap handler itself, see handler-inside.cc. - --#include -+#include "src/base/win32-headers.h" - - #include "src/trap-handler/handler-inside-win.h" - #include "src/trap-handler/trap-handler.h" -diff --git a/src/wasm/function-body-decoder-impl.h b/src/wasm/function-body-decoder-impl.h -index 6c9700b100..e3be3c31f5 100644 ---- a/src/wasm/function-body-decoder-impl.h -+++ b/src/wasm/function-body-decoder-impl.h -@@ -2006,7 +2006,7 @@ class WasmDecoder : public Decoder { - } - - // TODO(clemensb): This is only used by the interpreter; move there. -- V8_EXPORT_PRIVATE std::pair StackEffect(const byte* pc) { -+ std::pair StackEffect(const byte* pc) { - WasmOpcode opcode = static_cast(*pc); - // Handle "simple" opcodes with a fixed signature first. - const FunctionSig* sig = WasmOpcodes::Signature(opcode); -diff --git a/test/cctest/BUILD.gn b/test/cctest/BUILD.gn -index e63fe5ed35..416c81f4a0 100644 ---- a/test/cctest/BUILD.gn -+++ b/test/cctest/BUILD.gn -@@ -35,6 +35,12 @@ v8_executable("cctest") { - "../..:v8_tracing_config", - ":cctest_config", - ] -+ if(is_mingw) { -+ configs += [ -+ "//build/config/compiler:strip_debug", -+ ] -+ } -+ - - ldflags = [] - -@@ -475,17 +481,28 @@ v8_source_set("cctest_sources") { - } - - if (is_win) { -- # This warning is benignly triggered by the U16 and U32 macros in -- # bytecode-utils.h. -- # C4309: 'static_cast': truncation of constant value -- cflags += [ "/wd4309" ] -- -- # MSVS wants this for gay-{precision,shortest}.cc. -- cflags += [ "/bigobj" ] -- -- if (symbol_level == 2) { -- sources += [ "test-v8windbg.cc" ] -- deps += [ "../../tools/v8windbg:v8windbg_test" ] -+ if(is_mingw) { -+ # Buffer overrun warning... intended? -+ cflags += [ -+ "-Wno-array-bounds", -+ "-Wno-stringop-truncation" -+ ] -+ } else { -+ # This warning is benignly triggered by the U16 and U32 macros in -+ # bytecode-utils.h. -+ # C4309: 'static_cast': truncation of constant value -+ cflags += [ "/wd4309" ] -+ -+ # Buffer overrun warning... intended? -+ cflags += [ "/wd4789" ] -+ -+ # MSVS wants this for gay-{precision,shortest}.cc. -+ cflags += [ "/bigobj" ] -+ -+ if (symbol_level == 2) { -+ sources += [ "test-v8windbg.cc" ] -+ deps += [ "../../tools/v8windbg:v8windbg_test" ] -+ } - } - } - -diff --git a/test/unittests/BUILD.gn b/test/unittests/BUILD.gn -index 1940dfa77e..cda03d0bc1 100644 ---- a/test/unittests/BUILD.gn -+++ b/test/unittests/BUILD.gn -@@ -186,6 +186,12 @@ v8_executable("unittests") { - "../..:external_config", - "../..:internal_config_base", - ] -+ -+ if(is_mingw) { -+ configs += [ -+ "//build/config/compiler:strip_debug", -+ ] -+ } - } - - v8_source_set("unittests_sources") { -@@ -492,10 +498,12 @@ v8_source_set("unittests_sources") { - "//testing/gtest", - ] - -- if (is_win) { -+ if (is_win && !is_mingw) { - # This warning is benignly triggered by the U16 and U32 macros in - # bytecode-utils.h. - # C4309: 'static_cast': truncation of constant value - cflags = [ "/wd4309" ] -+ } else if (is_mingw) { -+ cflags = [ "-Wno-pessimizing-move" ] - } - } -diff --git a/test/unittests/wasm/trap-handler-win-unittest.cc b/test/unittests/wasm/trap-handler-win-unittest.cc -index 8ad753469e..193119b4f6 100644 ---- a/test/unittests/wasm/trap-handler-win-unittest.cc -+++ b/test/unittests/wasm/trap-handler-win-unittest.cc -@@ -2,7 +2,7 @@ - // Use of this source code is governed by a BSD-style license that can be - // found in the LICENSE file. - --#include -+#include "src/base/win32-headers.h" - - #include "include/v8.h" - #include "src/base/page-allocator.h" -diff --git a/test/unittests/wasm/trap-handler-x64-unittest.cc b/test/unittests/wasm/trap-handler-x64-unittest.cc -index 1d8efdae75..c7d6cb2469 100644 ---- a/test/unittests/wasm/trap-handler-x64-unittest.cc -+++ b/test/unittests/wasm/trap-handler-x64-unittest.cc -@@ -11,7 +11,7 @@ - #include - #include - #elif V8_OS_WIN --#include -+#include "src/base/win32-headers.h" - #endif - - #include "testing/gtest/include/gtest/gtest.h" -diff --git a/third_party/googletest/BUILD.gn b/third_party/googletest/BUILD.gn -index cfa9205547..f3b0051f61 100644 ---- a/third_party/googletest/BUILD.gn -+++ b/third_party/googletest/BUILD.gn -@@ -30,7 +30,7 @@ config("gtest_config") { - "src/googletest/include", - ] - -- if (is_win) { -+ if (is_win && !is_mingw) { - cflags = [ "/wd4800" ] # Unused variable warning. - } - } -diff --git a/tools/BUILD.gn b/tools/BUILD.gn -index 2f8197dd36..9b1e4fabb9 100644 ---- a/tools/BUILD.gn -+++ b/tools/BUILD.gn -@@ -15,7 +15,8 @@ group("gn_all") { - "jsfunfuzz:v8_jsfunfuzz", - ] - -- if (is_win) { -+ # MinGW does not support DbgModel yet -+ if (is_win && !is_mingw) { - data_deps += [ "v8windbg" ] - } - } -diff --git a/tools/debug_helper/BUILD.gn b/tools/debug_helper/BUILD.gn -index 54cd3b7a4c..9c6666871d 100644 ---- a/tools/debug_helper/BUILD.gn -+++ b/tools/debug_helper/BUILD.gn -@@ -99,10 +99,12 @@ v8_component("v8_debug_helper") { - "../..:v8_libbase", - "../..:v8_shared_internal_headers", - "../..:v8_tracing", -+ "../..:v8", - ] - - configs = [ ":internal_config" ] - if (v8_enable_i18n_support) { -+ public_deps = [ "//third_party/icu" ] - configs += [ "//third_party/icu:icu_config" ] - } - -diff --git a/tools/v8windbg/BUILD.gn b/tools/v8windbg/BUILD.gn -index 10d06a127f..49654be32c 100644 ---- a/tools/v8windbg/BUILD.gn -+++ b/tools/v8windbg/BUILD.gn -@@ -6,7 +6,9 @@ import("../../gni/v8.gni") - - config("v8windbg_config") { - # Required for successful compilation of SDK header file DbgModel.h. -- cflags_cc = [ "/Zc:twoPhase-" ] -+ if(!is_mingw){ -+ cflags_cc = [ "/Zc:twoPhase-", "/std:c++latest" ] -+ } - - include_dirs = [ "../.." ] - } -diff --git a/tools/v8windbg/base/dbgext.h b/tools/v8windbg/base/dbgext.h -index 8b36a8f361..f8d9f0d64e 100644 ---- a/tools/v8windbg/base/dbgext.h -+++ b/tools/v8windbg/base/dbgext.h -@@ -9,6 +9,7 @@ - #error Unicode not defined - #endif - -+#include - #include - #include - #include -diff --git a/tools/v8windbg/src/v8-debug-helper-interop.h b/tools/v8windbg/src/v8-debug-helper-interop.h -index f7d78c5dd3..1c70e54e7a 100644 ---- a/tools/v8windbg/src/v8-debug-helper-interop.h -+++ b/tools/v8windbg/src/v8-debug-helper-interop.h -@@ -5,10 +5,11 @@ - #ifndef V8_TOOLS_V8WINDBG_SRC_V8_DEBUG_HELPER_INTEROP_H_ - #define V8_TOOLS_V8WINDBG_SRC_V8_DEBUG_HELPER_INTEROP_H_ - --#include -- -+#include -+#include - #include - -+#include - #include - #include - #include -diff --git a/tools/v8windbg/test/debug-callbacks.h b/tools/v8windbg/test/debug-callbacks.h -index 8855d6ffbc..ed2b0f62e9 100644 ---- a/tools/v8windbg/test/debug-callbacks.h -+++ b/tools/v8windbg/test/debug-callbacks.h -@@ -9,6 +9,7 @@ - #error Unicode not defined - #endif - -+#include - #include - #include - #include diff --git a/deps/windows_x86_64/0001-add-mingw-toolchain.patch b/deps/windows_x86_64/0001-add-mingw-toolchain.patch deleted file mode 100644 index 4f9b87681..000000000 --- a/deps/windows_x86_64/0001-add-mingw-toolchain.patch +++ /dev/null @@ -1,1237 +0,0 @@ -diff --git a/config/BUILD.gn b/config/BUILD.gn -index c0a686022..8e73a31ce 100644 ---- a/config/BUILD.gn -+++ b/config/BUILD.gn -@@ -127,13 +127,13 @@ config("debug") { - defines += [ "DYNAMIC_ANNOTATIONS_PREFIX=NACL_" ] - } - -- if (is_win) { -+ if (is_win && !is_mingw) { - if (!enable_iterator_debugging && !use_custom_libcxx) { - # Iterator debugging is enabled by default by the compiler on debug - # builds, and we have to tell it to turn it off. - defines += [ "_HAS_ITERATOR_DEBUGGING=0" ] - } -- } else if ((is_linux || is_chromeos) && current_cpu == "x64" && -+ } else if ((is_linux || is_chromeos || is_mingw) && current_cpu == "x64" && - enable_iterator_debugging) { - # Enable libstdc++ debugging facilities to help catch problems early, see - # http://crbug.com/65151 . -@@ -168,7 +168,7 @@ config("release") { - - # This config defines the default libraries applied to all targets. - config("default_libs") { -- if (is_win) { -+ if (is_win && !is_mingw) { - # TODO(brettw) this list of defaults should probably be smaller, and - # instead the targets that use the less common ones (e.g. wininet or - # winspool) should include those explicitly. -@@ -294,8 +294,13 @@ group("shared_library_deps") { - - # Windows linker setup for EXEs and DLLs. - if (is_win) { -- _windows_linker_configs = [ -- "//build/config/win:sdk_link", -+ _windows_linker_configs = [] -+ if(!is_mingw){ -+ _windows_linker_configs += [ -+ "//build/config/win:sdk_link", -+ ] -+ } -+ _windows_linker_configs += [ - "//build/config/win:common_linker_setup", - ] - } -diff --git a/config/BUILDCONFIG.gn b/config/BUILDCONFIG.gn -index fa375deef..49daac2ee 100644 ---- a/config/BUILDCONFIG.gn -+++ b/config/BUILDCONFIG.gn -@@ -130,8 +130,12 @@ declare_args() { - # separate flags. - is_official_build = false - -+ # Set to true when compiling with the MinGW GCC compiler on the MSYS2 environment. -+ is_mingw = getenv("MSYSTEM") == "MINGW64" || getenv("MSYSTEM") == "MINGW32" -+ - # Set to true when compiling with the Clang compiler. - is_clang = current_os != "linux" || -+ !(getenv("MSYSTEM") == "MINGW64" || getenv("MSYSTEM") == "MINGW32") || - (current_cpu != "s390x" && current_cpu != "s390" && - current_cpu != "ppc64" && current_cpu != "ppc" && - current_cpu != "mips" && current_cpu != "mips64") -@@ -200,11 +204,15 @@ if (host_toolchain == "") { - if (target_cpu == "x86" || target_cpu == "x64") { - if (is_clang) { - host_toolchain = "//build/toolchain/win:win_clang_$target_cpu" -+ } else if (is_mingw) { -+ host_toolchain = "//build/toolchain/win:mingw_$target_cpu" - } else { - host_toolchain = "//build/toolchain/win:$target_cpu" - } - } else if (is_clang) { - host_toolchain = "//build/toolchain/win:win_clang_$host_cpu" -+ } else if (is_mingw) { -+ host_toolchain = "//build/toolchain/win:mingw_$host_cpu" - } else { - host_toolchain = "//build/toolchain/win:$host_cpu" - } -@@ -240,6 +248,8 @@ if (target_os == "android") { - # Beware, win cross builds have some caveats, see docs/win_cross.md - if (is_clang) { - _default_toolchain = "//build/toolchain/win:win_clang_$target_cpu" -+ } else if (is_mingw) { -+ _default_toolchain = "//build/toolchain/win:mingw_$target_cpu" - } else { - _default_toolchain = "//build/toolchain/win:$target_cpu" - } -diff --git a/config/compiler/BUILD.gn b/config/compiler/BUILD.gn -index 266b74b3b..e79c3e430 100644 ---- a/config/compiler/BUILD.gn -+++ b/config/compiler/BUILD.gn -@@ -286,8 +286,8 @@ config("compiler") { - } - - # In general, Windows is totally different, but all the other builds share -- # some common compiler and linker configuration. -- if (!is_win) { -+ # some common GCC configuration. -+ if (!is_win || is_mingw) { - # Common POSIX compiler flags setup. - # -------------------------------- - cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204 -@@ -301,7 +301,7 @@ config("compiler") { - } else { - cflags += [ "-fstack-protector" ] - } -- } else if ((is_posix && !is_chromeos_ash && !is_nacl) || is_fuchsia) { -+ } else if ((is_posix && !is_chromeos && !is_nacl) || is_fuchsia || is_mingw) { - # TODO(phajdan.jr): Use -fstack-protector-strong when our gcc supports it. - # See also https://crbug.com/533294 - cflags += [ "--param=ssp-buffer-size=4" ] -@@ -312,6 +312,12 @@ config("compiler") { - } else if (current_os != "aix") { - # Not available on aix. - cflags += [ "-fstack-protector" ] -+ if(is_mingw) { -+ # In MingW's GCC -fstack-protector -+ # needs to be passed to the linker as well -+ # for it to link against the ssp library -+ ldflags += [ "-fstack-protector" ] -+ } - } - } - -@@ -345,7 +351,7 @@ config("compiler") { - - # Non-Mac Posix and Fuchsia compiler flags setup. - # ----------------------------------- -- if ((is_posix && !is_apple) || is_fuchsia) { -+ if ((is_posix && !is_apple) || is_fuchsia || is_mingw) { - if (enable_profiling) { - if (!is_debug) { - cflags += [ "-g" ] -@@ -494,7 +500,7 @@ config("compiler") { - # TODO(thakis): Make the driver pass --color-diagnostics to the linker - # if -fcolor-diagnostics is passed to it, and pass -fcolor-diagnostics - # in ldflags instead. -- if (is_win) { -+ if (is_win && !is_mingw) { - # On Windows, we call the linker directly, instead of calling it through - # the driver. - ldflags += [ "--color-diagnostics" ] -@@ -522,7 +528,7 @@ config("compiler") { - - # C11/C++11 compiler flags setup. - # --------------------------- -- if (is_linux || is_chromeos || is_android || (is_nacl && is_clang) || -+ if (is_linux || is_mingw || is_chromeos || is_android || (is_nacl && is_clang) || - current_os == "aix") { - if (target_os == "android") { - cxx11_override = use_cxx11_on_android -@@ -673,7 +679,7 @@ config("compiler") { - # Tracked by llvm bug: https://bugs.llvm.org/show_bug.cgi?id=48245 - if (!is_android || current_cpu == "arm64") { - cflags += [ "-fwhole-program-vtables" ] -- if (!is_win) { -+ if (!is_win || is_mingw) { - ldflags += [ "-fwhole-program-vtables" ] - } - } -@@ -691,7 +697,7 @@ config("compiler") { - if (compiler_timing) { - if (is_clang && !is_nacl) { - cflags += [ "-ftime-trace" ] -- } else if (is_win) { -+ } else if (is_win && !is_mingw) { - cflags += [ - # "Documented" here: - # http://aras-p.info/blog/2017/10/23/Best-unknown-MSVC-flag-d2cgsummary/ -@@ -753,7 +759,7 @@ config("compiler") { - # Assign any flags set for the C compiler to asmflags so that they are sent - # to the assembler. The Windows assembler takes different types of flags - # so only do so for posix platforms. -- if (is_posix || is_fuchsia) { -+ if (is_posix || is_fuchsia || is_mingw) { - asmflags += cflags - asmflags += cflags_c - } -@@ -807,7 +813,7 @@ config("compiler_cpu_abi") { - ldflags = [] - defines = [] - -- if ((is_posix && !is_apple) || is_fuchsia) { -+ if ((is_posix && !is_apple) || is_fuchsia || is_mingw) { - # CPU architecture. We may or may not be doing a cross compile now, so for - # simplicity we always explicitly set the architecture. - if (current_cpu == "x64") { -@@ -1161,7 +1167,7 @@ config("compiler_deterministic") { - # Eliminate build metadata (__DATE__, __TIME__ and __TIMESTAMP__) for - # deterministic build. See https://crbug.com/314403 - if (!is_official_build) { -- if (is_win && !is_clang) { -+ if (is_win && !is_clang && !is_mingw) { - cflags += [ - "/wd4117", # Trying to define or undefine a predefined macro. - "/D__DATE__=", -@@ -1322,7 +1328,7 @@ config("default_warnings") { - cflags_cc = [] - ldflags = [] - -- if (is_win) { -+ if (is_win && !is_mingw) { - if (treat_warnings_as_errors) { - cflags += [ "/WX" ] - } -@@ -1532,15 +1538,32 @@ config("default_warnings") { - # files. - cflags += [ "-Wno-packed-not-aligned" ] - } -+ -+ if (is_mingw) { -+ cflags += [ -+ "-Wno-attributes", # "__decspec(dllimport) inline" -+ "-Wno-format", # PRIu64 llu support on MinGW -+ "-Wno-unused-but-set-variable", -+ "-Wno-stringop-overflow", # False positive overflow error on gcc 10 -+ -+ ] -+ cflags_cc += [ -+ "-Wno-subobject-linkage", # Tests having code in header files -+ ] -+ } - } - - # Common Clang and GCC warning setup. -- if (!is_win || is_clang) { -+ if (!is_win || is_clang || is_mingw) { - cflags += [ - # Disables. - "-Wno-missing-field-initializers", # "struct foo f = {0};" - "-Wno-unused-parameter", # Unused function parameters. -+ "-Wno-invalid-offsetof", # Use of "conditionally-supported" offsetof in c++17 - ] -+ if(is_clang){ -+ cflags += ["-Wno-range-loop-construct"] # Use of "conditionally-supported" offsetof in c++17 -+ } - } - - if (is_clang) { -@@ -1625,7 +1648,7 @@ config("default_warnings") { - # part of Chromium. - - config("chromium_code") { -- if (is_win) { -+ if (is_win && !is_mingw) { - cflags = [ "/W4" ] # Warning level 4. - - if (is_clang) { -@@ -1713,7 +1736,7 @@ config("no_chromium_code") { - cflags_cc = [] - defines = [] - -- if (is_win) { -+ if (is_win && !is_mingw) { - cflags += [ - "/W3", # Warning level 3. - "/wd4800", # Disable warning when forcing value to bool. -@@ -1772,7 +1795,7 @@ config("noshadowing") { - # Allows turning Run-Time Type Identification on or off. - - config("rtti") { -- if (is_win) { -+ if (is_win && !is_mingw) { - cflags_cc = [ "/GR" ] - } else { - cflags_cc = [ "-frtti" ] -@@ -1782,7 +1805,7 @@ config("rtti") { - config("no_rtti") { - # Some sanitizer configs may require RTTI to be left enabled globally - if (!use_rtti) { -- if (is_win) { -+ if (is_win && !is_mingw) { - cflags_cc = [ "/GR-" ] - } else { - cflags_cc = [ "-fno-rtti" ] -@@ -1835,7 +1858,7 @@ config("thin_archive") { - # Note: exceptions are disallowed in Google code. - - config("exceptions") { -- if (is_win) { -+ if (is_win && !is_mingw) { - # Enables exceptions in the STL. - if (!use_custom_libcxx) { - defines = [ "_HAS_EXCEPTIONS=1" ] -@@ -1844,11 +1867,16 @@ config("exceptions") { - } else { - cflags_cc = [ "-fexceptions" ] - cflags_objcc = cflags_cc -+ if (is_mingw && exclude_unwind_tables) { -+ # With exceptions explicitly allowed, override exclude_unwind_tables or -+ # linking will fail on MinGW -+ cflags_cc += [ "-funwind-tables", "-fasynchronous-unwind-tables" ] -+ } - } - } - - config("no_exceptions") { -- if (is_win) { -+ if (is_win && !is_mingw) { - # Disables exceptions in the STL. - # libc++ uses the __has_feature macro to control whether to use exceptions, - # so defining this macro is unnecessary. Defining _HAS_EXCEPTIONS to 0 also -@@ -1918,7 +1946,7 @@ config("no_shorten_64_warnings") { - if (is_clang) { - cflags = [ "-Wno-shorten-64-to-32" ] - } else { -- if (is_win) { -+ if (is_win && !is_mingw) { - # MSVC does not have an explicit warning equivalent to - # -Wshorten-64-to-32 but 4267 warns for size_t -> int - # on 64-bit builds, so is the closest. -@@ -1958,12 +1986,22 @@ config("no_incompatible_pointer_warnings") { - - # Shared settings for both "optimize" and "optimize_max" configs. - # IMPORTANT: On Windows "/O1" and "/O2" must go before the common flags. --if (is_win) { -- common_optimize_on_cflags = [ -+if (is_win && !is_mingw) { -+ common_optimize_on_cflags = [] -+ if(is_clang) { -+ common_optimize_on_cflags += [ - "/Ob2", # Both explicit and auto inlining. -+ ] -+ } else { -+ common_optimize_on_cflags += [ -+ "/Ob3", # Both explicit and auto inlining. -+ ] -+ } -+ common_optimize_on_cflags += [ - "/Oy-", # Disable omitting frame pointers, must be after /O2. - "/Zc:inline", # Remove unreferenced COMDAT (faster links). - ] -+ - if (!is_asan) { - common_optimize_on_cflags += [ - # Put data in separate COMDATs. This allows the linker -@@ -2063,7 +2101,7 @@ config("default_stack_frames") { - - # Default "optimization on" config. - config("optimize") { -- if (is_win) { -+ if (is_win && !is_mingw) { - if (chrome_pgo_phase != 2) { - # Favor size over speed, /O1 must be before the common flags. - # /O1 implies /Os and /GF. -@@ -2098,7 +2136,7 @@ config("optimize") { - - # Turn off optimizations. - config("no_optimize") { -- if (is_win) { -+ if (is_win && !is_mingw) { - cflags = [ - "/Od", # Disable optimization. - "/Ob0", # Disable all inlining (on by default). -@@ -2150,7 +2188,7 @@ config("optimize_max") { - configs = [ "//build/config/nacl:irt_optimize" ] - } else { - ldflags = common_optimize_on_ldflags -- if (is_win) { -+ if (is_win && !is_mingw) { - # Favor speed over size, /O2 must be before the common flags. - # /O2 implies /Ot, /Oi, and /GF. - cflags = [ "/O2" ] + common_optimize_on_cflags -@@ -2182,7 +2220,7 @@ config("optimize_speed") { - configs = [ "//build/config/nacl:irt_optimize" ] - } else { - ldflags = common_optimize_on_ldflags -- if (is_win) { -+ if (is_win && !is_mingw) { - # Favor speed over size, /O2 must be before the common flags. - # /O2 implies /Ot, /Oi, and /GF. - cflags = [ "/O2" ] + common_optimize_on_cflags -@@ -2314,7 +2352,7 @@ config("win_pdbaltpath") { - - # Full symbols. - config("symbols") { -- if (is_win) { -+ if (is_win && !is_mingw) { - if (is_clang) { - cflags = [ "/Z7" ] # Debug information in the .obj files. - } else { -@@ -2366,7 +2404,8 @@ config("symbols") { - # build-directory-independent output. pnacl and nacl-clang do support that - # flag, so we can use use -g1 for pnacl and nacl-clang compiles. - # gcc nacl is is_nacl && !is_clang, pnacl and nacl-clang are && is_clang. -- if (!is_nacl || is_clang) { -+ # mingw cannot handle the size of the debug symbols generated. -+ if (!is_mingw && (!is_nacl || is_clang)) { - cflags += [ "-g2" ] - } - -@@ -2417,7 +2456,7 @@ config("symbols") { - # This config guarantees to hold symbol for stack trace which are shown to user - # when crash happens in unittests running on buildbot. - config("minimal_symbols") { -- if (is_win) { -+ if (is_win && !is_mingw) { - # Functions, files, and line tables only. - cflags = [] - ldflags = [ "/DEBUG" ] -@@ -2476,7 +2515,7 @@ config("minimal_symbols") { - # told to not generate debug information and the linker then just puts function - # names in the final debug information. - config("no_symbols") { -- if (is_win) { -+ if (is_win && !is_mingw) { - ldflags = [ "/DEBUG" ] - - # All configs using /DEBUG should include this: -@@ -2569,6 +2608,11 @@ buildflag_header("compiler_buildflags") { - config("cet_shadow_stack") { - if (enable_cet_shadow_stack && is_win) { - assert(target_cpu == "x64") -- ldflags = [ "/CETCOMPAT" ] -+ if(is_mingw){ -+ ldflags = [ "-fcf-protection=full" ] -+ cflags = [ "-fcf-protection=full" ] -+ } else { -+ ldflags = [ "/CETCOMPAT" ] -+ } - } - } -diff --git a/config/linux/pkg-config.py b/config/linux/pkg-config.py -index 5adf70cc3..e28e798df 100644 ---- a/config/linux/pkg-config.py -+++ b/config/linux/pkg-config.py -@@ -41,7 +41,11 @@ from optparse import OptionParser - # Additionally, you can specify the option --atleast-version. This will skip - # the normal outputting of a dictionary and instead print true or false, - # depending on the return value of pkg-config for the given package. -- -+# -+# --pkg_config_libdir= allows direct override -+# of the PKG_CONFIG_LIBDIR environment library. -+# -+# --full-path-libs causes lib names to include their full path. - - def SetConfigPath(options): - """Set the PKG_CONFIG_LIBDIR environment variable. -@@ -105,11 +109,29 @@ def RewritePath(path, strip_prefix, sysroot): - return path - - -+flag_regex = re.compile("(-.)(.+)") -+ -+def FlagReplace(matchobj): -+ if matchobj.group(1) == '-I': -+ return matchobj.group(1) + subprocess.check_output([u'cygpath',u'-w',matchobj.group(2)]).strip().decode("utf-8") -+ if matchobj.group(1) == '-L': -+ return matchobj.group(1) + subprocess.check_output([u'cygpath',u'-w',matchobj.group(2)]).strip().decode("utf-8") -+ if matchobj.group(1) == '-l': -+ return matchobj.group(1) + matchobj.group(2) + '.lib' -+ return matchobj.group(0) -+ -+def ConvertGCCToMSVC(flags): -+ """Rewrites GCC flags into MSVC flags.""" -+ # need a better way to determine mingw vs msvc build -+ if 'win32' not in sys.platform or "GCC" in sys.version: -+ return flags -+ return [ flag_regex.sub(FlagReplace,flag) for flag in flags] -+ - def main(): - # If this is run on non-Linux platforms, just return nothing and indicate - # success. This allows us to "kind of emulate" a Linux build from other - # platforms. -- if "linux" not in sys.platform: -+ if "linux" not in sys.platform and 'win32' not in sys.platform: - print("[[],[],[],[],[]]") - return 0 - -@@ -122,12 +144,15 @@ def main(): - parser.add_option('-a', action='store', dest='arch', type='string') - parser.add_option('--system_libdir', action='store', dest='system_libdir', - type='string', default='lib') -+ parser.add_option('--pkg_config_libdir', action='store', dest='pkg_config_libdir', -+ type='string') - parser.add_option('--atleast-version', action='store', - dest='atleast_version', type='string') - parser.add_option('--libdir', action='store_true', dest='libdir') - parser.add_option('--dridriverdir', action='store_true', dest='dridriverdir') - parser.add_option('--version-as-components', action='store_true', - dest='version_as_components') -+ parser.add_option('--full-path-libs', action='store_true', dest='full_path_libs') - (options, args) = parser.parse_args() - - # Make a list of regular expressions to strip out. -@@ -144,6 +169,10 @@ def main(): - else: - prefix = '' - -+ # Override PKG_CONFIG_LIBDIR -+ if options.pkg_config_libdir: -+ os.environ['PKG_CONFIG_LIBDIR'] = options.pkg_config_libdir -+ - if options.atleast_version: - # When asking for the return value, just run pkg-config and print the return - # value, no need to do other work. -@@ -203,7 +232,7 @@ def main(): - # For now just split on spaces to get the args out. This will break if - # pkgconfig returns quoted things with spaces in them, but that doesn't seem - # to happen in practice. -- all_flags = flag_string.strip().split(' ') -+ all_flags = ConvertGCCToMSVC(flag_string.strip().split(' ')) - - - sysroot = options.sysroot -@@ -220,7 +249,10 @@ def main(): - continue; - - if flag[:2] == '-l': -- libs.append(RewritePath(flag[2:], prefix, sysroot)) -+ library = RewritePath(flag[2:], prefix, sysroot) -+ # Skip math library on MSVC -+ if library != 'm.lib': -+ libs.append(library) - elif flag[:2] == '-L': - lib_dirs.append(RewritePath(flag[2:], prefix, sysroot)) - elif flag[:2] == '-I': -@@ -237,6 +269,14 @@ def main(): - else: - cflags.append(flag) - -+ if options.full_path_libs: -+ full_path_libs = [] -+ for lib_dir in lib_dirs: -+ for lib in libs: -+ if os.path.isfile(lib_dir+"/"+lib): -+ full_path_libs.append(lib_dir+"/"+lib) -+ libs = full_path_libs -+ - # Output a GN array, the first one is the cflags, the second are the libs. The - # JSON formatter prints GN compatible lists when everything is a list of - # strings. -diff --git a/config/linux/pkg_config.gni b/config/linux/pkg_config.gni -index 428e44ac0..a0d2175ee 100644 ---- a/config/linux/pkg_config.gni -+++ b/config/linux/pkg_config.gni -@@ -45,6 +45,9 @@ declare_args() { - # in similar fashion by setting the `system_libdir` variable in the build's - # args.gn file to 'lib' or 'lib64' as appropriate for the target architecture. - system_libdir = "lib" -+ -+ # Allow directly overriding the PKG_CONFIG_LIBDIR enviroment variable -+ pkg_config_libdir = "" - } - - pkg_config_script = "//build/config/linux/pkg-config.py" -@@ -87,6 +90,17 @@ if (host_pkg_config != "") { - host_pkg_config_args = pkg_config_args - } - -+if (pkg_config_libdir != "") { -+ pkg_config_args += [ -+ "--pkg_config_libdir", -+ pkg_config_libdir, -+ ] -+ host_pkg_config_args += [ -+ "--pkg_config_libdir", -+ pkg_config_libdir, -+ ] -+} -+ - template("pkg_config") { - assert(defined(invoker.packages), - "Variable |packages| must be defined to be a list in pkg_config.") -diff --git a/config/win/BUILD.gn b/config/win/BUILD.gn -index 4870f67d4..19cc8594b 100644 ---- a/config/win/BUILD.gn -+++ b/config/win/BUILD.gn -@@ -46,7 +46,7 @@ declare_args() { - # is applied to all targets. It is here to separate out the logic that is - # Windows-only. - config("compiler") { -- if (current_cpu == "x86") { -+ if (current_cpu == "x86" && !is_mingw) { - asmflags = [ - # When /safeseh is specified, the linker will only produce an image if it - # can also produce a table of the image's safe exception handlers. This -@@ -57,27 +57,36 @@ config("compiler") { - ] - } - -- cflags = [ -- "/Gy", # Enable function-level linking. -- "/FS", # Preserve previous PDB behavior. -- "/bigobj", # Some of our files are bigger than the regular limits. -- "/utf-8", # Assume UTF-8 by default to avoid code page dependencies. -- ] -+ if(!is_mingw) { -+ cflags = [ -+ "/Gy", # Enable function-level linking. -+ "/FS", # Preserve previous PDB behavior. -+ "/bigobj", # Some of our files are bigger than the regular limits. -+ "/utf-8", # Assume UTF-8 by default to avoid code page dependencies. -+ ] -+ } else { -+ cflags = [ -+ "-Wa,-mbig-obj", -+ "-fno-keep-inline-dllexport" -+ ] -+ } - - if (is_clang) { - cflags += [ "/Zc:twoPhase" ] - } - -- # Force C/C++ mode for the given GN detected file type. This is necessary -- # for precompiled headers where the same source file is compiled in both -- # modes. -- cflags_c = [ "/TC" ] -- cflags_cc = [ "/TP" ] -+ if(!is_mingw) { -+ # Force C/C++ mode for the given GN detected file type. This is necessary -+ # for precompiled headers where the same source file is compiled in both -+ # modes. -+ cflags_c = [ "/TC" ] -+ cflags_cc = [ "/TP" ] - -- cflags += [ -- # Work around crbug.com/526851, bug in VS 2015 RTM compiler. -- "/Zc:sizedDealloc-", -- ] -+ cflags += [ -+ # Work around crbug.com/526851, bug in VS 2015 RTM compiler. -+ "/Zc:sizedDealloc-", -+ ] -+ } - - if (is_clang) { - # Required to make the 19041 SDK compatible with clang-cl. -@@ -150,7 +159,7 @@ config("compiler") { - ldflags += [ "/lldignoreenv" ] - } - -- if (!is_debug && !is_component_build) { -+ if (!is_debug && !is_component_build && !is_mingw) { - # Enable standard linker optimizations like GC (/OPT:REF) and ICF in static - # release builds. - # Release builds always want these optimizations, so enable them explicitly. -@@ -175,17 +184,19 @@ config("compiler") { - ldflags += [ "/PROFILE" ] - } - -- # arflags apply only to static_libraries. The normal linker configs are only -- # set for executable and shared library targets so arflags must be set -- # elsewhere. Since this is relatively contained, we just apply them in this -- # more general config and they will only have an effect on static libraries. -- arflags = [ -- # "No public symbols found; archive member will be inaccessible." This -- # means that one or more object files in the library can never be -- # pulled in to targets that link to this library. It's just a warning that -- # the source file is a no-op. -- "/ignore:4221", -- ] -+ if(!is_mingw){ -+ # arflags apply only to static_libraries. The normal linker configs are only -+ # set for executable and shared library targets so arflags must be set -+ # elsewhere. Since this is relatively contained, we just apply them in this -+ # more general config and they will only have an effect on static libraries. -+ arflags = [ -+ # "No public symbols found; archive member will be inaccessible." This -+ # means that one or more object files in the library can never be -+ # pulled in to targets that link to this library. It's just a warning that -+ # the source file is a no-op. -+ "/ignore:4221", -+ ] -+ } - } - - # This is included by reference in the //build/config/compiler:runtime_library -@@ -294,29 +305,31 @@ config("sdk_link") { - ldflags = [ "/MACHINE:ARM64" ] - } - -- vcvars_toolchain_data = exec_script("../../toolchain/win/setup_toolchain.py", -- [ -- visual_studio_path, -- windows_sdk_path, -- visual_studio_runtime_dirs, -- current_os, -- current_cpu, -- "none", -- ], -- "scope") -- -- vc_lib_path = vcvars_toolchain_data.vc_lib_path -- if (defined(vcvars_toolchain_data.vc_lib_atlmfc_path)) { -- vc_lib_atlmfc_path = vcvars_toolchain_data.vc_lib_atlmfc_path -- } -- vc_lib_um_path = vcvars_toolchain_data.vc_lib_um_path -+ if(!is_mingw){ -+ vcvars_toolchain_data = exec_script("../../toolchain/win/setup_toolchain.py", -+ [ -+ visual_studio_path, -+ windows_sdk_path, -+ visual_studio_runtime_dirs, -+ current_os, -+ current_cpu, -+ "none", -+ ], -+ "scope") -+ -+ vc_lib_path = vcvars_toolchain_data.vc_lib_path -+ if (defined(vcvars_toolchain_data.vc_lib_atlmfc_path)) { -+ vc_lib_atlmfc_path = vcvars_toolchain_data.vc_lib_atlmfc_path -+ } -+ vc_lib_um_path = vcvars_toolchain_data.vc_lib_um_path - -- lib_dirs = [ -- "$vc_lib_um_path", -- "$vc_lib_path", -- ] -- if (defined(vc_lib_atlmfc_path)) { -- lib_dirs += [ "$vc_lib_atlmfc_path" ] -+ lib_dirs = [ -+ "$vc_lib_um_path", -+ "$vc_lib_path", -+ ] -+ if (defined(vc_lib_atlmfc_path)) { -+ lib_dirs += [ "$vc_lib_atlmfc_path" ] -+ } - } - } - -@@ -324,19 +337,27 @@ config("sdk_link") { - # targets who want different library configurations can remove this and specify - # their own. - config("common_linker_setup") { -- ldflags = [ -- "/FIXED:NO", -- "/ignore:4199", -- "/ignore:4221", -- "/NXCOMPAT", -- "/DYNAMICBASE", -- ] -- -- if (win_linker_timing) { -- ldflags += [ -- "/time", -- "/verbose:incr", -+ if(is_mingw) { -+ # Enable DEP and ASLR -+ ldflags = [ -+ "-Wl,-dynamicbase", -+ "-Wl,-nxcompat", -+ ] -+ } else { -+ ldflags = [ -+ "/FIXED:NO", -+ "/ignore:4199", -+ "/ignore:4221", -+ "/NXCOMPAT", -+ "/DYNAMICBASE", - ] -+ -+ if (win_linker_timing) { -+ ldflags += [ -+ "/time", -+ "/verbose:incr", -+ ] -+ } - } - } - -@@ -373,7 +394,7 @@ config("cfi_linker") { - # ASan and CFG leads to slow process startup. Chromium's test runner uses - # lots of child processes, so this means things are really slow. Disable CFG - # for now. https://crbug.com/846966 -- if (!is_debug && !is_asan) { -+ if (!is_debug && !is_asan && !is_mingw) { - # Turn on CFG bitmap generation and CFG load config. - if (target_cpu == "arm64") { - # longjmp protection is temporarily disabled on Windows on Arm64 due to -@@ -470,20 +491,22 @@ config("delayloads_not_for_child_dll") { - # See https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx for a reference of - # what each value does. - config("default_crt") { -- if (is_component_build) { -- # Component mode: dynamic CRT. Since the library is shared, it requires -- # exceptions or will give errors about things not matching, so keep -- # exceptions on. -- configs = [ ":dynamic_crt" ] -- } else { -- if (current_os == "winuwp") { -- # https://blogs.msdn.microsoft.com/vcblog/2014/06/10/the-great-c-runtime-crt-refactoring/ -- # contains a details explanation of what is happening with the Windows -- # CRT in Visual Studio releases related to Windows store applications. -+ if(!is_mingw){ -+ if (is_component_build) { -+ # Component mode: dynamic CRT. Since the library is shared, it requires -+ # exceptions or will give errors about things not matching, so keep -+ # exceptions on. - configs = [ ":dynamic_crt" ] - } else { -- # Desktop Windows: static CRT. -- configs = [ ":static_crt" ] -+ if (current_os == "winuwp") { -+ # https://blogs.msdn.microsoft.com/vcblog/2014/06/10/the-great-c-runtime-crt-refactoring/ -+ # contains a details explanation of what is happening with the Windows -+ # CRT in Visual Studio releases related to Windows store applications. -+ configs = [ ":dynamic_crt" ] -+ } else { -+ # Desktop Windows: static CRT. -+ configs = [ ":static_crt" ] -+ } - } - } - } -@@ -524,42 +547,54 @@ config("static_crt") { - if (current_cpu == "x64") { - # The number after the comma is the minimum required OS version. - # 5.02 = Windows Server 2003. -- subsystem_version_suffix = ",5.02" -+ subsystem_version_suffix = "5.02" - } else if (current_cpu == "arm64") { - # Windows ARM64 requires Windows 10. -- subsystem_version_suffix = ",10.0" -+ subsystem_version_suffix = "10.0" - } else { - # 5.01 = Windows XP. -- subsystem_version_suffix = ",5.01" -+ subsystem_version_suffix = "5.01" - } - - config("console") { -- ldflags = [ "/SUBSYSTEM:CONSOLE$subsystem_version_suffix" ] -+ if(is_mingw){ -+ cflags = [ "-mconsole" ] -+ ldflags = [ "-Wl,--subsystem,console:$subsystem_version_suffix" ] -+ } else { -+ ldflags = [ "/SUBSYSTEM:CONSOLE,$subsystem_version_suffix" ] -+ } - } - config("windowed") { -- ldflags = [ "/SUBSYSTEM:WINDOWS$subsystem_version_suffix" ] -+ if(is_mingw){ -+ cflags = [ "-mwindows" ] -+ ldflags = [ "-Wl,--subsystem,windows:$subsystem_version_suffix" ] -+ } else { -+ ldflags = [ "/SUBSYSTEM:WINDOWS,$subsystem_version_suffix" ] -+ } - } - - # Incremental linking ---------------------------------------------------------- - - # Applies incremental linking or not depending on the current configuration. - config("default_incremental_linking") { -- # Enable incremental linking for debug builds and all component builds - any -- # builds where performance is not job one. -- # TODO(thakis): Always turn this on with lld, no reason not to. -- if (is_debug || is_component_build) { -- ldflags = [ "/INCREMENTAL" ] -- if (use_lld) { -- # lld doesn't use ilk files and doesn't really have an incremental link -- # mode; the only effect of the flag is that the .lib file timestamp isn't -- # updated if the .lib doesn't change. -- # TODO(thakis): Why pass /OPT:NOREF for lld, but not otherwise? -- # TODO(thakis): /INCREMENTAL is on by default in link.exe, but not in -- # lld. -- ldflags += [ "/OPT:NOREF" ] -+ if(!is_mingw){ -+ # Enable incremental linking for debug builds and all component builds - any -+ # builds where performance is not job one. -+ # TODO(thakis): Always turn this on with lld, no reason not to. -+ if (is_debug || is_component_build) { -+ ldflags = [ "/INCREMENTAL" ] -+ if (use_lld) { -+ # lld doesn't use ilk files and doesn't really have an incremental link -+ # mode; the only effect of the flag is that the .lib file timestamp isn't -+ # updated if the .lib doesn't change. -+ # TODO(thakis): Why pass /OPT:NOREF for lld, but not otherwise? -+ # TODO(thakis): /INCREMENTAL is on by default in link.exe, but not in -+ # lld. -+ ldflags += [ "/OPT:NOREF" ] -+ } -+ } else { -+ ldflags = [ "/INCREMENTAL:NO" ] - } -- } else { -- ldflags = [ "/INCREMENTAL:NO" ] - } - } - -@@ -571,6 +606,9 @@ config("unicode") { - "_UNICODE", - "UNICODE", - ] -+ if(is_mingw) { -+ cflags = [ "-municode" ] -+ } - } - - # Lean and mean ---------------------------------------------------------------- -@@ -591,3 +629,21 @@ config("lean_and_mean") { - config("nominmax") { - defines = [ "NOMINMAX" ] - } -+ -+# Let unit tests see all "for_testing" dll symbols. -+config("export_all_symbols") { -+ if(is_win && is_mingw){ -+ ldflags = [ "-Wl,--export-all-symbols" ] -+ } -+} -+ -+# Workaround a Mingw ld bug where large debug symbol data -+# causes the produced executable to be corrupted -+# https://stackoverflow.com/questions/22261539/ld-exe-crashing-in-mingw -+# this affects mksnapshot and v8 component. -+ -+config("strip_all_symbols_at_link_time") { -+ if(is_win && is_mingw){ -+ ldflags = [ "-Wl,--strip-all" ] -+ } -+} -diff --git a/config/win/manifest.gni b/config/win/manifest.gni -index e2115083f..c6bdef8fb 100644 ---- a/config/win/manifest.gni -+++ b/config/win/manifest.gni -@@ -85,12 +85,14 @@ if (is_win) { - foreach(i, rebase_path(invoker.sources, root_build_dir)) { - manifests += [ "/manifestinput:" + i ] - } -- ldflags = [ -- "/manifest:embed", -+ if(!is_mingw){ -+ ldflags = [ -+ "/manifest:embed", - -- # We handle UAC by adding explicit .manifest files instead. -- "/manifestuac:no", -- ] + manifests -+ # We handle UAC by adding explicit .manifest files instead. -+ "/manifestuac:no", -+ ] + manifests -+ } - } - - # This source set only exists to add a dep on the invoker's deps and to -diff --git a/config/x64.gni b/config/x64.gni -index 9e86979cb..ca8f47501 100644 ---- a/config/x64.gni -+++ b/config/x64.gni -@@ -16,7 +16,7 @@ if (current_cpu == "x64") { - x64_arch = "" - } - -- if ((is_posix && !is_apple) || is_fuchsia) { -+ if ((is_posix && !is_apple) || is_fuchsia || is_mingw) { - if (x64_arch == "") { - x64_arch = "x86-64" - } -diff --git a/toolchain/gcc_solink_wrapper.py b/toolchain/gcc_solink_wrapper.py -index 32f38670a..c4b11a9ae 100644 ---- a/toolchain/gcc_solink_wrapper.py -+++ b/toolchain/gcc_solink_wrapper.py -@@ -18,10 +18,11 @@ import sys - - import wrapper_utils - -- - def CollectSONAME(args): - """Replaces: readelf -d $sofile | grep SONAME""" - toc = '' -+ if ("GCC" in sys.version and sys.platform=='win32'): # Mingw's readelf doesn't work on PE files -+ return 0, toc - readelf = subprocess.Popen(wrapper_utils.CommandToRun( - [args.readelf, '-d', args.sofile]), - stdout=subprocess.PIPE, -@@ -36,6 +37,10 @@ def CollectSONAME(args): - def CollectDynSym(args): - """Replaces: nm --format=posix -g -D -p $sofile | cut -f1-2 -d' '""" - toc = '' -+ -+ if ("GCC" in sys.version and sys.platform=='win32'): # Mingw's nm doesn't work on PE/COFF files -+ return 0, toc -+ - nm = subprocess.Popen(wrapper_utils.CommandToRun( - [args.nm, '--format=posix', '-g', '-D', '-p', args.sofile]), - stdout=subprocess.PIPE, -@@ -94,6 +99,9 @@ def main(): - help='The strip binary to run', - metavar='PATH') - parser.add_argument('--dwp', help='The dwp binary to run', metavar='PATH') -+ parser.add_argument('--objcopy', -+ help='The objcopy binary to run', -+ metavar='PATH') - parser.add_argument('--sofile', - required=True, - help='Shared object file produced by linking command', -@@ -183,8 +191,18 @@ def main(): - - # Finally, strip the linked shared object file (if desired). - if args.strip: -+ if args.objcopy: -+ result = subprocess.call(wrapper_utils.CommandToRun( -+ [args.objcopy, '--only-keep-debug', args.sofile, args.output + '.debug'])) -+ if result != 0: -+ return result - result = subprocess.call(wrapper_utils.CommandToRun( - [args.strip, '-o', args.output, args.sofile])) -+ if result != 0: -+ return result -+ if args.objcopy: -+ result = subprocess.call(wrapper_utils.CommandToRun( -+ [args.objcopy, '--add-gnu-debuglink', args.output + '.debug',args.output])) - - if dwp_proc: - dwp_result = dwp_proc.wait() -@@ -193,6 +211,5 @@ def main(): - - return result - -- - if __name__ == "__main__": - sys.exit(main()) -diff --git a/toolchain/gcc_toolchain.gni b/toolchain/gcc_toolchain.gni -index 06d6a684f..24a6bcd4a 100644 ---- a/toolchain/gcc_toolchain.gni -+++ b/toolchain/gcc_toolchain.gni -@@ -59,6 +59,7 @@ if (enable_resource_allowlist_generation) { - # - cc - # - cxx - # - ld -+# - rc (mingw only) - # - # Optional parameters that control the tools: - # -@@ -111,7 +112,9 @@ template("gcc_toolchain") { - assert(defined(invoker.cc), "gcc_toolchain() must specify a \"cc\" value") - assert(defined(invoker.cxx), "gcc_toolchain() must specify a \"cxx\" value") - assert(defined(invoker.ld), "gcc_toolchain() must specify a \"ld\" value") -- -+ if(is_mingw){ -+ assert(defined(invoker.rc), "gcc_toolchain() must specify a \"rc\" value") -+ } - # This define changes when the toolchain changes, forcing a rebuild. - # Nothing should ever use this define. - if (defined(invoker.rebuild_define)) { -@@ -261,15 +264,19 @@ template("gcc_toolchain") { - asm = asm_prefix + invoker.cc - ar = invoker.ar - ld = "$goma_ld${invoker.ld}" -- if (defined(invoker.readelf)) { -- readelf = invoker.readelf -- } else { -- readelf = "readelf" -- } -- if (defined(invoker.nm)) { -- nm = invoker.nm -+ if(!is_mingw){ -+ if (defined(invoker.readelf)) { -+ readelf = invoker.readelf -+ } else { -+ readelf = "readelf" -+ } -+ if (defined(invoker.nm)) { -+ nm = invoker.nm -+ } else { -+ nm = "nm" -+ } - } else { -- nm = "nm" -+ rc = invoker.rc - } - if (defined(invoker.dwp)) { - dwp_switch = " --dwp=\"${invoker.dwp}\"" -@@ -277,6 +284,7 @@ template("gcc_toolchain") { - dwp_switch = "" - } - -+ - if (defined(invoker.shlib_extension)) { - default_shlib_extension = invoker.shlib_extension - } else { -@@ -354,6 +362,16 @@ template("gcc_toolchain") { - outputs = [ "$object_subdir/{{source_name_part}}.o" ] - } - -+ if(is_mingw){ -+ tool("rc") { -+ depfile = "{{output}}.d" -+ command = "$rc -i {{source}} -o {{output}}" -+ depsformat = "gcc" -+ description = "RC {{output}}" -+ outputs = [ "$object_subdir/{{source_name_part}}.o" ] -+ } -+ } -+ - tool("asm") { - # For GCC we can just use the C compiler to compile assembly. - depfile = "{{output}}.d" -@@ -414,8 +432,6 @@ template("gcc_toolchain") { - # .TOC file, overwrite it, otherwise, don't change it. - tocfile = sofile + ".TOC" - -- link_command = "$ld -shared -Wl,-soname=\"$soname\" {{ldflags}}${extra_ldflags} -o \"$unstripped_sofile\" @\"$rspfile\"" -- - # Generate a map file to be used for binary size analysis. - # Map file adds ~10% to the link time on a z620. - # With target_os="android", libchrome.so.map.gz is ~20MB. -@@ -425,13 +441,30 @@ template("gcc_toolchain") { - map_switch = " --map-file \"$map_file\"" - } - -- assert(defined(readelf), "to solink you must have a readelf") -- assert(defined(nm), "to solink you must have an nm") - strip_switch = "" - if (defined(invoker.strip)) { - strip_switch = "--strip=${invoker.strip} " - } - -+ mingw_flags = "" -+ if(is_mingw){ -+ # Have MinGW linker generate a .def file and a .a import library -+ mingw_flags = " -Wl,--dll -Wl,--output-def=\"$sofile\".def -Wl,--out-implib=\"$sofile\".a " -+ readelf = "" -+ if (defined(invoker.readelf)) { -+ readelf = "${invoker.readelf} " -+ } -+ nm = "" -+ if (defined(invoker.nm)) { -+ readelf = "${invoker.nm} " -+ } -+ } else { -+ assert(defined(readelf), "to solink you must have a readelf") -+ assert(defined(nm), "to solink you must have an nm") -+ } -+ -+ link_command = "$ld -shared -Wl,-soname=\"$soname\" ${mingw_flags} {{ldflags}}${extra_ldflags} -o \"$unstripped_sofile\" @\"$rspfile\"" -+ - # This needs a Python script to avoid using a complex shell command - # requiring sh control structures, pipelines, and POSIX utilities. - # The host might not have a POSIX shell and utilities (e.g. Windows). -diff --git a/toolchain/win/BUILD.gn b/toolchain/win/BUILD.gn -index eff2a14c9..79f1bb786 100644 ---- a/toolchain/win/BUILD.gn -+++ b/toolchain/win/BUILD.gn -@@ -9,6 +9,7 @@ import("//build/config/win/visual_studio_version.gni") - import("//build/toolchain/cc_wrapper.gni") - import("//build/toolchain/goma.gni") - import("//build/toolchain/toolchain.gni") -+import("//build/toolchain/gcc_toolchain.gni") - - # Should only be running on Windows. - assert(is_win) -@@ -46,13 +47,15 @@ if (current_toolchain == default_toolchain) { - } else { - configuration_name = "Release" - } -- exec_script("../../vs_toolchain.py", -- [ -- "copy_dlls", -- rebase_path(root_build_dir), -- configuration_name, -- target_cpu, -- ]) -+ if(!is_mingw){ -+ exec_script("../../vs_toolchain.py", -+ [ -+ "copy_dlls", -+ rebase_path(root_build_dir), -+ configuration_name, -+ target_cpu, -+ ]) -+ } - } - - if (host_os == "win") { -@@ -528,3 +531,29 @@ if (target_os == "winuwp") { - } - } - } -+ -+template("mingw_toolchain") { -+ gcc_toolchain("mingw_" + target_name) { -+ forward_variables_from(invoker, "*") -+ cc = "gcc" -+ cxx = "g++" -+ ar = "ar" -+ ld = cxx -+ if(is_mingw){ -+ rc = "windres" -+ } -+ strip = "strip" -+ executable_extension = ".exe" -+ toolchain_args = { -+ current_cpu = target_name -+ current_os = "win" -+ is_clang = false -+ } -+ } -+} -+ -+mingw_toolchain("x64") { -+} -+ -+mingw_toolchain("x86") { -+} -diff --git a/util/lastchange.py b/util/lastchange.py -index 874870ad5..a4fc0be8d 100644 ---- a/util/lastchange.py -+++ b/util/lastchange.py -@@ -191,7 +191,10 @@ def GetGitTopDirectory(source_dir): - Returns: - The output of "git rev-parse --show-toplevel" as a string - """ -- return _RunGitCommand(source_dir, ['rev-parse', '--show-toplevel']) -+ directory = _RunGitCommand(source_dir, ['rev-parse', '--show-toplevel']) -+ if "GCC" in sys.version and sys.platform=='win32': -+ return subprocess.check_output(["cygpath", "-w", directory]).strip(b"\n").decode() -+ return directory - - - def WriteIfChanged(file_name, contents): -diff --git a/win/BUILD.gn b/win/BUILD.gn -index d449f5925..558e04229 100644 ---- a/win/BUILD.gn -+++ b/win/BUILD.gn -@@ -16,7 +16,7 @@ windows_manifest("default_exe_manifest") { - ] - } - --if (is_win) { -+if (is_win && !is_mingw) { - assert(host_os != "mac" || target_cpu != "x86", - "Windows cross-builds from Mac must be 64-bit.") - -@@ -92,7 +92,7 @@ if (is_win) { - - group("runtime_libs") { - data = [] -- if (is_component_build) { -+ if (is_component_build && !is_mingw) { - # Copy the VS runtime DLLs into the isolate so that they don't have to be - # preinstalled on the target machine. The debug runtimes have a "d" at - # the end. diff --git a/deps/windows_x86_64/README.md b/deps/windows_x86_64/README.md deleted file mode 100644 index d3087621b..000000000 --- a/deps/windows_x86_64/README.md +++ /dev/null @@ -1,39 +0,0 @@ - -The MINGW patches (`0000`, `0001`, `zlib.gn`) are originally from the [MSYS2 V8 package](https://packages.msys2.org/package/mingw-w64-x86_64-v8?repo=mingw64) -([sources](https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-v8), [LICENSE](https://github.com/msys2/MINGW-packages/blob/master/LICENSE)). - -As v8go was already using V8 9.0.257.18 while the MSYS2 package was still at -8.8.278.14-1, they have been slightly updated to work with the newer version. - -To create a new version, apply the existing patches as far as possible: - - cd ${v8go_project}/deps/v8 - git apply --reject --whitespace=fix 0000-add-mingw-main-code-changes.patch - cd build - git apply --reject --whitespace=fix 0001-add-mingw-toolchain.patch - -Check the git output for files that could not be patched cleanly: - - Applying patch config/win/BUILD.gn with 1 reject... - -There will be a corresponding .rej file (`config/win/BUILD.gn.rej`) that -contains the rejected parts of the patch. Apply the necessary changes -manually and delete the .rej file afterwards. - -Once all changes are complete, create the new patches from the modified working -tree: - - cd ${v8go_project}/deps/v8 - git diff --relative >../windows_x86_64/0000-add-mingw-main-code-changes.patch - cd build - git diff --relative >../../windows_x86_64/0001-add-mingw-toolchain.patch - -Optional: To minimize whitespace/filemode diffs to the original MINGW patches, -run: - - sed -i 's/[ \t]*$//' - sed -i 's/100755/100644/' - -Note: `git reset --hard` the `v8` and `v8/build` submodules if you want to run -`build.py` after this. Otherwise the build will complain about the unstaged -changes. diff --git a/deps/windows_x86_64/libv8.a b/deps/windows_x86_64/libv8.a deleted file mode 100644 index 45d71a793..000000000 Binary files a/deps/windows_x86_64/libv8.a and /dev/null differ diff --git a/deps/windows_x86_64/vendor.go b/deps/windows_x86_64/vendor.go deleted file mode 100644 index 38e7bfca3..000000000 --- a/deps/windows_x86_64/vendor.go +++ /dev/null @@ -1,3 +0,0 @@ -// Package windows_x86_64 is required to provide support for vendoring modules -// DO NOT REMOVE -package windows_x86_64 diff --git a/deps/windows_x86_64/zlib.gn b/deps/windows_x86_64/zlib.gn deleted file mode 100644 index c6b57050e..000000000 --- a/deps/windows_x86_64/zlib.gn +++ /dev/null @@ -1,21 +0,0 @@ -import("//build/config/linux/pkg_config.gni") - -pkg_config("system_zlib") { - packages = [ "zlib" ] - defines = [ "USE_SYSTEM_ZLIB=1" ] -} - -config("zlib_config") { - if(is_win && !is_mingw && !is_component_build) { - ldflags = ["/ignore:4099"] # needed on VCPKG CI builds - } - configs = [ - ":system_zlib", - ] -} - -source_set("zlib") { - public_configs = [ - ":system_zlib", - ] -} diff --git a/v8go.h b/v8go.h index 591b54729..051dc5582 100644 --- a/v8go.h +++ b/v8go.h @@ -6,11 +6,6 @@ #define V8GO_H #ifdef __cplusplus -#if defined(__MINGW32__) || defined(__MINGW64__) -// MinGW header files do not implicitly include windows.h -struct _EXCEPTION_POINTERS; -#endif - #include "libplatform/libplatform.h" #include "v8-profiler.h" #include "v8.h"