use upstream fix to avoid header patching hack
This commit is contained in:
parent
cdada4c9be
commit
e70aac0f1b
@ -6,9 +6,9 @@ packages: .
|
|||||||
source-repository-package
|
source-repository-package
|
||||||
type: git
|
type: git
|
||||||
location: https://github.com/well-typed/hs-bindgen
|
location: https://github.com/well-typed/hs-bindgen
|
||||||
tag: 6ca94188abd756a1fb4dd8a4037de3fa7dca0765
|
tag: 94d74d3f3e72c8fabc85700f916387fe851ba20a
|
||||||
subdir: c-expr-dsl c-expr-runtime hs-bindgen hs-bindgen-runtime
|
subdir: c-expr-dsl c-expr-runtime hs-bindgen hs-bindgen-runtime
|
||||||
--sha256: M+8tEZA8gsEc6gXnNdSbRpMBQ5LkH7sphcV1aR0fclA=
|
--sha256: eM0CJj1HDAClvjkv5QUaF7aZoMwnPm4GuoLTkp8SHq8=
|
||||||
source-repository-package
|
source-repository-package
|
||||||
type: git
|
type: git
|
||||||
location: https://github.com/well-typed/libclang
|
location: https://github.com/well-typed/libclang
|
||||||
|
|||||||
@ -34,8 +34,8 @@ data Shape
|
|||||||
| Rectangle CDouble CDouble
|
| Rectangle CDouble CDouble
|
||||||
convertShape :: Shape -> Raw.Shape
|
convertShape :: Shape -> Raw.Shape
|
||||||
convertShape = \case
|
convertShape = \case
|
||||||
Circle r -> Raw.Shape Raw.Circle $ Raw.set_shape_body_circle $ Raw.Circle_Body r
|
Circle r -> Raw.Shape Raw.Circle $ Raw.set_shape_anon0_circle $ Raw.Circle_Body r
|
||||||
Rectangle w h -> Raw.Shape Raw.Rectangle $ Raw.set_shape_body_rectangle $ Raw.Rectangle_Body w h
|
Rectangle w h -> Raw.Shape Raw.Rectangle $ Raw.set_shape_anon0_rectangle $ Raw.Rectangle_Body w h
|
||||||
|
|
||||||
data BTree a
|
data BTree a
|
||||||
= Leaf a
|
= Leaf a
|
||||||
@ -43,14 +43,14 @@ data BTree a
|
|||||||
withBTree :: BTree Int64 -> (Raw.BTreeC -> IO a) -> IO a
|
withBTree :: BTree Int64 -> (Raw.BTreeC -> IO a) -> IO a
|
||||||
withBTree =
|
withBTree =
|
||||||
runContT . fix \f -> \case
|
runContT . fix \f -> \case
|
||||||
Leaf v -> pure $ Raw.BTreeC Raw.Leaf $ Raw.set_bTreeC_body_leaf $ Raw.Leaf_Body v
|
Leaf v -> pure $ Raw.BTreeC Raw.Leaf $ Raw.set_bTreeC_anon0_leaf $ Raw.Leaf_Body v
|
||||||
Fork l r -> do
|
Fork l r -> do
|
||||||
lRaw <- f l
|
lRaw <- f l
|
||||||
rRaw <- f r
|
rRaw <- f r
|
||||||
lPtr <- ContT alloca
|
lPtr <- ContT alloca
|
||||||
rPtr <- ContT alloca
|
rPtr <- ContT alloca
|
||||||
lift $ poke lPtr lRaw >> poke rPtr rRaw
|
lift $ poke lPtr lRaw >> poke rPtr rRaw
|
||||||
pure . Raw.BTreeC Raw.Fork . Raw.set_bTreeC_body_fork $
|
pure . Raw.BTreeC Raw.Fork . Raw.set_bTreeC_anon0_fork $
|
||||||
Raw.Fork_Body (unsafeFromPtr lPtr) (unsafeFromPtr rPtr)
|
Raw.Fork_Body (unsafeFromPtr lPtr) (unsafeFromPtr rPtr)
|
||||||
|
|
||||||
hello :: ByteString -> IO ()
|
hello :: ByteString -> IO ()
|
||||||
|
|||||||
@ -13,31 +13,15 @@ fn main() {
|
|||||||
.generate()
|
.generate()
|
||||||
.expect("Unable to generate bindings");
|
.expect("Unable to generate bindings");
|
||||||
|
|
||||||
// TODO vibe-coded workaround for hs-bindgen issue: https://github.com/well-typed/hs-bindgen/issues/1649
|
|
||||||
// would otherwise just use `.write_to_file`
|
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
bindings.write(&mut buf);
|
bindings.write(&mut buf);
|
||||||
let header = String::from_utf8(buf).unwrap();
|
let header = String::from_utf8(buf).unwrap();
|
||||||
let mut patched = String::new();
|
|
||||||
let mut saw_union = false;
|
|
||||||
for line in header.lines() {
|
|
||||||
if line == " };" && saw_union {
|
|
||||||
patched.push_str(" } body;\n");
|
|
||||||
saw_union = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if line == " union {" {
|
|
||||||
saw_union = true;
|
|
||||||
}
|
|
||||||
patched.push_str(line);
|
|
||||||
patched.push('\n');
|
|
||||||
}
|
|
||||||
fs::write(
|
fs::write(
|
||||||
PathBuf::from(&crate_dir)
|
PathBuf::from(&crate_dir)
|
||||||
.join("target")
|
.join("target")
|
||||||
.join(&profile)
|
.join(&profile)
|
||||||
.join("garnet_rs.h"),
|
.join("garnet_rs.h"),
|
||||||
patched,
|
header,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user