George Thomas 0a1911862f Expose explicit C interface
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.
2026-02-19 16:29:41 +00:00

49 lines
1.3 KiB
Haskell

{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_HADDOCK prune #-}
module GarnetRs.Safe where
import qualified Foreign.C as FC
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>"
, "void hs_bindgen_433ea2a26af4e593 ("
, " char const *arg1"
, ")"
, "{"
, " hello(arg1);"
, "}"
]))
-- __unique:__ @com_garnet_GarnetRs_Safe_hello@
foreign import ccall safe "hs_bindgen_433ea2a26af4e593" hs_bindgen_433ea2a26af4e593_base ::
Ptr.Ptr Void
-> IO ()
-- __unique:__ @com_garnet_GarnetRs_Safe_hello@
hs_bindgen_433ea2a26af4e593 ::
HsBindgen.Runtime.PtrConst.PtrConst FC.CChar
-> IO ()
hs_bindgen_433ea2a26af4e593 =
HsBindgen.Runtime.Internal.HasFFIType.fromFFIType hs_bindgen_433ea2a26af4e593_base
{-| __C declaration:__ @hello@
__defined at:__ @garnet_rs.h 6:6@
__exported by:__ @garnet_rs.h@
-}
hello ::
HsBindgen.Runtime.PtrConst.PtrConst FC.CChar
-- ^ __C declaration:__ @c@
-> IO ()
hello = hs_bindgen_433ea2a26af4e593