Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions mingw-w64-ghc/0001-use-system-gmp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- ghc-8.6.5/libraries/integer-gmp/gmp/ghc.mk.orig 2019-04-08 03:39:58.000000000 +0800
+++ ghc-8.6.5/libraries/integer-gmp/gmp/ghc.mk 2026-06-29 20:27:55.692507600 +0800
@@ -42,7 +42,6 @@
ifeq "$(Windows_Host)" "YES"
# Apparently building on Windows fails when there is a system gmp
# available, so we never try to use the system gmp on Windows
-libraries/integer-gmp_CONFIGURE_OPTS += --configure-option=--with-intree-gmp
endif

ifeq "$(GMP_PREFER_FRAMEWORK)" "YES"
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ index 664deb4..f4b839e 100644
# versions of LLVM simultaneously, but that stopped working around
# 3.5/3.6 release of LLVM.
-LlvmVersion=6.0
+LlvmVersion=7.0
+LlvmVersion=22.1
AC_SUBST([LlvmVersion])
sUPPORTED_LLVM_VERSION=$(echo \($LlvmVersion\) | sed 's/\./,/')
AC_DEFINE_UNQUOTED([sUPPORTED_LLVM_VERSION], ${sUPPORTED_LLVM_VERSION}, [The supported LLVM version number])
Expand Down
188 changes: 188 additions & 0 deletions mingw-w64-ghc/0003-fix-build-with-ucrt.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
--- ghc-8.6.5/libraries/base/base.cabal.orig
+++ ghc-8.6.5/libraries/base/base.cabal
@@ -366,7 +366,7 @@
-- mingw32: Unfortunately required because of a resource leak between
-- mingwex and mingw32. the __math_err symbol is defined in
-- mingw32 which is required by mingwex.
- extra-libraries: wsock32, user32, shell32, msvcrt, mingw32, mingwex
+ extra-libraries: wsock32, user32, shell32, shlwapi, msvcrt, mingw32, mingwex
exposed-modules:
GHC.IO.Encoding.CodePage.API
GHC.IO.Encoding.CodePage.Table
--- ghc-8.6.5/rts/RtsSymbols.c.orig 2026-06-29 22:22:19.848368500 +0800
+++ ghc-8.6.5/rts/RtsSymbols.c 2026-06-29 22:59:30.712087400 +0800
@@ -38,12 +38,12 @@
SymI_HasProto(stg_finalizzeWeakzh)

#define RTS_LIBDW_SYMBOLS \
- SymE_HasProto(backtraceFree) \
- SymE_HasProto(libdwGetBacktrace) \
- SymE_HasProto(libdwLookupLocation) \
- SymE_HasProto(libdwPoolTake) \
- SymE_HasProto(libdwPoolRelease) \
- SymE_HasProto(libdwPoolClear)
+ SymI_HasProto(backtraceFree) \
+ SymI_HasProto(libdwGetBacktrace) \
+ SymI_HasProto(libdwLookupLocation) \
+ SymI_HasProto(libdwPoolTake) \
+ SymI_HasProto(libdwPoolRelease) \
+ SymI_HasProto(libdwPoolClear)

#if !defined (mingw32_HOST_OS)
#define RTS_POSIX_ONLY_SYMBOLS \
@@ -102,14 +102,12 @@
SymI_HasProto(atexit) \
RTS_WIN32_ONLY(SymI_NeedsProto(__chkstk_ms)) \
RTS_WIN64_ONLY(SymI_NeedsProto(___chkstk_ms)) \
- RTS_WIN32_ONLY(SymI_HasProto(_imp___environ)) \
- RTS_WIN64_ONLY(SymI_HasProto(__imp__environ)) \
- RTS_WIN32_ONLY(SymI_HasProto(_imp___iob)) \
- RTS_WIN64_ONLY(SymI_HasProto(__iob_func)) \
RTS_WIN64_ONLY(SymI_HasProto(__mingw_vsnwprintf)) \
/* see Note [Symbols for MinGW's printf] */ \
SymI_HasProto(_lock_file) \
- SymI_HasProto(_unlock_file)
+ SymI_HasProto(_unlock_file) \
+ SymI_HasProto(__acrt_iob_func) \
+ SymI_NeedsDataProto(__imp___acrt_iob_func)

