Compare commits

..

21 Commits

Author SHA1 Message Date
George Thomas
3235165797 debug wip 2026-04-14 01:44:18 +01:00
George Thomas
7a07808115 bump to hs-bindgen and libclang to latest...
had hoped this might solve the weird field naming but alas - should just report issue
2026-04-14 01:44:18 +01:00
George Thomas
23f732cabf file dependency reload stuff 2026-04-14 01:44:18 +01:00
George Thomas
7105ad0fd5 basic enum example 2026-04-14 01:44:18 +01:00
George Thomas
4f57e96071 Use lambdas in all wrappers for consistency
This is partly with a view to eventually abstracting away much of the boilerplate.
2026-04-14 01:44:18 +01:00
George Thomas
8f7a1c31f3 Add maybe/optional example 2026-04-14 01:44:18 +01:00
George Thomas
6ec7bc004f Add vector/slice example 2026-04-14 01:44:18 +01:00
George Thomas
97e2fd8823 Remove unnecessary Rust unit return type annotations 2026-04-14 01:44:18 +01:00
George Thomas
09ca0541ca Pass all non-primitive types by (immutable) reference 2026-04-14 01:44:18 +01:00
George Thomas
c3ac431600 Deduplicate base dependency 2026-04-14 01:44:18 +01:00
George Thomas
a69c1a0031 Get Rust Analyzer from overlay instead of directly from Nixpkgs
Right now, the latter invokes `cargo metadata --lockfile-path`,
which this Cargo nightly doesn't support.
2026-04-14 01:44:18 +01:00
George Thomas
2d0b7f26e0 Reformat 2026-04-14 01:44:18 +01:00
George Thomas
0771074981 Remove unnecessary library linking 2026-04-14 01:44:18 +01:00
George Thomas
40f62bf808 Specify include directories via environment variable 2026-04-14 01:44:18 +01:00
George Thomas
358b55c6e1 Minor refactor to avoid long line 2026-04-14 01:43:52 +01:00
George Thomas
c1308094f1 Combine overrides 2026-04-14 01:43:52 +01:00
George Thomas
325cb98b76 Inline project Nix file 2026-04-14 01:43:52 +01:00
George Thomas
9452f9f95a Remove unused binding 2026-04-14 01:41:48 +01:00
George Thomas
4fb40e2ed4 Simplify build script
Seeing as we now no longer need to modify generated header files.
2026-04-14 01:41:48 +01:00
George Thomas
3395fe3b1c Bump hs-bindgen to avoid header patching hack 2026-04-14 01:41:48 +01:00
George Thomas
a35380b3e9 stuff from Yuri
things I've changed from the PR:
- dropped legacy (i.e. non-flake) compat stuff, which turns out to account for most of the diff
- dropped `packages.garnet` since it doesn't work with `nix build .#garnet`
- back to using Rust-extended packages everywhere, which _seems_ fine
the rest is just re-inlining things and other refactors

final question:
it does seems a bit weird that `garnet-rs` arg to `project.nix` was always the same
might be a mistake, and we're supposed to be using local for local build?

"improve nix-haskell use"

there are a few things going on here but the main ones are ...
note that changes we keep are essentially:
- bumping `nix-haskell` to avoid shell hook workaround
- various changes in how we call `nix-haskell`
- using `libCgarnet_rs` name, which Cabal expects
- adding proper non-dev-shell targets, so that e.g. `nix run` works
2026-04-14 01:41:48 +01:00
4 changed files with 25 additions and 13 deletions

2
build
View File

