on master help sign in
Allow to build katip under windows.

Introduce compatibility module that provide functions for working with ProcessID that is used in logs. This change allow to build katip on windows.

commit9cf7991cebbc6c76e1b8d0d25291218d98f317c0 authorAlexander Vershilov <alexander.vershilov@tweag.io> dateWed 14 Dec 2016, 22:25 (10 years ago) parent63abb86
3 files changed+41−1
katip/katip.cabal+6−1 katip/src/Katip/Compat.hs+30 katip/src/Katip/Core.hs+5
katip/katip.cabal+6−1
@@ -68,7 +68,6 @@ library
6868 , time >= 1 && < 1.7
6969 , transformers >= 0.3 && < 0.6
7070 , transformers-compat
71− , unix >= 2.5 && < 2.8
7271 , unordered-containers >= 0.2 && < 0.3
7372 , monad-control >= 1.0 && < 1.1
7473 , mtl >= 2.0 && < 2.3
@@ -83,6 +82,12 @@ library
8382 ghc-options: -Wall
8483 if flag(lib-Werror)
8584 ghc-options: -Werror
85+ if os(windows)
86+ build-depends: Win32 >=2.3 && <2.5
87+ other-modules: Katip.Compat
88+ else
89+ build-depends: unix >= 2.5 && <2.8
90+
8691
8792test-suite test
8893 type: exitcode-stdio-1.0
katip/src/Katip/Compat.hsnew file+30
@@ -0,0 +1,30 @@
1+{-# LANGUAGE ForeignFunctionInterface #-}
2+{-# LANGUAGE CPP #-}
3+module Katip.Compat
4+ ( ProcessID
5+ , getProcessID
6+ ) where
7+
8+import System.Win32.Process
9+
10+type ProcessID = ProcessId
11+
12+#if !MIN_VERSION_Win32(2,4,0)
13+
14+#if defined(i386_HOST_ARCH)
15+# define WINDOWS_CCONV stdcall
16+#elif defined(x86_64_HOST_ARCH)
17+# define WINDOWS_CCONV ccall
18+#else
19+# error Unknown mingw32 arch
20+#endif
21+
22+foreign import WINDOWS_CCONV unsafe "windows.h GetCurrentProcessId"
23+ c_GetCurrentProcessId :: IO ProcessId
24+
25+getProcessID :: IO ProcessID
26+getProcessID = c_GetCurrentProcessId
27+#else
28+getProcessID :: IO ProcessID
29+getProcessID = getCurrentProcessId
30+#endif
katip/src/Katip/Core.hs+5
@@ -63,7 +63,12 @@ import qualified Language.Haskell.TH.Syntax as TH
6363import Lens.Micro
6464import Lens.Micro.TH
6565import Network.HostName
66+#if mingw32_HOST_OS
67+import Katip.Compat
68+#else
6669import System.Posix
70+#endif
71+
6772-------------------------------------------------------------------------------
6873
6974