diff options
| author | Sylvain Henry <sylvain@haskus.fr> | 2021-11-10 14:52:24 +0100 |
|---|---|---|
| committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-11-15 13:19:42 -0500 |
| commit | d9f5490591c290295e161431008d60a4495c2390 (patch) | |
| tree | 27e517234d40307e0ebe4e434ce9e249a6e5f90f /libraries | |
| parent | 3302f42a57a9e26423e30221e455de5a173cd6c5 (diff) | |
| download | haskell-d9f5490591c290295e161431008d60a4495c2390.tar.gz | |
Hadrian: fix windows cross-build (#20657)
Many small things to fix:
* Hadrian: platform triple is "x86_64-w64-mingw32" and this wasn't recognized by
Hadrian (note "w64" instead of "unknown")
* Hadrian was using the build platform ("isWindowsHost") to detect
the use of the Windows toolchain, which was wrong. We now use the
"targetOs" setting.
* Hadrian was doing the same thing for Darwin so we fixed both at once,
even if cross-compilation to Darwin is unlikely to happen afaik (cf
"osxHost" vs "osxTarget" changes)
* Hadrian: libffi name was computed in two different places and one of
them wasn't taking the different naming on Windows into account.
* Hadrian was passing "-Irts/include" when building the stage1 compiler
leading to the same error as in #18143 (which is using make).
stage1's RTS is stage0's one so mustn't do this.
* Hadrian: Windows linker doesn't seem to support "-zorigin" so we
don't pass it (similarly to Darwin)
* Hadrian: hsc2hs in cross-compilation mode uses a trick (taken from
autoconf): it defines "static int test_array[SOME_EXPR]" where
SOME_EXPR is a constant expression. However GCC reports an error
because SOME_EXPR is supposedly not constant. This is fixed by using
another method enabled with the `--via-asm` flag of hsc2hs. It has been
fixed in `make` build system (5f6fcf7808b16d066ad0fb2068225b3f2e8363f7)
but not in Hadrian.
* Hadrian: some packages are specifically built only on Windows but they
shouldn't be when building a cross-compiler (`touchy` and
`ghci-wrapper`). We now correctly detect this case and disable these
packages.
* Base: we use `iNVALID_HANDLE_VALUE` in a few places. It fixed some
hsc2hs issues before we switched to `--via-asm` (see above). I've kept
these changes are they make the code nicer.
* Base: `base`'s configure tries to detect if it is building for Windows
but for some reason the `$host_alias` value is `x86_64-windows` in my
case and it wasn't properly detected.
* Base: libraries/base/include/winio_structs.h imported "Windows.h" with
a leading uppercase. It doesn't work on case-sensitive systems when
cross-compiling so we have to use "windows.h".
* RTS: rts/win32/ThrIOManager.c was importin "rts\OSThreads.h" but this
path isn't valid when cross-compiling. We replaced "\" with "/".
* DeriveConstants: this tool derives the constants from the target
RTS header files. However these header files define `StgAsyncIOResult`
only when `mingw32_HOST_OS` is set hence it seems we have to set it
explicitly.
Note that deriveConstants is called more than once (why? there is
only one target for now so it shouldn't) and in the second case this
value is correctly defined (probably coming indirectly from the import
of "rts/PosixSource.h"). A better fix would probably be to disable the
unneeded first run of deriveconstants.
Diffstat (limited to 'libraries')
| -rw-r--r-- | libraries/base/GHC/Event/Windows.hsc | 2 | ||||
| -rw-r--r-- | libraries/base/System/Environment/ExecutablePath.hsc | 3 | ||||
| -rw-r--r-- | libraries/base/configure.ac | 2 | ||||
| -rw-r--r-- | libraries/base/include/winio_structs.h | 2 |
4 files changed, 5 insertions, 4 deletions
diff --git a/libraries/base/GHC/Event/Windows.hsc b/libraries/base/GHC/Event/Windows.hsc index a695df71d2..dd0b2d9db9 100644 --- a/libraries/base/GHC/Event/Windows.hsc +++ b/libraries/base/GHC/Event/Windows.hsc @@ -481,7 +481,7 @@ associateHandle' hwnd -- | A handle value representing an invalid handle. invalidHandle :: HANDLE -invalidHandle = intPtrToPtr (#{const INVALID_HANDLE_VALUE}) +invalidHandle = iNVALID_HANDLE_VALUE -- | Associate a 'HANDLE' with the I/O manager's completion port. This must be -- done before using the handle with 'withOverlapped'. diff --git a/libraries/base/System/Environment/ExecutablePath.hsc b/libraries/base/System/Environment/ExecutablePath.hsc index 6d8eac9b83..5cb49489c5 100644 --- a/libraries/base/System/Environment/ExecutablePath.hsc +++ b/libraries/base/System/Environment/ExecutablePath.hsc @@ -56,6 +56,7 @@ import Data.Word import Foreign.C import Foreign.Marshal.Array import Foreign.Ptr +import GHC.Windows #include <windows.h> #include <stdint.h> #else @@ -278,7 +279,7 @@ executablePath = Just (Just <$> getExecutablePath) getFinalPath :: FilePath -> IO FilePath getFinalPath path = withCWString path $ \s -> bracket (createFile s) c_closeHandle $ \h -> do - let invalid = h == wordPtrToPtr (#const (intptr_t)INVALID_HANDLE_VALUE) + let invalid = h == iNVALID_HANDLE_VALUE if invalid then pure path else go h bufSize where go h sz = allocaArray (fromIntegral sz) $ \outPath -> do diff --git a/libraries/base/configure.ac b/libraries/base/configure.ac index 68295563af..e034549476 100644 --- a/libraries/base/configure.ac +++ b/libraries/base/configure.ac @@ -12,7 +12,7 @@ AC_USE_SYSTEM_EXTENSIONS AC_MSG_CHECKING(for WINDOWS platform) case $host_alias in - *mingw32*|*mingw64*|*cygwin*|*msys*) + *mingw32*|*mingw64*|*cygwin*|*msys*|*windows*) WINDOWS=YES;; *) WINDOWS=NO;; diff --git a/libraries/base/include/winio_structs.h b/libraries/base/include/winio_structs.h index da9dab05b7..a4c7604fd0 100644 --- a/libraries/base/include/winio_structs.h +++ b/libraries/base/include/winio_structs.h @@ -4,7 +4,7 @@ * Structures supporting the IOCP based I/O Manager or Windows. */ -#include <Windows.h> +#include <windows.h> #include <stdint.h> #if defined(_WIN64) |
