Update cabal/nix build code for bench-report

This commit is contained in:
Harendra Kumar 2021-06-17 13:58:20 +05:30
parent 8fd51b2a37
commit 595331343a
4 changed files with 71 additions and 48 deletions

View File

@ -85,6 +85,13 @@ report from the results using the `bench-show` package. Try `bench.sh
## bench.sh: Quick start
IMPORTANT NOTE: If you are using nix then you can use `--use-nix`
flag so that the `bench-report` executable is built using nix. That
can save a lot of time compiling it. However, once it is built it
will be cached in the `bin` directory of the repo and used from there
every time. You can also build it manually from the cabal file in
`benchmark/bench-report` and install it in the `bin` directory.
Run the default benchmark suites:
```

View File

@ -1 +1 @@
packages: benchmark/bench-report/bench-report.cabal
packages: .

View File

@ -1,30 +1,50 @@
{ nixpkgs ? import <nixpkgs> {}, compiler ? "default", doBenchmark ? false }:
{
nixpkgs ?
# nixpkgs 21.05 needs a revised version of bench-show and we do not
# know how to use a revised version in nix.
#import (builtins.fetchTarball https://github.com/NixOS/nixpkgs/archive/refs/tags/21.05.tar.gz)
import (builtins.fetchTarball https://github.com/composewell/nixpkgs/archive/01dd2b4e738.tar.gz)
{}
#, compiler ? "ghc884" # For nix 21.05
, compiler ? "default"
}:
let haskellPackages =
if compiler == "default"
then nixpkgs.haskellPackages
else nixpkgs.haskell.packages.${compiler};
let
mkPackage = super: pkg: path: opts: inShell:
let orig = super.callCabal2nixWithOptions pkg path opts {};
in if inShell
# Avoid copying the source directory to nix store by using
# src = null.
then orig.overrideAttrs (oldAttrs: { src = null; })
else orig;
inherit (nixpkgs) pkgs;
mkHaskellPackages = inShell:
haskellPackages.override {
overrides = self: super:
with nixpkgs.haskell.lib;
{
bench-report = mkPackage super "bench-report" ./. "" inShell;
};
};
f = { mkDerivation, base, bench-show, stdenv, transformers }:
mkDerivation {
pname = "bench-report";
version = "0.0.0";
src = ./.;
isLibrary = false;
isExecutable = true;
executableHaskellDepends = [ base bench-show transformers ];
description = "Benchmark report generation";
license = "unknown";
hydraPlatforms = stdenv.lib.platforms.none;
};
drv = mkHaskellPackages true;
haskellPackages = if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};
variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;
drv = variant (haskellPackages.callPackage f {});
in
if pkgs.lib.inNixShell then drv.env else drv
shell = drv.shellFor {
packages = p:
[ p.bench-report
];
# Use a better prompt
shellHook = ''
export CABAL_DIR="$(pwd)/.cabal.nix"
if test -n "$PS_SHELL"
then
export PS1="$PS_SHELL\[$bldred\](nix)\[$txtrst\] "
fi
'';
};
in if nixpkgs.lib.inNixShell
then shell
else (mkHaskellPackages false).streamly

View File

@ -21,6 +21,7 @@ print_help () {
echo " [--quick]"
echo " [--raw]"
echo " [--dev-build]"
echo " [--use-nix]"
echo " [--with-compiler <compiler exe name>]"
echo " [--cabal-build-options <options>]"
echo " [--rtsopts <opts>]"
@ -68,28 +69,13 @@ list_comparisons () {
echo
}
# chart is expensive to build and usually not required to be rebuilt,
# use master branch as fallback
# chart is expensive to build and usually not required to be rebuilt
cabal_which_report() {
local path=$(cabal_which bench-report x $1)
if test -z "$path"
then
echo "Cannot find $1 executable, trying in dist-newstyle" 1>&2
local path1=$(cabal_which_builddir dist-newstyle bench-report x $1)
if test -z "$path1"
local path="./bin/$1"
if test -e "$path"
then
local path2="./bin/$1"
echo "Cannot find $1 executable, trying $path2" 1>&2
if test -e "$path2"
then
echo $path2
fi
else
echo $path1
echo $path
fi
else
echo $path
fi
}
find_report_prog() {
@ -113,8 +99,16 @@ build_report_prog() {
then
echo "Building bench-report executables"
BUILD_ONCE=1
$CABAL_EXECUTABLE v2-build bench-report --project-file=benchmark/bench-report/cabal.project \
|| die "bench-report build failed"
pushd benchmark/bench-report
local cmd
cmd="$CABAL_EXECUTABLE install --installdir ../../bin bench-report"
if test "$USE_NIX" -eq 0
then
$cmd || die "bench-report build failed"
else
nix-shell --run "$cmd" || die "bench-report build failed"
fi
popd
elif test ! -x "$prog_path"
then
@ -308,6 +302,7 @@ cd $SCRIPT_DIR/..
USE_GAUGE=0
USE_GIT_CABAL=1
USE_NIX=0
set_common_vars
DEFAULT_FIELDS="allocated bytescopied cputime"
@ -360,6 +355,7 @@ do
--graphs) GRAPH=1; shift ;;
--no-measure) MEASURE=0; shift ;;
--dev-build) RUNNING_DEVBUILD=1; shift ;;
--use-nix) USE_NIX=1; shift ;;
--use-gauge) USE_GAUGE=1; shift ;;
--) shift; break ;;
*) echo "Unknown flags: $*"; echo; print_help ;;