on master help sign in
Update cabal/nix build code for bench-report
5953313Harendra Kumar
benchmark/README.md+7
@@ -85,6 +85,13 @@ report from the results using the `bench-show` package. Try `bench.sh
85
85
86## bench.sh: Quick start
86## bench.sh: Quick start
87
87
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+
88Run the default benchmark suites:
95Run the default benchmark suites:
89
96
90```
97```
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 }:
1+{
2−
2+ nixpkgs ?
3−let
3+ # nixpkgs 21.05 needs a revised version of bench-show and we do not
4−
4+ # know how to use a revised version in nix.
5− inherit (nixpkgs) pkgs;
5+ #import (builtins.fetchTarball https://github.com/NixOS/nixpkgs/archive/refs/tags/21.05.tar.gz)
6−
6+ import (builtins.fetchTarball https://github.com/composewell/nixpkgs/archive/01dd2b4e738.tar.gz)
7− f = { mkDerivation, base, bench-show, stdenv, transformers }:
7+ {}
8− mkDerivation {
8+#, compiler ? "ghc884" # For nix 21.05
9− pname = "bench-report";
9+, compiler ? "default"
10− version = "0.0.0";
10+}:
11− src = ./.;
11+let haskellPackages =
12− isLibrary = false;
12+ if compiler == "default"
13− isExecutable = true;
13+ then nixpkgs.haskellPackages
14− executableHaskellDepends = [ base bench-show transformers ];
14+ else nixpkgs.haskell.packages.${compiler};
15− description = "Benchmark report generation";
15+
16− license = "unknown";
16+ mkPackage = super: pkg: path: opts: inShell:
17− hydraPlatforms = stdenv.lib.platforms.none;
17+ let orig = super.callCabal2nixWithOptions pkg path opts {};
18− };
18+ in if inShell
19−
19+ # Avoid copying the source directory to nix store by using
20− haskellPackages = if compiler == "default"
20+ # src = null.
21− then pkgs.haskellPackages
21+ then orig.overrideAttrs (oldAttrs: { src = null; })
22− else pkgs.haskell.packages.${compiler};
22+ else orig;
23−
23+
24− variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;
24+ mkHaskellPackages = inShell:
25−
25+ haskellPackages.override {
26− drv = variant (haskellPackages.callPackage f {});
26+ overrides = self: super:
27−
27+ with nixpkgs.haskell.lib;
28−in
28+ {
29−
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+ };
30− if pkgs.lib.inNixShell then drv.env else drv
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 () {
21 echo " [--quick]"
21 echo " [--quick]"
22 echo " [--raw]"
22 echo " [--raw]"
23 echo " [--dev-build]"
23 echo " [--dev-build]"
24+ echo " [--use-nix]"
24 echo " [--with-compiler <compiler exe name>]"
25 echo " [--with-compiler <compiler exe name>]"
25 echo " [--cabal-build-options <options>]"
26 echo " [--cabal-build-options <options>]"
26 echo " [--rtsopts <opts>]"
27 echo " [--rtsopts <opts>]"
@@ -68,28 +69,13 @@ list_comparisons () {
68 echo
69 echo
69}
70}
70
71
71−# chart is expensive to build and usually not required to be rebuilt,
72+# chart is expensive to build and usually not required to be rebuilt
72−# use master branch as fallback
73cabal_which_report() {
73cabal_which_report() {
74− local path=$(cabal_which bench-report x $1)
74+ local path="./bin/$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"
75+ if test -e "$path"
80 then
76 then
81− local path2="./bin/$1"
77+ echo $path
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
89 fi
78 fi
90− else
91− echo $path
92− fi
93}
79}
94
80
95find_report_prog() {
81find_report_prog() {
@@ -113,8 +99,16 @@ build_report_prog() {
113 then
99 then
114 echo "Building bench-report executables"
100 echo "Building bench-report executables"
115 BUILD_ONCE=1
101 BUILD_ONCE=1
102+ pushd benchmark/bench-report
103+ local cmd
116− $CABAL_EXECUTABLE v2-build bench-report --project-file=benchmark/bench-report/cabal.project \
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
117− || die "bench-report build failed"
109+ nix-shell --run "$cmd" || die "bench-report build failed"
110+ fi
111+ popd
118
112
119 elif test ! -x "$prog_path"
113 elif test ! -x "$prog_path"
120 then
114 then
@@ -308,6 +302,7 @@ cd $SCRIPT_DIR/..
308
302
309USE_GAUGE=0
303USE_GAUGE=0
310USE_GIT_CABAL=1
304USE_GIT_CABAL=1
305+USE_NIX=0
311set_common_vars
306set_common_vars
312
307
313DEFAULT_FIELDS="allocated bytescopied cputime"
308DEFAULT_FIELDS="allocated bytescopied cputime"
@@ -360,6 +355,7 @@ do
360 --graphs) GRAPH=1; shift ;;
355 --graphs) GRAPH=1; shift ;;
361 --no-measure) MEASURE=0; shift ;;
356 --no-measure) MEASURE=0; shift ;;
362 --dev-build) RUNNING_DEVBUILD=1; shift ;;
357 --dev-build) RUNNING_DEVBUILD=1; shift ;;
358+ --use-nix) USE_NIX=1; shift ;;
363 --use-gauge) USE_GAUGE=1; shift ;;
359 --use-gauge) USE_GAUGE=1; shift ;;
364 --) shift; break ;;
360 --) shift; break ;;
365 *) echo "Unknown flags: $*"; echo; print_help ;;
361 *) echo "Unknown flags: $*"; echo; print_help ;;