use upstream fix to avoid header patching hack

This commit is contained in:
George Thomas 2026-03-18 11:25:15 +00:00
parent cdada4c9be
commit e70aac0f1b
3 changed files with 7 additions and 23 deletions

View File

@ -6,9 +6,9 @@ packages: .
source-repository-package
type: git
location: https://github.com/well-typed/hs-bindgen
tag: 6ca94188abd756a1fb4dd8a4037de3fa7dca0765
tag: 94d74d3f3e72c8fabc85700f916387fe851ba20a
subdir: c-expr-dsl c-expr-runtime hs-bindgen hs-bindgen-runtime
--sha256: M+8tEZA8gsEc6gXnNdSbRpMBQ5LkH7sphcV1aR0fclA=
--sha256: eM0CJj1HDAClvjkv5QUaF7aZoMwnPm4GuoLTkp8SHq8=
source-repository-package
type: git
location: https://github.com/well-typed/libclang

View File

@ -34,8 +34,8 @@ data Shape
| Rectangle CDouble CDouble
convertShape :: Shape -> Raw.Shape
convertShape = \case
Circle r -> Raw.Shape Raw.Circle $ Raw.set_shape_body_circle $ Raw.Circle_Body r
Rectangle w h -> Raw.Shape Raw.Rectangle $ Raw.set_shape_body_rectangle $ Raw.Rectangle_Body w h
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_anon0_rectangle $ Raw.Rectangle_Body w h
data BTree a
= Leaf a
@ -43,14 +43,14 @@ data BTree a
withBTree :: BTree Int64 -> (Raw.BTreeC -> IO a) -> IO a
withBTree =
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
lRaw <- f l
rRaw <- f r
lPtr <- ContT alloca
rPtr <- ContT alloca
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)
hello :: ByteString -> IO ()

View File

@ -13,31 +13,15 @@ fn main() {
.generate()
.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();
bindings.write(&mut buf);
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(
PathBuf::from(&crate_dir)
.join("target")
.join(&profile)
.join("garnet_rs.h"),
patched,
header,
)
.unwrap();
}