From aaaf02b783e01126c37c7c235550dcf011175cc4 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Wed, 18 Mar 2026 11:25:15 +0000 Subject: [PATCH] use upstream fix to avoid header patching hack... --- flake.lock | 14 ++++++-------- flake.nix | 4 ++-- lib/GarnetRs/Wrapped.hs | 8 ++++---- rust/build.rs | 18 +----------------- 4 files changed, 13 insertions(+), 31 deletions(-) diff --git a/flake.lock b/flake.lock index d876244..9c0d1a8 100644 --- a/flake.lock +++ b/flake.lock @@ -527,17 +527,16 @@ "hs-bindgen-src": { "flake": false, "locked": { - "lastModified": 1773399083, - "narHash": "sha256-oF6E1/zRZ4iiZs9QjtQMvHnLMfq/W6CXOX44QbDGYXs=", + "lastModified": 1774379170, + "narHash": "sha256-lZV6IdCBf8uCt21qB5mfgLaP9CNgho/HsqjvkulDR2Q=", "owner": "well-typed", "repo": "hs-bindgen", - "rev": "6ca94188abd756a1fb4dd8a4037de3fa7dca0765", + "rev": "4b6febb5cc6196835bd2890a3ab27a88dab1806b", "type": "github" }, "original": { "owner": "well-typed", "repo": "hs-bindgen", - "rev": "6ca94188abd756a1fb4dd8a4037de3fa7dca0765", "type": "github" } }, @@ -561,17 +560,16 @@ "libclang-src": { "flake": false, "locked": { - "lastModified": 1773221966, - "narHash": "sha256-VPG7jKdq2g/Hwf5cPiy4coAvLULxDeA4KHCVkNSSs5w=", + "lastModified": 1774018529, + "narHash": "sha256-Bo5wvityXKCmlnrobtI9WkA1maR7sfkDXo1VOZvrPLk=", "owner": "well-typed", "repo": "libclang", - "rev": "d6e482df49b88375cf3075928a78ee86c2a068d4", + "rev": "83387d72a8dfae9f75d27db6b32ea37afab06268", "type": "github" }, "original": { "owner": "well-typed", "repo": "libclang", - "rev": "d6e482df49b88375cf3075928a78ee86c2a068d4", "type": "github" } }, diff --git a/flake.nix b/flake.nix index 202c05b..3232689 100644 --- a/flake.nix +++ b/flake.nix @@ -3,8 +3,8 @@ nix-haskell.url = "github:reflex-frp/nix-haskell"; nixpkgs.follows = "nix-haskell/nixpkgs"; hls-src = { url = "github:haskell/haskell-language-server/2.13.0.0"; flake = false; }; - hs-bindgen-src = { url = "github:well-typed/hs-bindgen/6ca94188abd756a1fb4dd8a4037de3fa7dca0765"; flake = false; }; - libclang-src = { url = "github:well-typed/libclang/d6e482df49b88375cf3075928a78ee86c2a068d4"; flake = false; }; + hs-bindgen-src = { url = "github:well-typed/hs-bindgen"; flake = false; }; + libclang-src = { url = "github:well-typed/libclang"; flake = false; }; flake-utils.url = "github:numtide/flake-utils"; crane.url = "github:ipetkov/crane"; rust-overlay = { diff --git a/lib/GarnetRs/Wrapped.hs b/lib/GarnetRs/Wrapped.hs index 4ad72c2..51d9255 100644 --- a/lib/GarnetRs/Wrapped.hs +++ b/lib/GarnetRs/Wrapped.hs @@ -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_circle_circle $ Raw.Circle_Body r + Rectangle w h -> Raw.Shape Raw.Rectangle $ Raw.set_shape_circle_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_leaf_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_leaf_fork $ Raw.Fork_Body (unsafeFromPtr lPtr) (unsafeFromPtr rPtr) hello :: ByteString -> IO () diff --git a/rust/build.rs b/rust/build.rs index d633ace..45a8313 100644 --- a/rust/build.rs +++ b/rust/build.rs @@ -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#issuecomment-3994425922 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(); }