Skip to content

Commit 0c2a4f3

Browse files
NicolasTBodigrim
authored andcommitted
Fix WASI build
The `System.Posix.Files.PosixString` and `System.Posix.Temp.PosixString` modules failed to build on the WASI/WASM platform because foreign imports of `mkstemp` and `mknod` was not conditional on `configure` findings. This patch aligns these modules with their non-`PosixString` counterparts. See: #245 See: https://github.com/haskell/unix/runs/8284652815?check_suite_focus=true
1 parent c631dd7 commit 0c2a4f3

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

System/Posix/Files/PosixString.hsc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ import System.Posix.PosixPath.FilePath
107107

108108
import Data.Time.Clock.POSIX (POSIXTime)
109109

110+
#if !defined(HAVE_MKNOD)
111+
import System.IO.Error ( ioeSetLocation )
112+
import GHC.IO.Exception ( unsupportedOperation )
113+
#endif
114+
110115
-- -----------------------------------------------------------------------------
111116
-- chmod()
112117

@@ -205,6 +210,13 @@ createNamedPipe name mode = do
205210
withFilePath name $ \s ->
206211
throwErrnoPathIfMinus1_ "createNamedPipe" name (c_mkfifo s mode)
207212

213+
#if !defined(HAVE_MKNOD)
214+
215+
{-# WARNING createDevice "operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_MKNOD@)" #-}
216+
createDevice :: PosixPath -> FileMode -> DeviceID -> IO ()
217+
createDevice _ _ _ = ioError (ioeSetLocation unsupportedOperation "createDevice")
218+
219+
#else
208220
-- | @createDevice path mode dev@ creates either a regular or a special file
209221
-- depending on the value of @mode@ (and @dev@). @mode@ will normally be either
210222
-- 'blockSpecialMode' or 'characterSpecialMode'. May fail with
@@ -221,6 +233,8 @@ createDevice path mode dev =
221233
foreign import capi unsafe "HsUnix.h mknod"
222234
c_mknod :: CString -> CMode -> CDev -> IO CInt
223235

236+
#endif // HAVE_MKNOD
237+
224238
-- -----------------------------------------------------------------------------
225239
-- Hard links
226240

System/Posix/Temp/PosixString.hsc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ import System.Posix.Directory.PosixPath (createDirectory)
3535
import System.Posix.IO.PosixString
3636
import System.Posix.Types
3737

38+
#if !defined(HAVE_MKSTEMP)
39+
import System.IO.Error ( ioeSetLocation )
40+
import GHC.IO.Exception ( unsupportedOperation )
41+
#endif
42+
43+
#if !defined(HAVE_MKSTEMP)
44+
45+
{-# WARNING mkstemp "operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_MKSTEMP@)" #-}
46+
mkstemp :: PosixString -> IO (PosixPath, Handle)
47+
mkstemp _ = ioError (ioeSetLocation unsupportedOperation "mkstemp")
48+
49+
#else
50+
3851
foreign import capi unsafe "HsUnix.h mkstemp"
3952
c_mkstemp :: CString -> IO CInt
4053

@@ -54,6 +67,8 @@ mkstemp (PosixString template') = do
5467
h <- fdToHandle (Fd fd)
5568
return (name, h)
5669

70+
#endif // HAVE_MKSTEMP
71+
5772
#if HAVE_MKSTEMPS
5873
foreign import capi unsafe "HsUnix.h mkstemps"
5974
c_mkstemps :: CString -> CInt -> IO CInt

0 commit comments

Comments
 (0)