Compare commits
1 Commits
main
...
th-record-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5aa0cdc38d |
@ -5,10 +5,10 @@ packages: .
|
||||
-- so we specify the equivalent commit SHAs manually instead
|
||||
source-repository-package
|
||||
type: git
|
||||
location: https://github.com/well-typed/hs-bindgen
|
||||
tag: e2a9260678d9fa76dab602a5a07927acada3be4f
|
||||
location: https://github.com/georgefst/hs-bindgen
|
||||
tag: 3693360bcd1f8478932c4944c70baca7c4ecf950
|
||||
subdir: c-expr-dsl c-expr-runtime hs-bindgen hs-bindgen-runtime
|
||||
--sha256: 0nrs3iq0l5ha5kxyhqnlmvgi7734pmzyp3zf7p8s1gb21ylh4sy0
|
||||
--sha256: lV2FwS80iHhJU6iie/F24W4dYV+vvmeTu6465NLnOb4=
|
||||
source-repository-package
|
||||
type: git
|
||||
location: https://github.com/well-typed/libclang
|
||||
|
||||
@ -19,7 +19,7 @@ set -euo pipefail
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
RUST_DIR="$SCRIPT_DIR/rust"
|
||||
HEADER_NAME="garnet_rs.h"
|
||||
HEADER="$RUST_DIR/target/debug/$HEADER_NAME"
|
||||
HEADER="$RUST_DIR/$HEADER_NAME"
|
||||
|
||||
# --- Step 1: Build Rust static library ---
|
||||
echo "=== Building Rust library ==="
|
||||
@ -66,7 +66,7 @@ echo " Patched header at $HEADER"
|
||||
echo "=== Configuring Cabal ==="
|
||||
cabal configure \
|
||||
--extra-lib-dirs="$RUST_DIR/target/debug" \
|
||||
--extra-include-dirs="$RUST_DIR/target/debug"
|
||||
--extra-include-dirs="$RUST_DIR"
|
||||
|
||||
echo "=== Done ==="
|
||||
echo "Run 'cabal run' to test."
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{-# LANGUAGE CApiFFI #-}
|
||||
{-# LANGUAGE DerivingVia #-}
|
||||
{-# LANGUAGE FieldSelectors #-}
|
||||
-- {-# LANGUAGE NoFieldSelectors #-}
|
||||
{-# LANGUAGE MagicHash #-}
|
||||
{-# LANGUAGE PatternSynonyms #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
@ -40,7 +41,10 @@ do
|
||||
<$> runIO (readProcessWithExitCode "cpp" ["-v"] "")
|
||||
withHsBindgen
|
||||
def
|
||||
{ clang = def{extraIncludeDirs = Pkg "rust/target/debug" : systemDirs}
|
||||
{ clang = def{extraIncludeDirs = Pkg "rust" : systemDirs}
|
||||
-- hmm, I guess there's a reason this wasn't exported
|
||||
-- , fieldNamingStrategy = EnableRecordDot
|
||||
, fieldNamingStrategy = PrefixedFieldNames
|
||||
}
|
||||
def
|
||||
$ hashInclude "garnet_rs.h"
|
||||
|
||||
63
rust/garnet_rs.h
Normal file
63
rust/garnet_rs.h
Normal file
@ -0,0 +1,63 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct T {
|
||||
bool a;
|
||||
uint8_t b;
|
||||
};
|
||||
|
||||
enum Shape_Tag {
|
||||
Circle,
|
||||
Rectangle,
|
||||
};
|
||||
|
||||
struct Circle_Body {
|
||||
double radius;
|
||||
};
|
||||
|
||||
struct Rectangle_Body {
|
||||
double width;
|
||||
double height;
|
||||
};
|
||||
|
||||
struct Shape {
|
||||
enum Shape_Tag tag;
|
||||
union {
|
||||
struct Circle_Body circle;
|
||||
struct Rectangle_Body rectangle;
|
||||
} body;
|
||||
};
|
||||
|
||||
enum BTreeC_Tag {
|
||||
Leaf,
|
||||
Fork,
|
||||
};
|
||||
|
||||
struct Leaf_Body {
|
||||
int64_t value;
|
||||
};
|
||||
|
||||
struct Fork_Body {
|
||||
const struct BTreeC *left;
|
||||
const struct BTreeC *right;
|
||||
};
|
||||
|
||||
struct BTreeC {
|
||||
enum BTreeC_Tag tag;
|
||||
union {
|
||||
struct Leaf_Body leaf;
|
||||
struct Fork_Body fork;
|
||||
} body;
|
||||
};
|
||||
|
||||
void hello(const char *c);
|
||||
|
||||
void hello_struct(struct T t);
|
||||
|
||||
void hello_shape(struct Shape s);
|
||||
|
||||
__attribute__((const)) int64_t add(int64_t a, int64_t b);
|
||||
|
||||
int64_t sum_tree(struct BTreeC t);
|
||||
Loading…
x
Reference in New Issue
Block a user