Compare commits

..

9 Commits
wip ... main

Author SHA1 Message Date
George Thomas
52f0a49d87 Fix build script to work correctly on clean checkout 2026-03-24 15:29:36 +00:00
George Thomas
df1f73eb8a Script the full build 2026-03-24 11:24:40 +00:00
George Thomas
6bb06b117f Symlink static lib instead of copying
This means we need to run the script much less often.
2026-03-24 11:24:40 +00:00
George Thomas
649c1b466f Revert "Ditch Bash script for custom setup"
This reverts commit 1f1c0d959da699ce04f7951ecbcdb7976c8c0750.

This doesn't work well with multi-component builds. For example, it requires `"haskell.sessionLoading": "singleComponent"` in VSCode, which makes HLS work less reliably.
2026-03-24 11:24:40 +00:00
George Thomas
b79a4c0804 Ditch Bash script for custom setup 2026-03-24 11:24:40 +00:00
George Thomas
b68d6257d3 Move bindings generation to Rust build script 2026-03-24 11:24:40 +00:00
George Thomas
b94e8ef11b Make staged imports consistent 2026-03-24 11:24:40 +00:00
George Thomas
4ecd0b16e2 Drop build hooks in favour of just using bundled libraries properly
The script addition is a bit hacky, but there's no obvious straightforward arch/version-independent way to get most of the build path. And eventually, once issues with HLS etc. are sorted out we will revert to using Cabal hooks anyway.
2026-03-23 23:06:29 +00:00
George Thomas
ddb9c300cf Switch to Hooks API instead of using cabal configure hack for lib/include dirs 2026-03-23 22:57:34 +00:00
5 changed files with 44 additions and 15 deletions

6
build
View File

@ -2,5 +2,9 @@
set -euo pipefail
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

View File

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

View File

@ -15,6 +15,7 @@ module GarnetRs.Raw where
-- {-# LANGUAGE ExplicitLevelImports #-}
-- import HsBindgen.Runtime.LibC qualified
-- import splice Data.List
-- import splice Data.Text qualified as T
-- import splice Data.Tuple.Extra
-- import splice HsBindgen.TH
-- import splice Language.Haskell.TH

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_anon0_circle $ Raw.Circle_Body r
Rectangle w h -> Raw.Shape Raw.Rectangle $ Raw.set_shape_anon0_rectangle $ Raw.Rectangle_Body w h
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
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_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
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_anon0_fork $
pure . Raw.BTreeC Raw.Fork . Raw.set_bTreeC_body_fork $
Raw.Fork_Body (unsafeFromPtr lPtr) (unsafeFromPtr rPtr)
hello :: ByteString -> IO ()

View File

@ -1,19 +1,43 @@
use std::env;
use std::fs;
use std::path::PathBuf;
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let profile = env::var("PROFILE").unwrap();
cbindgen::Builder::new()
let bindings = cbindgen::Builder::new()
.with_crate(&crate_dir)
.with_language(cbindgen::Language::C)
.with_style(cbindgen::Style::Tag)
.generate()
.expect("Unable to generate bindings")
.write_to_file(
PathBuf::from(&crate_dir)
.join("target")
.join(&profile)
.join("garnet_rs.h"),
);
.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,
)
.unwrap();
}