Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52f0a49d87 | ||
|
|
df1f73eb8a | ||
|
|
6bb06b117f | ||
|
|
649c1b466f | ||
|
|
b79a4c0804 | ||
|
|
b68d6257d3 | ||
|
|
b94e8ef11b | ||
|
|
4ecd0b16e2 | ||
|
|
ddb9c300cf |
6
build
6
build
@ -2,5 +2,9 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
cargo build --manifest-path ./rust/Cargo.toml
|
cargo build --manifest-path ./rust/Cargo.toml
|
||||||
ln -sf $(pwd)/rust/target/debug/libgarnet_rs.a $(cabal list-bin . | sed -e 's=x/garnet/build/garnet/garnet=build=g')
|
|
||||||
|
BUNDLED_LIB_DIR=$(cabal list-bin . | sed -e 's=x/garnet/build/garnet/garnet=build=g')
|
||||||
|
mkdir -p $BUNDLED_LIB_DIR
|
||||||
|
ln -sf $(pwd)/rust/target/debug/libgarnet_rs.a $BUNDLED_LIB_DIR
|
||||||
|
|
||||||
cabal build
|
cabal build
|
||||||
|
|||||||
@ -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: 94d74d3f3e72c8fabc85700f916387fe851ba20a
|
tag: 6ca94188abd756a1fb4dd8a4037de3fa7dca0765
|
||||||
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: eM0CJj1HDAClvjkv5QUaF7aZoMwnPm4GuoLTkp8SHq8=
|
--sha256: M+8tEZA8gsEc6gXnNdSbRpMBQ5LkH7sphcV1aR0fclA=
|
||||||
source-repository-package
|
source-repository-package
|
||||||
type: git
|
type: git
|
||||||
location: https://github.com/well-typed/libclang
|
location: https://github.com/well-typed/libclang
|
||||||
|
|||||||
@ -15,6 +15,7 @@ module GarnetRs.Raw where
|
|||||||
-- {-# LANGUAGE ExplicitLevelImports #-}
|
-- {-# LANGUAGE ExplicitLevelImports #-}
|
||||||
-- import HsBindgen.Runtime.LibC qualified
|
-- import HsBindgen.Runtime.LibC qualified
|
||||||
-- import splice Data.List
|
-- import splice Data.List
|
||||||
|
-- import splice Data.Text qualified as T
|
||||||
-- import splice Data.Tuple.Extra
|
-- import splice Data.Tuple.Extra
|
||||||
-- import splice HsBindgen.TH
|
-- import splice HsBindgen.TH
|
||||||
-- import splice Language.Haskell.TH
|
-- import splice Language.Haskell.TH
|
||||||
|
|||||||
@ -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_anon0_circle $ Raw.Circle_Body r
|
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_anon0_rectangle $ Raw.Rectangle_Body w h
|
Rectangle w h -> Raw.Shape Raw.Rectangle $ Raw.set_shape_body_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_anon0_leaf $ Raw.Leaf_Body v
|
Leaf v -> pure $ Raw.BTreeC Raw.Leaf $ Raw.set_bTreeC_body_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_anon0_fork $
|
pure . Raw.BTreeC Raw.Fork . Raw.set_bTreeC_body_fork $
|
||||||
Raw.Fork_Body (unsafeFromPtr lPtr) (unsafeFromPtr rPtr)
|
Raw.Fork_Body (unsafeFromPtr lPtr) (unsafeFromPtr rPtr)
|
||||||
|
|
||||||
hello :: ByteString -> IO ()
|
hello :: ByteString -> IO ()
|
||||||
|
|||||||
@ -1,19 +1,43 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||||
let profile = env::var("PROFILE").unwrap();
|
let profile = env::var("PROFILE").unwrap();
|
||||||
cbindgen::Builder::new()
|
|
||||||
|
let bindings = cbindgen::Builder::new()
|
||||||
.with_crate(&crate_dir)
|
.with_crate(&crate_dir)
|
||||||
.with_language(cbindgen::Language::C)
|
.with_language(cbindgen::Language::C)
|
||||||
.with_style(cbindgen::Style::Tag)
|
.with_style(cbindgen::Style::Tag)
|
||||||
.generate()
|
.generate()
|
||||||
.expect("Unable to generate bindings")
|
.expect("Unable to generate bindings");
|
||||||
.write_to_file(
|
|
||||||
|
// 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)
|
PathBuf::from(&crate_dir)
|
||||||
.join("target")
|
.join("target")
|
||||||
.join(&profile)
|
.join(&profile)
|
||||||
.join("garnet_rs.h"),
|
.join("garnet_rs.h"),
|
||||||
);
|
patched,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user