#define RTS_MINGW_COMPAT_SYMBOLS \
SymI_HasProto_deprecated(access) \
@@ -966,7 +964,7 @@
#define SymI_NeedsProto(vvv) extern void vvv(void);
#define SymI_NeedsDataProto(vvv) extern StgWord vvv[];
#if defined(COMPILING_WINDOWS_DLL)
-#define SymE_HasProto(vvv) SymE_HasProto(vvv);
+#define SymE_HasProto(vvv) SymE_NeedsProto(vvv);
# if defined(x86_64_HOST_ARCH)
# define SymE_NeedsProto(vvv) extern void __imp_ ## vvv (void);
# define SymE_NeedsDataProto(vvv) SymE_NeedsProto(vvv)
--- ghc-8.6.5/rts/RtsAPI.c.orig 2019-04-08 03:39:58.000000000 +0800
+++ ghc-8.6.5/rts/RtsAPI.c 2026-06-30 15:14:13.097572400 +0800
@@ -475,7 +475,7 @@
SchedulerStatus stat;

p = (StgClosure *)deRefStablePtr(s);
- w = rts_apply(*cap, &base_GHCziTopHandler_runMainIO_closure, p);
+ w = rts_apply(*cap, runMainIO_closure, p);
tso = createStrictIOThread(*cap, RtsFlags.GcFlags.initialStkSize, w);
// async exceptions are always blocked by default in the created
// thread. See #1048.
--- ghc-8.6.5/rts/ghc.mk.orig 2019-04-08 03:39:58.000000000 +0800
+++ ghc-8.6.5/rts/ghc.mk 2026-06-30 17:00:00.000000000 +0800
@@ -203,14 +203,18 @@

ifneq "$$(UseSystemLibFFI)" "YES"
rts_dist_FFI_SO = rts/dist/build/lib$$(LIBFFI_NAME)$$(soext)
+rts_dist_FFI_DLL = rts/dist/build/$$(LIBFFI_DLL)
+rts_dist_FFI_LIBS = -Lrts/dist/build -l$$(LIBFFI_NAME)
else
rts_dist_FFI_SO =
+rts_dist_FFI_DLL =
+rts_dist_FFI_LIBS =
endif

# Making a shared library for the RTS.
ifneq "$$(findstring dyn, $1)" ""
ifeq "$$(TargetOS_CPP)" "mingw32"
-$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/dist/libs.depend rts/dist/build/$$(LIBFFI_DLL)
+$$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(ALL_RTS_DEF_LIBS) rts/dist/libs.depend $$(rts_dist_FFI_DLL)
"$$(RM)" $$(RM_OPTS) $$@
# Call out to the shell script to decide how to build the dll.
# Making a shared library for the RTS.
@@ -226,7 +230,7 @@
# $$10 = SxS Name
# $$11 = SxS Version
$$(gen-dll_INPLACE) link "rts/dist/build" "rts/dist/build" "" "" "$$(ALL_RTS_DEF_LIBS)" "$$(rts_$1_OBJS)" "$$@" "$$(rts_dist_HC) -this-unit-id rts -no-hs-main -shared -dynamic -dynload deploy \
- -no-auto-link-packages -Lrts/dist/build -l$$(LIBFFI_NAME) \
+ -no-auto-link-packages $$(rts_dist_FFI_LIBS) \
`cat rts/dist/libs.depend | tr '\n' ' '` \
$$(rts_dist_$1_GHC_LD_OPTS)" "NO" \
"$(rts_INSTALL_INFO)-$(subst dyn,,$(subst _dyn,,$(subst v,,$1)))" "$(ProjectVersion)"
--- ghc-8.6.5/rts/rts.cabal.in.orig 2019-04-08 03:39:58.000000000 +0800
+++ ghc-8.6.5/rts/rts.cabal.in 2026-06-30 16:20:00.000000000 +0800
@@ -36,9 +36,7 @@
-- expects the unit-id to be
-- set without version
ghc-options: -this-unit-id rts
- if os(windows)
- extra-bundled-libraries: Cffi-6
- else
+ if !os(windows)
extra-bundled-libraries: Cffi
-- the rts comes in a variety of flavours that ar built outside
-- of cabal. The combination of extra-bundled-libraries and
--- ghc-8.6.5/rts/rts.cabal.orig 2019-04-08 03:39:58.000000000 +0800
+++ ghc-8.6.5/rts/rts.cabal 2026-06-30 16:20:00.000000000 +0800
@@ -36,9 +36,7 @@
-- expects the unit-id to be
-- set without version
ghc-options: -this-unit-id rts
- if os(windows)
- extra-bundled-libraries: Cffi-6
- else
+ if !os(windows)
extra-bundled-libraries: Cffi
-- the rts comes in a variety of flavours that ar built outside
-- of cabal. The combination of extra-bundled-libraries and
--- ghc-8.6.5/rts/win32/libHSbase.def.orig
+++ ghc-8.6.5/rts/win32/libHSbase.def
@@ -18,6 +18,7 @@
base_GHCziPack_unpackCString_closure

