commit cd04db7d5a1fcd1e36c881c139b3bd3fbb5ca17e
parent 37a70b4eec5647a51a9b27f92bf539f772140b6c
Author: Jared Tobin <jared@jtobin.io>
Date: Wed, 4 Nov 2026 21:14:36 +0400
nix, cabal: build with LLVM
Adds a manual llvm flag, as in the ppad libraries, compiling the
library with -fllvm -O2 and the benchmarks with -fllvm. The flake
builds ppad-sha256 and ppad-base16 with their llvm flags, and puts cc,
llvm, and clang in the dev shell.
Diffstat:
2 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/flake.nix b/flake.nix
@@ -31,18 +31,33 @@
let
lib = "mssmt";
- pkgs = import nixpkgs { inherit system; };
- hlib = pkgs.haskell.lib;
+ pkgs = import nixpkgs { inherit system; };
+ hlib = pkgs.haskell.lib;
+ llvm = pkgs.llvmPackages_19.llvm;
+ clang = pkgs.llvmPackages_19.clang;
+
+ base16 = ppad-base16.packages.${system}.default;
+ base16-llvm =
+ hlib.addBuildTools
+ (hlib.enableCabalFlag base16 "llvm")
+ [ llvm clang ];
+
+ sha256 = ppad-sha256.packages.${system}.default;
+ sha256-llvm =
+ hlib.addBuildTools
+ (hlib.enableCabalFlag sha256 "llvm")
+ [ llvm clang ];
hpkgs = pkgs.haskell.packages.ghc910.extend (new: old: {
- ppad-base16 = ppad-base16.packages.${system}.default;
- ppad-sha256 = ppad-sha256.packages.${system}.default;
+ ppad-base16 = base16-llvm;
+ ppad-sha256 = sha256-llvm;
${lib} = new.callCabal2nix lib ./. {
ppad-base16 = new.ppad-base16;
ppad-sha256 = new.ppad-sha256;
};
});
+ cc = pkgs.stdenv.cc;
ghc = hpkgs.ghc;
cabal = hpkgs.cabal-install;
in
@@ -56,6 +71,9 @@
buildInputs = [
cabal
+ cc
+ llvm
+ clang
];
doBenchmark = true;
@@ -63,8 +81,10 @@
shellHook = ''
PS1="[${lib}] \w$ "
echo "entering ${system} shell, using"
+ echo "cc: $(${cc}/bin/cc --version)"
echo "ghc: $(${ghc}/bin/ghc --version)"
echo "cabal: $(${cabal}/bin/cabal --version)"
+ echo "llc: $(${llvm}/bin/llc --version | head -2 | tail -1)"
'';
};
}
diff --git a/mssmt.cabal b/mssmt.cabal
@@ -18,11 +18,18 @@ description:
A merkle-sum sparse merkle tree (MS-SMT), after the construction used
by Taproot Assets.
+flag llvm
+ description: Use GHC's LLVM backend.
+ default: False
+ manual: True
+
library
default-language: Haskell2010
hs-source-dirs: lib
ghc-options:
-Wall
+ if flag(llvm)
+ ghc-options: -fllvm -O2
exposed-modules:
Data.MSSMT
, Data.MSSMT.Aggregate
@@ -69,6 +76,8 @@ benchmark mssmt-bench
ghc-options:
-rtsopts -O2 -Wall
+ if flag(llvm)
+ ghc-options: -fllvm
build-depends:
base
@@ -88,6 +97,8 @@ benchmark mssmt-weigh
ghc-options:
-rtsopts -O2 -Wall
+ if flag(llvm)
+ ghc-options: -fllvm
build-depends:
base