@ -1,6 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
# generate this file from Nix config for now to avoid duplication?
cargo build --manifest-path ./rust/Cargo.toml cargo build --manifest-path ./rust/Cargo.toml
BUNDLED_LIB_DIR=$(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')

13
flake.lock generated
View File

@ -527,16 +527,15 @@
"hs-bindgen-src": { "hs-bindgen-src": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1774599157, "lastModified": 1776078838,
"narHash": "sha256-jgV67xhWzxMwyiyy5RPtu+VQvGTt+FoMXCWJcZ7lczY=", "narHash": "sha256-f8SE6IuACy8bzIX+EOYTpekaAI/TOQ3zTwJKJmHl3LY=",
"owner": "well-typed", "owner": "well-typed",
"repo": "hs-bindgen", "repo": "hs-bindgen",
"rev": "3c4af10590d0d09e825a9735e9a03d7f60914e21", "rev": "ca714aca1ed941271ac248488c9a469554c5b470",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "well-typed", "owner": "well-typed",
"ref": "release-0.1-alpha2",
"repo": "hs-bindgen", "repo": "hs-bindgen",
"type": "github" "type": "github"
} }
@ -561,11 +560,11 @@
"libclang-src": { "libclang-src": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1774600891, "lastModified": 1775645278,
"narHash": "sha256-LTAyNMY4Vu0vPeEq2wXB0KWY4kGtqtHTRmADjLdkv78=", "narHash": "sha256-JWARcbqH432vWcCvQ2bagTXBka8sCRNAnK1qOmnLWKw=",
"owner": "well-typed", "owner": "well-typed",
"repo": "libclang", "repo": "libclang",
"rev": "1054474fae403bfb52c7919680cac03d3d3d4237", "rev": "bf574efcb492d2738d8a82b6ce556f840ff92778",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -3,7 +3,7 @@
nix-haskell.url = "github:reflex-frp/nix-haskell"; nix-haskell.url = "github:reflex-frp/nix-haskell";
nixpkgs.follows = "nix-haskell/nixpkgs"; nixpkgs.follows = "nix-haskell/nixpkgs";
hls-src = { url = "github:haskell/haskell-language-server/2.13.0.0"; flake = false; }; hls-src = { url = "github:haskell/haskell-language-server/2.13.0.0"; flake = false; };
hs-bindgen-src = { url = "github:well-typed/hs-bindgen/release-0.1-alpha2"; flake = false; }; hs-bindgen-src = { url = "github:well-typed/hs-bindgen"; flake = false; };
libclang-src = { url = "github:well-typed/libclang"; flake = false; }; libclang-src = { url = "github:well-typed/libclang"; flake = false; };
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
crane.url = "github:ipetkov/crane"; crane.url = "github:ipetkov/crane";
@ -16,7 +16,7 @@
inputs: inputs:
inputs.flake-utils.lib.eachSystem [ "x86_64-linux" ] (system: inputs.flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
let let
pkgs = (import inputs.nixpkgs { inherit system; }).extend (import inputs.rust-overlay); pkgs = haskell.nixpkgs.extend (import inputs.rust-overlay);
crane = (inputs.crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.selectLatestNightlyWith ( crane = (inputs.crane.mkLib pkgs).overrideToolchain (p: p.rust-bin.selectLatestNightlyWith (
toolchain: toolchain.default.override { toolchain: toolchain.default.override {
extensions = [ "rust-src" "rust-analyzer" ]; extensions = [ "rust-src" "rust-analyzer" ];
@ -27,7 +27,7 @@
'' ''
export C_INCLUDE_PATH="${pkgs.stdenv.cc.libc.dev}/include''${C_INCLUDE_PATH:+:$C_INCLUDE_PATH}" export C_INCLUDE_PATH="${pkgs.stdenv.cc.libc.dev}/include''${C_INCLUDE_PATH:+:$C_INCLUDE_PATH}"
''; '';
project = (import inputs.nix-haskell { inherit system inputs; } { haskell = (import inputs.nix-haskell { inherit system inputs; } {
name = "garnet"; name = "garnet";
src = ./.; src = ./.;
compiler-nix-name = "ghc914"; compiler-nix-name = "ghc914";
@ -49,6 +49,7 @@
}; };
packages.garnet.components.library = { packages.garnet.components.library = {
preBuild = addLibcIncludeDir; preBuild = addLibcIncludeDir;
# try removing?
preConfigure = '' preConfigure = ''
mkdir -p rust/target/debug mkdir -p rust/target/debug
ln -s ${garnet-rs}/include/garnet_rs.h rust/target/debug/garnet_rs.h ln -s ${garnet-rs}/include/garnet_rs.h rust/target/debug/garnet_rs.h
@ -76,7 +77,7 @@
withHaddock = true; withHaddock = true;
shellHook = addLibcIncludeDir; shellHook = addLibcIncludeDir;
}; };
}).project.haskell-nix; });
garnet-rs = crane.buildPackage { garnet-rs = crane.buildPackage {
src = crane.cleanCargoSource ./rust; src = crane.cleanCargoSource ./rust;
doCheck = false; doCheck = false;
@ -89,14 +90,14 @@
in in
rec { rec {
defaultPackage = packages.garnet-exe; defaultPackage = packages.garnet-exe;
packages = let garnet = project.hsPkgs.garnet; in { packages = let garnet = haskell.project.haskell-nix.hsPkgs.garnet; in {
inherit garnet-rs; inherit garnet-rs;
garnet-exe = garnet.components.exes.garnet; garnet-exe = garnet.components.exes.garnet;
garnet-lib = garnet.components.library; garnet-lib = garnet.components.library;
}; };
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
inputsFrom = [ inputsFrom = [
project.shell haskell.project.haskell-nix.shell
(crane.devShell { }) (crane.devShell { })
]; ];
packages = with pkgs; [ packages = with pkgs; [

View File

@ -14,6 +14,14 @@ extra-source-files:
-- extra-tmp-files: -- extra-tmp-files:
-- rust/target/debug/garnet_rs.h -- rust/target/debug/garnet_rs.h
-- actually maybe this is pointless given we always need debug path anyway in `extra-source-files`
-- plus we have it in `Raw.hs`
flag dev
default:
False
manual:
True
common common common common
default-language: GHC2024 default-language: GHC2024
default-extensions: default-extensions:
@ -50,6 +58,8 @@ library
GarnetRs.Raw GarnetRs.Raw
GarnetRs.Wrapped GarnetRs.Wrapped
hs-source-dirs: lib hs-source-dirs: lib
-- if flag (dev)
-- include-dirs: rust/target/debug
include-dirs: rust/target/debug include-dirs: rust/target/debug
-- HLS gives up entirely when the header is malformed if we do this -- HLS gives up entirely when the header is malformed if we do this
-- and anyway, I don't think it gives us dependency tracking like `extra-source-files` does -- and anyway, I don't think it gives us dependency tracking like `extra-source-files` does