base_GHCziTopHandler_runIO_closure
+ base_GHCziTopHandler_runMainIO_closure
base_GHCziTopHandler_runNonIO_closure

base_GHCziIOziException_stackOverflow_closure
--- ghc-8.6.5/rts/win32/libHSghc-prim.def.orig
+++ ghc-8.6.5/rts/win32/libHSghc-prim.def
@@ -3,6 +3,7 @@

EXPORTS

+ ghczmprim_GHCziTuple_Z0T_closure
ghczmprim_GHCziTypes_True_closure
ghczmprim_GHCziTypes_False_closure
ghczmprim_GHCziTypes_Czh_con_info
--- ghc-8.6.5/rts/win32/ConsoleHandler.c.orig 2026-06-29 22:22:19.928336300 +0800
+++ ghc-8.6.5/rts/win32/ConsoleHandler.c 2026-06-30 00:01:15.856326200 +0800
@@ -9,6 +9,7 @@
#include "RtsUtils.h"
#include "AsyncIO.h"
#include "RtsSignals.h"
+#include "ThreadLabels.h"

extern int stg_InstallConsoleEvent(int action, StgStablePtr *handler);

--- ghc-8.6.5/rts/win32/OSMem.c.orig 2026-06-29 22:22:19.923546300 +0800
+++ ghc-8.6.5/rts/win32/OSMem.c 2026-06-30 00:00:37.631885300 +0800
@@ -37,28 +37,11 @@
/* free_blocks are kept in ascending order, and adjacent blocks are merged */
static block_rec* free_blocks = NULL;

-/* Mingw-w64 does not currently have this in their header. So we have to import it.*/
-typedef LPVOID(WINAPI *VirtualAllocExNumaProc)(HANDLE, LPVOID, SIZE_T, DWORD, DWORD, DWORD);
-
-/* Cache NUMA API call. */
-VirtualAllocExNumaProc VirtualAllocExNuma;
-
void
osMemInit(void)
{
allocs = NULL;
free_blocks = NULL;
-
- /* Resolve and cache VirtualAllocExNuma. */
- if (osNumaAvailable() && RtsFlags.GcFlags.numa)
- {
- VirtualAllocExNuma = (VirtualAllocExNumaProc)GetProcAddress(GetModuleHandleW(L"kernel32"), "VirtualAllocExNuma");
- if (!VirtualAllocExNuma)
- {
- sysErrorBelch(
- "osBindMBlocksToNode: VirtualAllocExNuma does not exist. How did you get this far?");
- }
- }
}

static
26 changes: 26 additions & 0 deletions mingw-w64-ghc/0004-fix-windres.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Port from https://github.com/ghc/ghc/commit/3302f42a57a9e26423e30221e455de5a173cd6c5
--- ghc-8.6.5/compiler/main/SysTools/Tasks.hs.orig 2026-06-29 23:10:09.998057500 +0800
+++ ghc-8.6.5/compiler/main/SysTools/Tasks.hs 2026-06-29 23:11:02.861676300 +0800
@@ -326,17 +326,15 @@
args' = -- If windres.exe and gcc.exe are in a directory containing
-- spaces then windres fails to run gcc. We therefore need
-- to tell it what command to use...
- Option ("--preprocessor=" ++
- unwords (map quote (gcc :
- map showOpt gcc_args ++
- map showOpt opts ++
- ["-E", "-xc", "-DRC_INVOKED"])))
+ [ Option ("--preprocessor=" ++ quote gcc) ]
+ ++ map (Option . ("--preprocessor-arg=" ++) . quote)
+ (map showOpt gcc_args ++ map showOpt opts ++ ["-E", "-xc", "-DRC_INVOKED"])
-- ...but if we do that then if windres calls popen then
-- it can't understand the quoting, so we have to use
-- --use-temp-file so that it interprets it correctly.
-- See #1828.
- : Option "--use-temp-file"
- : args
+ ++ [ Option "--use-temp-file" ]
+ ++ args
mb_env <- getGccEnv gcc_args
runSomethingFiltered dflags id "Windres" windres args' Nothing mb_env

