Compare commits
8 Commits
7bbba202af
...
c1d30b0e61
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1d30b0e61 | ||
|
|
ea5f816425 | ||
|
|
5c3aa088f7 | ||
|
|
6203e7570f | ||
|
|
9e8bccdafd | ||
|
|
8cb0bf9c5e | ||
|
|
2ff3ad93e5 | ||
|
|
8a5bf61d6b |
@ -29,15 +29,7 @@ import HsBindgen.TH
|
||||
import Language.Haskell.TH
|
||||
import System.Process
|
||||
|
||||
import Control.Monad.IO.Class (MonadIO (liftIO))
|
||||
import Language.Haskell.TH.Syntax (addDependentFile)
|
||||
import System.Directory.Extra (getCurrentDirectory)
|
||||
|
||||
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
|
||||
map (Dir . T.unpack . T.strip)
|
||||
. concatMap (takeWhile (maybe False ((== ' ') . fst) . T.uncons) . dropWhile T.null . T.lines)
|
||||
|
||||
@ -19,8 +19,6 @@
|
||||
};
|
||||
overrides = [
|
||||
({ 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 = {
|
||||
build-tools = [ pkgs.llvmPackages.llvm ];
|
||||
libs = [ pkgs.llvmPackages.libclang ];
|
||||
|
||||
@ -14,6 +14,7 @@ fn main() {
|
||||
// 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
|
||||
// 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
|
||||
// don't get me started in the discoverability of actually then using the terminal for debugging:
|
||||
// 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)]
|
||||
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())
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ struct T {
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn hello_struct(t: &T) {
|
||||
extern "C" fn hello_struct(t: &T) -> () {
|
||||
say_hello(&format!("{:?}", t))
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ enum Shape {
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn hello_shape(s: &Shape) {
|
||||
extern "C" fn hello_shape(s: &Shape) -> () {
|
||||
say_hello(&format!("{:?}", s))
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ enum BTreeC {
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn sum_tree(t: &BTreeC) -> i64 {
|
||||
(unsafe { std::mem::transmute::<&BTreeC, &BTree<i64>>(t) }).sum()
|
||||
(unsafe { std::mem::transmute::<_, &BTree<i64>>(t) }).sum()
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
@ -102,8 +102,9 @@ extern "C" fn sum_slice(v: *const i64, s: usize) -> i64 {
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn print_optional(x: Option<&i8>) {
|
||||
if let Some(x) = x {
|
||||
println!("{}", x / 2)
|
||||
extern "C" fn print_optional(x: Option<&i8>) -> () {
|
||||
match x {
|
||||
Some(x) => println!("{}", x / 2),
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user