All Projects → harpocrates → Inline Rust

harpocrates / Inline Rust

Licence: other
Use snippets of Rust inline in your Haskell programs

Programming Languages

rust
11053 projects
haskell
3896 projects

Labels

Projects that are alternatives of or similar to Inline Rust

Winapi Rs
Rust bindings to Windows API
Stars: ✭ 1,237 (+489.05%)
Mutual labels:  ffi
Fficxx
Haskell-C++ Foreign Function Interface Generator
Stars: ✭ 117 (-44.29%)
Mutual labels:  ffi
Goluwa
a game framework written in luajit
Stars: ✭ 173 (-17.62%)
Mutual labels:  ffi
Realm Dart Ffi
Experimental Realm binding using dart:ffi preview support
Stars: ✭ 83 (-60.48%)
Mutual labels:  ffi
Derry
A script manager for Dart.
Stars: ✭ 107 (-49.05%)
Mutual labels:  ffi
Tflite native
A Dart interface to TensorFlow Lite (tflite) through dart:ffi
Stars: ✭ 120 (-42.86%)
Mutual labels:  ffi
Fruity
Rusty bindings for Apple libraries
Stars: ✭ 72 (-65.71%)
Mutual labels:  ffi
Emacs Module Rs
Rust binding and tools for emacs-module (Emacs's dynamic module support)
Stars: ✭ 203 (-3.33%)
Mutual labels:  ffi
Lzmq
Lua binding to ZeroMQ
Stars: ✭ 110 (-47.62%)
Mutual labels:  ffi
Rustr
Rust and R Integration
Stars: ✭ 160 (-23.81%)
Mutual labels:  ffi
Erlang nif Sys
Low level bindings to Erlang NIF API for Rust
Stars: ✭ 84 (-60%)
Mutual labels:  ffi
Android Luajit Launcher
Android NativeActivity based launcher for LuaJIT, implementing the main loop within Lua land via FFI
Stars: ✭ 87 (-58.57%)
Mutual labels:  ffi
Ffi Navigator
Stars: ✭ 122 (-41.9%)
Mutual labels:  ffi
Koreader Base
Base framework offering a Lua scriptable environment for creating document readers
Stars: ✭ 81 (-61.43%)
Mutual labels:  ffi
Rust Bindgen
Automatically generates Rust FFI bindings to C (and some C++) libraries.
Stars: ✭ 2,453 (+1068.1%)
Mutual labels:  ffi
Ffi Platypus
Write Perl bindings to non-Perl libraries with FFI. No XS required.
Stars: ✭ 80 (-61.9%)
Mutual labels:  ffi
Swift Haskell Tutorial
Integrating Haskell with Swift Mac Apps
Stars: ✭ 118 (-43.81%)
Mutual labels:  ffi
Rust Ffi Guide
A guide for doing FFI using Rust
Stars: ✭ 207 (-1.43%)
Mutual labels:  ffi
Inline Java
Haskell/Java interop via inline Java code in Haskell modules.
Stars: ✭ 197 (-6.19%)
Mutual labels:  ffi
Libnotify
Ruby bindings for libnotify using FFI.
Stars: ✭ 138 (-34.29%)
Mutual labels:  ffi

inline-rust

Build Status Windows build status

This package allows you to write Rust inline in your Haskell source using quasiquotes. Here is a short example. For more examples, check out the examples folder.

-- examples/Hello.hs
{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}

module Main where

import Language.Rust.Inline
import Data.Int

extendContext basic
setCrateRoot []

main = do
  putStrLn "Haskell: Hello. Enter a number:"
  x <- readLn
  y <- [rustIO| i32 {
    let x = $(x: i32);
    println!("Rust: Your number is {}", x);
    x + 1
  } |]
  putStrLn $ "Haskell: Rust says number plus 1 is " ++ show y

If you want to use this with GHCi, make sure to pass in -fobject-code.

Building

This currently depends on a GHC feature that will be available in GHC 8.6. Until then, you'll have to build GHC yourself or get a binary. For the latter, you can install one of GHC's nightly builds.

$ curl https://ghc-artifacts.s3.amazonaws.com/nightly/validate-x86_64-darwin/latest/bindist.tar.xz | tar xz
$ cd ghc-*
$ ./configure && make install

With that installed, something like the following should work

$ cabal new-build -w /usr/local/bin/ghc-8.5.20180423
$ cabal new-test  -w /usr/local/bin/ghc-8.5.20180423

Running the examples is only a matter of threading through the right package databases. With a new enough Cabal, new-exec does this for you.

$ cabal new-exec -w /usr/local/bin/ghc-8.5.20180423 ghc -- -threaded -package inline-rust examples/Hello.hs
[1 of 1] Compiling Main             ( examples/Hello.hs, examples/Hello.o )
Linking examples/Hello ...
$ ./examples/Hello
Haskell: Hello. Enter a number:
42
Rust: Your number is 42
Haskell: Rust says number plus 1 is 43

Bugs

Please report bugs to the issue tracker

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].