module Unison.Runtime.FFI.DLL where
import Foreign.Ptr
import System.Posix.DynamicLinker qualified as Posix
data DLL = DLL !FilePath !Posix.DL
getDLLPath :: DLL -> FilePath
getDLLPath :: DLL -> FilePath
getDLLPath (DLL FilePath
path DL
_) = FilePath
path
openDLL :: FilePath -> IO DLL
openDLL :: FilePath -> IO DLL
openDLL FilePath
path = FilePath -> DL -> DLL
DLL FilePath
path (DL -> DLL) -> IO DL -> IO DLL
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FilePath -> [RTLDFlags] -> IO DL
Posix.dlopen FilePath
path [RTLDFlags
Posix.RTLD_LAZY]
getDLLSym :: DLL -> String -> IO (FunPtr a)
getDLLSym :: forall a. DLL -> FilePath -> IO (FunPtr a)
getDLLSym (DLL FilePath
_ DL
dll) FilePath
symbol = DL -> FilePath -> IO (FunPtr a)
forall a. DL -> FilePath -> IO (FunPtr a)
Posix.dlsym DL
dll FilePath
symbol