summaryrefslogtreecommitdiff
path: root/rusty-haskell/haskell
diff options
context:
space:
mode:
authorstuebinm2021-04-11 03:37:32 +0200
committerstuebinm2021-04-11 03:37:32 +0200
commitfa49e0bf71ccd4bc98df0fa83546250c1b849e2e (patch)
treef84c1ff8000fe87fae6b7c703e6b7871101a5094 /rusty-haskell/haskell
parentf7605dfefa304b1a7b20a474ce168cd5b9849533 (diff)
simple ffi with rust and haskell
so far, only calling rust from haskell, not the other way round.
Diffstat (limited to 'rusty-haskell/haskell')
-rw-r--r--rusty-haskell/haskell/.gitignore1
-rw-r--r--rusty-haskell/haskell/rust-haskell-ffi.cabal26
-rw-r--r--rusty-haskell/haskell/src/FLib.hs8
-rw-r--r--rusty-haskell/haskell/src/Main.hs16
4 files changed, 51 insertions, 0 deletions
diff --git a/rusty-haskell/haskell/.gitignore b/rusty-haskell/haskell/.gitignore
new file mode 100644
index 0000000..b5e3679
--- /dev/null
+++ b/rusty-haskell/haskell/.gitignore
@@ -0,0 +1 @@
+dist-newstyle/*
diff --git a/rusty-haskell/haskell/rust-haskell-ffi.cabal b/rusty-haskell/haskell/rust-haskell-ffi.cabal
new file mode 100644
index 0000000..c540b57
--- /dev/null
+++ b/rusty-haskell/haskell/rust-haskell-ffi.cabal
@@ -0,0 +1,26 @@
+cabal-version: >=1.10
+-- Initial package description 'rust-haskell-ffi.cabal' generated by 'cabal
+-- init'. For further documentation, see
+-- http://haskell.org/cabal/users-guide/
+
+name: rust-haskell-ffi
+version: 0.1.0.0
+-- synopsis:
+-- description:
+-- bug-reports:
+-- license:
+license-file: LICENSE
+author: stuebinm
+maintainer: stuebinm@disroot.org
+-- copyright:
+-- category:
+build-type: Simple
+extra-source-files: CHANGELOG.md
+
+executable rust-haskell-ffi
+ main-is: src/Main.hs
+ other-extensions: ForeignFunctionInterface
+ build-depends: base >= 4.7 && < 5
+ default-language: Haskell2010
+ extra-libraries: rustlib, pthread
+ extra-lib-dirs: ../rust/target/release
diff --git a/rusty-haskell/haskell/src/FLib.hs b/rusty-haskell/haskell/src/FLib.hs
new file mode 100644
index 0000000..7fc1d61
--- /dev/null
+++ b/rusty-haskell/haskell/src/FLib.hs
@@ -0,0 +1,8 @@
+module FLib where
+
+import Foreign.C.Types
+import Foreign.C.String
+
+foreign import ccall "double_input" doubleInput :: CInt -> CInt
+--foreign import ccall unsafe "print_string" printString :: CString -> IO ()
+foreign import ccall "print_hello" printHello :: IO ()
diff --git a/rusty-haskell/haskell/src/Main.hs b/rusty-haskell/haskell/src/Main.hs
new file mode 100644
index 0000000..2c6a7ae
--- /dev/null
+++ b/rusty-haskell/haskell/src/Main.hs
@@ -0,0 +1,16 @@
+module Main where
+
+
+import Foreign.C.Types
+import Foreign.C.String
+
+foreign import ccall "double_input" doubleInput :: CInt -> CInt
+--foreign import ccall unsafe "print_string" printString :: CString -> IO ()
+foreign import ccall "print_hello" printHello :: IO ()
+
+
+main :: IO ()
+main = do
+ let b = doubleInput 2
+ printHello
+ putStrLn $ show b