77 changes: 77 additions & 0 deletions mingw-w64-ghc/0005-fix-hardcoded-mingw.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
--- ghc-8.6.5/ghc.mk.orig 2019-04-08 03:39:58.000000000 +0800
+++ ghc-8.6.5/ghc.mk 2026-06-30 02:55:18.543108600 +0800
@@ -819,20 +819,6 @@
# -----------------------------------------------------------------------------
# Creating a local mingw copy on Windows

-ifeq "$(Windows_Host)" "YES"
-
-install : install_mingw
-.PHONY: install_mingw
-install_mingw : $(INPLACE_MINGW)
- "$(CP)" -Rp $(INPLACE_MINGW) $(prefix)
-
-install : install_perl
-.PHONY: install_perl
-install_perl : $(INPLACE_PERL)
- "$(CP)" -Rp $(INPLACE_PERL) $(prefix)
-
-endif # Windows_Host
-
ifneq "$(BINDIST)" "YES"
$(ghc-prim-$(libraries/ghc-prim_dist-install_VERSION)_HADDOCK_FILE): \
libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs
--- ghc-8.6.5/compiler/main/SysTools/BaseDir.hs.orig 2019-04-08 03:39:58.000000000 +0800
+++ ghc-8.6.5/compiler/main/SysTools/BaseDir.hs 2026-06-30 03:03:20.276421800 +0800
@@ -92,12 +92,7 @@
-- | Expand occurrences of the @$tooldir@ interpolation in a string
-- on Windows, leave the string untouched otherwise.
expandToolDir :: Maybe FilePath -> String -> String
-#if defined(mingw32_HOST_OS)
-expandToolDir (Just tool_dir) s = expandPathVar "tooldir" tool_dir s
-expandToolDir Nothing _ = panic "Could not determine $tooldir"
-#else
expandToolDir _ s = s
-#endif

-- | @expandPathVar var value str@
--
@@ -230,18 +230,4 @@
findToolDir
:: FilePath -- ^ topdir
-> IO (Maybe FilePath)
-#if defined(mingw32_HOST_OS)
-findToolDir top_dir = go 0 (top_dir </> "..")
- where maxDepth = 2
- go :: Int -> FilePath -> IO (Maybe FilePath)
- go k path
- | k == maxDepth = throwGhcExceptionIO $
- InstallationError "could not detect mingw toolchain"
- | otherwise = do
- oneLevel <- doesDirectoryExist (path </> "mingw")
- if oneLevel
- then return (Just path)
- else go (k+1) (path </> "..")
-#else
findToolDir _ = return Nothing
-#endif
--- ghc-8.6.5/mk/config.mk.in.orig
+++ ghc-8.6.5/mk/config.mk.in
@@ -670,7 +670,7 @@
ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
WINDRES = $(INPLACE_MINGW)/bin/windres
else ifeq "$(TARGETPLATFORM)" "x86_64-unknown-mingw32"
-WINDRES = $(INPLACE_MINGW)/bin/windres
+WINDRES = windres
endif

#-----------------------------------------------------------------------------
@@ -680,7 +680,7 @@
ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
DLLTOOL = inplace/mingw/bin/dlltool.exe
else ifeq "$(TARGETPLATFORM)" "x86_64-unknown-mingw32"
-DLLTOOL = inplace/mingw/bin/dlltool.exe
+DLLTOOL = dlltool.exe
endif

#-----------------------------------------------------------------------------
Loading
Loading