on master help sign in
Update cabal/nix build code for bench-report
commit595331343abec4bbcc3ab00af54257268870b5bc authorHarendra Kumar <harendra@composewell.com> dateThu 17 Jun 2021, 13:58 (5 years ago) parent8fd51b2
4 files changed+75−52
benchmark/README.md+7 benchmark/bench-report/cabal.project+1−1 benchmark/bench-report/default.nix+50−30 bin/bench.sh+17−21
benchmark/README.md+7
@@ -85,6 +85,13 @@ report from the results using the `bench-show` package. Try `bench.sh
8585
8686## bench.sh: Quick start
8787
88+IMPORTANT NOTE: If you are using nix then you can use `--use-nix`
89+flag so that the `bench-report` executable is built using nix. That
90+can save a lot of time compiling it. However, once it is built it
91+will be cached in the `bin` directory of the repo and used from there
92+every time. You can also build it manually from the cabal file in
93+`benchmark/bench-report` and install it in the `bin` directory.
94+
8895Run the default benchmark suites:
8996
9097```
benchmark/bench-report/cabal.project+1−1
@@ -1 +1 @@
1−packages: benchmark/bench-report/bench-report.cabal
1+packages: .
benchmark/bench-report/default.nix+50−30
@@ -1,30 +1,50 @@
1−{ nixpkgs ? import <nixpkgs> {}, compiler ? "default", doBenchmark ? false }:
2−
3−let
4−
5− inherit (nixpkgs) pkgs;
6−
7− f = { mkDerivation, base, bench-show, stdenv, transformers }:
8− mkDerivation {
9− pname = "bench-report";
10− version = "0.0.0";
11− src = ./.;
12− isLibrary = false;
13− isExecutable = true;
14− executableHaskellDepends = [ base bench-show transformers ];
15− description = "Benchmark report generation";
16− license = "unknown";
17− hydraPlatforms = stdenv.lib.platforms.none;
18− };
19−
20− haskellPackages = if compiler == "default"
21− then pkgs.haskellPackages
22− else pkgs.haskell.packages.${compiler};
23−
24− variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;
25−
26− drv = variant (haskellPackages.callPackage f {});
27−
28−in
29−
30− if pkgs.lib.inNixShell then drv.env else drv
1+{
2+ nixpkgs ?
3+ # nixpkgs 21.05 needs a revised version of bench-show and we do not
4+ # know how to use a revised version in nix.
5+ #import (builtins.fetchTarball https://github.com/NixOS/nixpkgs/archive/refs/tags/21.05.tar.gz)
6+ import (builtins.fetchTarball https://github.com/composewell/nixpkgs/archive/01dd2b4e738.tar.gz)
7+ {}
8+#, compiler ? "ghc884" # For nix 21.05
9+, compiler ? "default"
10+}:
11+let haskellPackages =
12+ if compiler == "default"
13+ then nixpkgs.haskellPackages
14+ else nixpkgs.haskell.packages.${compiler};
15+
16+ mkPackage = super: pkg: path: opts: inShell:
17+ let orig = super.callCabal2nixWithOptions pkg path opts {};
18+ in if inShell
19+ # Avoid copying the source directory to nix store by using
20+ # src = null.
21+ then orig.overrideAttrs (oldAttrs: { src = null; })
22+ else orig;
23+
24+ mkHaskellPackages = inShell:
25+ haskellPackages.override {
26+ overrides = self: super:
27+ with nixpkgs.haskell.lib;
28+ {
29+ bench-report = mkPackage super "bench-report" ./. "" inShell;
30+ };
31+ };
32+
33+ drv = mkHaskellPackages true;
34+
35+ shell = drv.shellFor {
36+ packages = p:
37+ [ p.bench-report
38+ ];
39+ # Use a better prompt
40+ shellHook = ''
41+ export CABAL_DIR="$(pwd)/.cabal.nix"
42+ if test -n "$PS_SHELL"
43+ then
44+ export PS1="$PS_SHELL\[$bldred\](nix)\[$txtrst\] "
45+ fi
46+ '';
47+ };
48+in if nixpkgs.lib.inNixShell
49+ then shell
50+ else (mkHaskellPackages false).streamly
bin/bench.sh+17−21
@@ -21,6 +21,7 @@ print_help () {
2121 echo " [--quick]"
2222 echo " [--raw]"
2323 echo " [--dev-build]"
24+ echo " [--use-nix]"
2425 echo " [--with-compiler <compiler exe name>]"
2526 echo " [--cabal-build-options <options>]"
2627 echo " [--rtsopts <opts>]"
@@ -68,28 +69,13 @@ list_comparisons () {
6869 echo
6970}
7071
71−# chart is expensive to build and usually not required to be rebuilt,
72−# use master branch as fallback
72+# chart is expensive to build and usually not required to be rebuilt
7373cabal_which_report() {
74− local path=$(cabal_which bench-report x $1)
75− if test -z "$path"
76− then
77− echo "Cannot find $1 executable, trying in dist-newstyle" 1>&2
78− local path1=$(cabal_which_builddir dist-newstyle bench-report x $1)
79− if test -z "$path1"
74+ local path="./bin/$1"
75+ if test -e "$path"
8076 then
81− local path2="./bin/$1"
82− echo "Cannot find $1 executable, trying $path2" 1>&2
83− if test -e "$path2"
84− then
85− echo $path2
86− fi
87− else
88− echo $path1
77+ echo $path
8978 fi
90− else
91− echo $path
92− fi
9379}
9480
9581find_report_prog() {
@@ -113,8 +99,16 @@ build_report_prog() {
11399 then
114100 echo "Building bench-report executables"
115101 BUILD_ONCE=1
116− $CABAL_EXECUTABLE v2-build bench-report --project-file=benchmark/bench-report/cabal.project \
117− || die "bench-report build failed"
102+ pushd benchmark/bench-report
103+ local cmd
104+ cmd="$CABAL_EXECUTABLE install --installdir ../../bin bench-report"
105+ if test "$USE_NIX" -eq 0
106+ then
107+ $cmd || die "bench-report build failed"
108+ else
109+ nix-shell --run "$cmd" || die "bench-report build failed"
110+ fi
111+ popd
118112
119113 elif test ! -x "$prog_path"
120114 then
@@ -308,6 +302,7 @@ cd $SCRIPT_DIR/..
308302
309303USE_GAUGE=0
310304USE_GIT_CABAL=1
305+USE_NIX=0
311306set_common_vars
312307
313308DEFAULT_FIELDS="allocated bytescopied cputime"
@@ -360,6 +355,7 @@ do
360355 --graphs) GRAPH=1; shift ;;
361356 --no-measure) MEASURE=0; shift ;;
362357 --dev-build) RUNNING_DEVBUILD=1; shift ;;
358+ --use-nix) USE_NIX=1; shift ;;
363359 --use-gauge) USE_GAUGE=1; shift ;;
364360 --) shift; break ;;
365361 *) echo "Unknown flags: $*"; echo; print_help ;;