Compare commits
10 Commits
c1d30b0e61
...
7bbba202af
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7bbba202af | ||
|
|
209f674541 | ||
|
|
111b65c708 | ||
|
|
a06f3076c7 | ||
|
|
7d9982112a | ||
|
|
31ae16784a | ||
|
|
b788d6685d | ||
|
|
63efd03382 | ||
|
|
bf0fc90272 | ||
|
|
6028db040d |
@ -29,7 +29,15 @@ import HsBindgen.TH
|
|||||||
import Language.Haskell.TH
|
import Language.Haskell.TH
|
||||||
import System.Process
|
import System.Process
|
||||||
|
|
||||||
|
import Control.Monad.IO.Class (MonadIO (liftIO))
|
||||||
|
import Language.Haskell.TH.Syntax (addDependentFile)
|
||||||
|
import System.Directory.Extra (getCurrentDirectory)
|
||||||
|
|
||||||
do
|
do
|
||||||
|
-- not sure this does anything - hs-bindgen should already be doing the tracking, and the issues are from elsewhere
|
||||||
|
-- dir <- liftIO getCurrentDirectory
|
||||||
|
-- liftIO $ print dir
|
||||||
|
-- addDependentFile $ dir <> "/rust/target/debug/garnet_rs.h"
|
||||||
systemDirs <- -- TODO bit of a hack
|
systemDirs <- -- TODO bit of a hack
|
||||||
map (Dir . T.unpack . T.strip)
|
map (Dir . T.unpack . T.strip)
|
||||||
. concatMap (takeWhile (maybe False ((== ' ') . fst) . T.uncons) . dropWhile T.null . T.lines)
|
. concatMap (takeWhile (maybe False ((== ' ') . fst) . T.uncons) . dropWhile T.null . T.lines)
|
||||||
|
|||||||
@ -19,6 +19,8 @@
|
|||||||
};
|
};
|
||||||
overrides = [
|
overrides = [
|
||||||
({ pkgs, ... }: {
|
({ pkgs, ... }: {
|
||||||
|
# TODO get this upstreamed:
|
||||||
|
# https://input-output-hk.github.io/haskell.nix/tutorials/pkg-map.html#mapping-in-haskellnix
|
||||||
packages.libclang-bindings.components.library = {
|
packages.libclang-bindings.components.library = {
|
||||||
build-tools = [ pkgs.llvmPackages.llvm ];
|
build-tools = [ pkgs.llvmPackages.llvm ];
|
||||||
libs = [ pkgs.llvmPackages.libclang ];
|
libs = [ pkgs.llvmPackages.libclang ];
|
||||||
|
|||||||
@ -14,7 +14,6 @@ fn main() {
|
|||||||
// void print_optional(const int8_t *x);
|
// void print_optional(const int8_t *x);
|
||||||
// and that's only an issue because in HLS TH dependent-file watching gives up after an error
|
// and that's only an issue because in HLS TH dependent-file watching gives up after an error
|
||||||
// i.e. once the containing splice has thrown an exception once, the containing file needs a manual edit to kick it
|
// i.e. once the containing splice has thrown an exception once, the containing file needs a manual edit to kick it
|
||||||
// and that's really not helped by Rust Analyzer mostly only showing diagnostics on save
|
|
||||||
// P.S. strings to stdout?! what a terrible API
|
// P.S. strings to stdout?! what a terrible API
|
||||||
// don't get me started in the discoverability of actually then using the terminal for debugging:
|
// don't get me started in the discoverability of actually then using the terminal for debugging:
|
||||||
// println!("cargo::warning={:?}", env::var("OUT_DIR"));
|
// println!("cargo::warning={:?}", env::var("OUT_DIR"));
|
||||||
|
|||||||
15
rust/lib.rs
15
rust/lib.rs
@ -11,7 +11,7 @@ fn say_hello(name: &str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
extern "C" fn hello(c: *const c_char) -> () {
|
extern "C" fn hello(c: *const c_char) {
|
||||||
say_hello(unsafe { CStr::from_ptr(c) }.to_str().unwrap())
|
say_hello(unsafe { CStr::from_ptr(c) }.to_str().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ struct T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
extern "C" fn hello_struct(t: &T) -> () {
|
extern "C" fn hello_struct(t: &T) {
|
||||||
say_hello(&format!("{:?}", t))
|
say_hello(&format!("{:?}", t))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ enum Shape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
extern "C" fn hello_shape(s: &Shape) -> () {
|
extern "C" fn hello_shape(s: &Shape) {
|
||||||
say_hello(&format!("{:?}", s))
|
say_hello(&format!("{:?}", s))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ enum BTreeC {
|
|||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
extern "C" fn sum_tree(t: &BTreeC) -> i64 {
|
extern "C" fn sum_tree(t: &BTreeC) -> i64 {
|
||||||
(unsafe { std::mem::transmute::<_, &BTree<i64>>(t) }).sum()
|
(unsafe { std::mem::transmute::<&BTreeC, &BTree<i64>>(t) }).sum()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
@ -102,9 +102,8 @@ extern "C" fn sum_slice(v: *const i64, s: usize) -> i64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
extern "C" fn print_optional(x: Option<&i8>) -> () {
|
extern "C" fn print_optional(x: Option<&i8>) {
|
||||||
match x {
|
if let Some(x) = x {
|
||||||
Some(x) => println!("{}", x / 2),
|
println!("{}", x / 2)
|
||||||
None => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user