We drop the tools specifically designed for Haskell and Rust together, in favour of general tools for using each with C. Namely, we use Mozilla's `cbindgen` for generating header files from the Rust source, and Well-Typed's new `hs-bindgen` tool for generating Haskell from those header files. The Rust code here is essentially the result of expanding the old macro, then inlining and renaming internals. The most important thing here is that we're now relying solely on robust well-maintained tools.
48 lines
1.4 KiB
Haskell
48 lines
1.4 KiB
Haskell
{-# LANGUAGE CApiFFI #-}
|
|
{-# LANGUAGE NoImplicitPrelude #-}
|
|
{-# LANGUAGE TemplateHaskell #-}
|
|
{-# OPTIONS_HADDOCK prune #-}
|
|
|
|
module GarnetRs.FunPtr where
|
|
|
|
import qualified Foreign.C as FC
|
|
import qualified GHC.IO.Unsafe
|
|
import qualified GHC.Ptr as Ptr
|
|
import qualified HsBindgen.Runtime.Internal.CAPI
|
|
import qualified HsBindgen.Runtime.Internal.HasFFIType
|
|
import qualified HsBindgen.Runtime.PtrConst
|
|
import Data.Void (Void)
|
|
import Prelude (IO)
|
|
|
|
$(HsBindgen.Runtime.Internal.CAPI.addCSource (HsBindgen.Runtime.Internal.CAPI.unlines
|
|
[ "#include <garnet_rs.h>"
|
|
, "/* com_garnet_GarnetRs_get_hello */"
|
|
, "__attribute__ ((const))"
|
|
, "void (*hs_bindgen_faf62265b53521d3 (void)) ("
|
|
, " char const *arg1"
|
|
, ")"
|
|
, "{"
|
|
, " return &hello;"
|
|
, "}"
|
|
]))
|
|
|
|
-- __unique:__ @com_garnet_GarnetRs_get_hello@
|
|
foreign import ccall unsafe "hs_bindgen_faf62265b53521d3" hs_bindgen_faf62265b53521d3_base ::
|
|
IO (Ptr.FunPtr Void)
|
|
|
|
-- __unique:__ @com_garnet_GarnetRs_get_hello@
|
|
hs_bindgen_faf62265b53521d3 :: IO (Ptr.FunPtr ((HsBindgen.Runtime.PtrConst.PtrConst FC.CChar) -> IO ()))
|
|
hs_bindgen_faf62265b53521d3 =
|
|
HsBindgen.Runtime.Internal.HasFFIType.fromFFIType hs_bindgen_faf62265b53521d3_base
|
|
|
|
{-# NOINLINE hello #-}
|
|
{-| __C declaration:__ @hello@
|
|
|
|
__defined at:__ @garnet_rs.h 6:6@
|
|
|
|
__exported by:__ @garnet_rs.h@
|
|
-}
|
|
hello :: Ptr.FunPtr ((HsBindgen.Runtime.PtrConst.PtrConst FC.CChar) -> IO ())
|
|
hello =
|
|
GHC.IO.Unsafe.unsafePerformIO hs_bindgen_faf62265b53521d3
|