46 Commits

Author SHA1 Message Date
George Thomas
e70aac0f1b use upstream fix to avoid header patching hack 2026-03-19 11:54:09 +00:00
George Thomas
cdada4c9be symlink (plus messy comments) 2026-03-19 11:35:00 +00:00
George Thomas
c37b013467 Revert "ditch bash script for custom setup"
This reverts commit 1399946c4d582eaabb64cece292a48159b745e64.
2026-03-19 11:35:00 +00:00
George Thomas
22b6fac5b5 ditch bash script for custom setup
eugh, but this requires
"haskell.sessionLoading": "singleComponent"
2026-03-19 11:35:00 +00:00
George Thomas
927bf229a4 move bindings generation to Rust build script
bit cleaner, esp. as less hardcoding of "debug" path

instant updates all the way through to Haskell when we change Rust code
(this wasn't actually working at all before even when we did manually run the script, because TH file-dependency tracking seemed to get confused with the way that the Bash code moved a file to the header path rather than editing it)

should update to point to my comment on hs-bindgen

actually, isn't there a race condition here? the header files are generated before the new Rust code is actually compiled, and Cabal could in theory end up still linking against the old output

hardcoding "target" isn't great, though we do already do so in the Cabal file
there seems to be no env var for it though
docs suggest we're supposed to use OUT_DIR, but that has an unpredictable path... we could output the dir somewhere I suppose, and configure Cabal to use that, but that adds a fair bit of complexity

look in to https://doc.rust-lang.org/cargo/reference/build-scripts.html#change-detection?
bit blunt compared to e.g. Cabal Hooks, and anyway I think in the long run I'll be ditching `build.rs`, as discussed above
2026-03-19 11:35:00 +00:00
George Thomas
beb9e14542 drop hooks in favour of using bundled libraries properly
script addition is hacky, but I know no other way to get most of the build path, in arch/version-independent way
we'll use a custom setup or whatever eventually (_eventually_ hooks...) anyway
2026-03-19 11:35:00 +00:00
George Thomas
ffc59a418b remove cabal configure hack for lib/include dirs 2026-03-19 11:35:00 +00:00
George Thomas
718554cb2e Bump hs-bindgen for record-dot support 2026-03-19 11:34:50 +00:00
George Thomas
a018cc389a Generate header in Rust build output directory 2026-02-20 09:53:12 +00:00
George Thomas
96ec5c1cb1 Switch to Template Haskell mode for hs-bindgen 2026-02-20 09:08:16 +00:00
George Thomas
20b47594c6 Avoid IO for tree sum 2026-02-19 21:35:35 +00:00
George Thomas
71e4ffaede Make Rust tree type polymorphic 2026-02-19 21:28:00 +00:00
George Thomas
58005ee261 Refactor to use continuation monad 2026-02-19 21:18:37 +00:00
George Thomas
ca063b1dd6 Rename tree types 2026-02-19 21:11:58 +00:00
George Thomas
261acca8a4 Define nicer Rust tree type and coerce 2026-02-19 21:11:23 +00:00
George Thomas
55a781eeb8 Add tree example 2026-02-19 20:44:04 +00:00
George Thomas
06767e17ea Add newline for consistency 2026-02-19 19:37:46 +00:00
George Thomas
2a80e5b219 Minor simplification 2026-02-19 17:22:15 +00:00
George Thomas
e977181252 Avoid typedefs
This makes the header simpler, and silences `hs-bindgen` notices about "squashed" typedefs.
2026-02-19 17:22:15 +00:00
George Thomas
9ca4f615d8 Use simpler tagged union translation
Avoids the worst part of the header hack, and makes Haskell wrapper simpler.
2026-02-19 17:22:15 +00:00
George Thomas
5019af701f Mark pure function 2026-02-19 17:22:15 +00:00
George Thomas
5907a064a7 Use fixed-width integers
Even though `Int` and `isize` should be the same in practice, we can't cleanly convert, as the type information isn't quite there. And anyway, strictly speaking per the report, `Int` is only guaranteed to hold 30 bits.

Note that this is essentially unchanged even if we specify `usize_is_size_t = true` for `cbindgen`.
2026-02-19 17:19:28 +00:00
George Thomas
024b6aec87 Implement function with return value 2026-02-19 16:29:52 +00:00
George Thomas
40bb939302 Stick to Rust debug builds in shell to avoid C lib dir confusion 2026-02-19 16:29:52 +00:00
George Thomas
ddc8b9097d Avoid absolute path hack 2026-02-19 16:29:52 +00:00
George Thomas
25875c7dc1 Move Haskell package to top level 2026-02-19 16:29:52 +00:00
George Thomas
2bab0ff94e Rename Haskell.nix flake input 2026-02-19 16:29:52 +00:00
George Thomas
7d90990b74 Bump flake inputs 2026-02-19 16:29:52 +00:00
George Thomas
56370bb8a4 Reformat 2026-02-19 16:29:52 +00:00
George Thomas
b9e2e59174 Refactor Nix flake inputs 2026-02-19 16:29:52 +00:00
George Thomas
97a4f1c359 Disable dead code warning for whole Rust file 2026-02-19 16:29:52 +00:00
George Thomas
d8c12b5418 Call struct function with different arguments 2026-02-19 16:29:52 +00:00
George Thomas
0e54cccd74 Create manual high level wrapper 2026-02-19 16:29:52 +00:00
George Thomas
f1ec06fcca Add Bash script dependencies to Nix shell 2026-02-19 16:29:52 +00:00
George Thomas
13b9324bc4 Simplify use sites by passing by value 2026-02-19 16:29:52 +00:00
George Thomas
5f1e49c4ce Use ByteString 2026-02-19 16:29:52 +00:00
George Thomas
7e09c1d681 Add more complex data types 2026-02-19 16:29:52 +00:00
George Thomas
0a1911862f Expose explicit C interface
We drop the tools specifically designed for Haskell and Rust together, in favour of general tools for using each with C.

Namely, we use Mozilla's `cbindgen` for generating header files from the Rust source, and Well-Typed's new `hs-bindgen` tool for generating Haskell from those header files.

The Rust code here is essentially the result of expanding the old macro, then inlining and renaming internals.

The most important thing here is that we're now relying solely on robust well-maintained tools.
2026-02-19 16:29:41 +00:00
George Thomas
60f5f23b2d Move Haskell executable in to subdirectory 2026-02-19 13:57:14 +00:00
George Thomas
400960b0be Remove empty other-modules 2026-02-19 13:57:14 +00:00
George Thomas
7bb41f6825 Call Rust from Haskell with cargo-cabal and hs-bindgen
See https://sraka.xyz/posts/hs-bindgen-introduction.html.

For now, this is a shell-based workflow, rather than using Nix to build everything, i.e. `nix develop` works but `nix build` doesn't. And `cargo build` has to be called manually to create the C library, rather than `cabal` being clever enough to invoke it itself.

We ran `cargo cabal init` from the `rust` directory (`nix shell github:yvan-sraka/cargo-cabal`), which generated `hsbindgen.toml` (which we use), and `Setup.lhs` (which just added `extra-lib-dirs`, and with the wrong paths, so we dspecify those statically instead in `garnet.cabal`). We also follow its advice to use `staticlib`.

Also, after we ran the first `cargo build` (requiring a `mkdir rust/src` before it would run), we took the generated the Haskell file, and moved the main contents in to `Main.hs` manually.
2026-02-19 13:57:14 +00:00
George Thomas
ff8826d758 Fix authorship info 2026-02-19 13:57:14 +00:00
George Thomas
4ed5c5e1ae Simplify .gitignore 2026-02-19 13:57:14 +00:00
George Thomas
f664efc0e2 Remove stray Git submodule config 2026-02-19 13:56:00 +00:00
George Thomas
2640c75baf Format Nix file 2026-02-18 14:31:54 +00:00
39283930d5 Initial 2026-02-17 14:57:34 +00:00