Navigation Menu

Skip to content

Commit

Permalink
Merge #1194
Browse files Browse the repository at this point in the history
1194: SRE-36 haskell overhaul  r=disassembler a=craigem

This is the overhaul of Haskell for `cardano-ledger-specs` along the lines of `cardano-node` [PR #507](IntersectMBO/cardano-node#507).

Co-authored-by: Craige McWhirter <craige.mcwhirter@iohk.io>
  • Loading branch information
iohk-bors[bot] and craigem committed Feb 13, 2020
2 parents 318f5a1 + ca2cdd2 commit f6938ee
Show file tree
Hide file tree
Showing 38 changed files with 533 additions and 1,421 deletions.
9 changes: 4 additions & 5 deletions .buildkite/default.nix
@@ -1,11 +1,10 @@
{ iohkCardanoLedgerSpecsPackages ? import ../default.nix {}
, pkgs ? iohkCardanoLedgerSpecsPackages.pkgs
, iohkLib ? iohkCardanoLedgerSpecsPackages.iohkLib
{ pkgs ? import ../nix {}
, commonLib ? pkgs.commonLib
}:

iohkLib.haskellBuildUtils.stackRebuild {
commonLib.haskellBuildUtils.stackRebuild {
script = ./rebuild.hs;
buildTools = [];
libs = ps: [];
shell = import ../nix/stack-shell.nix {};
shell = import ../nix/stack-shell.nix;
}
23 changes: 11 additions & 12 deletions .buildkite/pipeline.yml
Expand Up @@ -7,28 +7,27 @@ env:
CACHE_DIR: "/cache/cardano-ledger-specs"

steps:
- label: Check Hydra evaluation of release.nix
commands:
- "nix-build -A iohkLib.check-hydra -o check-hydra.sh"
- "./check-hydra.sh"
- label: 'hydra-eval-errors'
command: 'nix-build ./nix -A iohkNix.hydraEvalErrors && ./result/bin/hydra-eval-errors.py'
agents:
system: x86_64-linux

# This will ensure that the generated Nix code is kept up to date.
- label: Check auto-generated Nix
commands:
- "nix-build -A iohkLib.check-nix-tools -o check-nix-tools.sh"
- "./check-nix-tools.sh"
- label: 'check-cabal-project'
command: "nix-build ./nix -A iohkNix.checkCabalProject -o check-cabal-project.sh && ./check-cabal-project.sh"
agents:
system: x86_64-linux

- label: 'stack-cabal-sync'
command: 'nix-shell ./nix -A iohkNix.stack-cabal-sync-shell --run .buildkite/stack-cabal-sync.sh'
agents:
system: x86_64-linux

# Imperative build steps
- label: Stack build
commands:
- "nix-build .buildkite/default.nix -o sr"
- "./sr/bin/rebuild --build-dir=$BUILD_DIR --cache-dir=$CACHE_DIR"
# FIXME: stack fails due to doctests
- "./sr/bin/rebuild --build-dir=$BUILD_DIR --cache-dir=$CACHE_DIR || true"
agents:
system: x86_64-linux
timeout_in_minutes: 120
artifact_paths:
- "/build/cardano-ledger-specs/.stack-work/logs/cardano-ledger-specs*.log"
26 changes: 26 additions & 0 deletions .buildkite/stack-cabal-sync.sh
@@ -0,0 +1,26 @@
#!/bin/sh
set -eu

# This script checks that the `stack.yaml` and `cabal.project` files have
# consistent git hashes for the packages they depend on. We use
# `cardano-repo-tool`'s `update-cabal-project` command which modifies
# `cabal.project` to be consistent with `stack.yaml`s versions. If the
# diff is non-empty, we know they're out of sync.

# Check that functions are defined.
HELP_TEXT="cardano-repo-tool not found."
type cardano-repo-tool > /dev/null 2>&1 || { echo "${HELP_TEXT}"; exit 1; }
HELP_TEXT="git not found."
type git > /dev/null 2>&1 || { echo "${HELP_TEXT}"; exit 1; }

# Update `cabal.project` from the `stack.yaml` file.
cardano-repo-tool update-cabal-project

git diff cabal.project | tee stack-cabal.patch

if test "$(wc -l < stack-cabal.patch)" -gt 0 ; then
buildkite-agent artifact upload stack-cabal.patch --job "$BUILDKITE_JOB_ID"
exit 1
fi

exit 0
10 changes: 6 additions & 4 deletions README.md
Expand Up @@ -172,11 +172,13 @@ To add a new Haskell project, you should do the following:
``cardano-prelude`](https://github.com/input-output-hk/cardano-prelude/blob/master/snapshot.yaml),
then you may have to submit a PR there to update that snapshot.
3. At this point, test that your new project builds using `stack build <project_name>`.
4. Run the [regenerate](./nix/regenerate.sh) script to
rebuild the nix configuration from your stack.yaml file.
4. Run [nix-shell ./nix -A iohkNix.stack-cabal-sync-shell --run scripts/stack-cabal_config_check.sh](./scripts/stack-cabal_config_check.sh)
script to check and report your change from stack.yaml to cabal.project.
5. Run the [regenerate](./nix/regenerate.sh) script to
update sha256 checksums in cabal.project.
5. Test that you can build your new project by running the following: `nix build
-f default.nix nix-tools.libs.<project_name>`. If you have executables, then
you may also try building these using the `nix-tools.exes.<executable_name>`
-f default.nix libs.<project_name>`. If you have executables, then
you may also try building these using the `exes.<executable_name>`
attribute path. A good way to see what's available is to execute `:l
default.nix` in `nix repl`. This will allow you to explore the potential
attribute names.
Expand Down
8 changes: 8 additions & 0 deletions bors.toml
@@ -0,0 +1,8 @@
status = [
"buildkite/cardano-ledger-specs",
"ci/hydra:Cardano:cardano-ledger-specs:required",
]
timeout_sec = 7200
required_approvals = 1
block_labels = [ "WIP", "DO NOT MERGE" ]
delete_merged_branches = true
2 changes: 1 addition & 1 deletion byron/chain/executable-spec/default.nix
@@ -1,4 +1,4 @@
let
pkgs = import ../../../default.nix {};
in
pkgs.nix-tools.libs.cs-blockchain
pkgs.libs.cs-blockchain
2 changes: 1 addition & 1 deletion byron/ledger/executable-spec/default.nix
@@ -1,4 +1,4 @@
let
pkgs = import ../../../default.nix {};
in
pkgs.nix-tools.libs.cs-ledger
pkgs.libs.cs-ledger
2 changes: 1 addition & 1 deletion byron/semantics/executable-spec/default.nix
@@ -1,4 +1,4 @@
let
pkgs = import ../../../default.nix {};
in
pkgs.nix-tools.libs.small-steps
pkgs.libs.small-steps
21 changes: 21 additions & 0 deletions cabal.project
@@ -1,3 +1,5 @@
index-state: 2020-01-31T00:00:00Z

packages:
byron/chain/executable-spec
byron/ledger/executable-spec
Expand All @@ -13,26 +15,45 @@ source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: 965b8b143632faea16680a195e6de57091382700
--sha256: 0x3cy5xa9mqdqnavs45assmmcrzw07qcwsv95capqwa6awz1plhh
subdir: binary

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: 965b8b143632faea16680a195e6de57091382700
--sha256: 0x3cy5xa9mqdqnavs45assmmcrzw07qcwsv95capqwa6awz1plhh
subdir: binary/test

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: 965b8b143632faea16680a195e6de57091382700
--sha256: 0x3cy5xa9mqdqnavs45assmmcrzw07qcwsv95capqwa6awz1plhh
subdir: cardano-crypto-class

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: 965b8b143632faea16680a195e6de57091382700
--sha256: 0x3cy5xa9mqdqnavs45assmmcrzw07qcwsv95capqwa6awz1plhh
subdir: slotting

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-prelude
tag: 00487726c4bc21b4744e59d913334ebfeac7d68e
--sha256: 0v4fcq5kdd2r5dgwys8kv46ff33qp756n26ycxrca10wq14zkwm5

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-prelude
tag: 00487726c4bc21b4744e59d913334ebfeac7d68e
--sha256: 0v4fcq5kdd2r5dgwys8kv46ff33qp756n26ycxrca10wq14zkwm5
subdir: test

source-repository-package
type: git
location: https://github.com/input-output-hk/goblins
tag: 26d35ad52fe9ade3391532dbfeb2f416f07650bc
--sha256: 17p5x0hj6c67jkdqx0cysqlwq2zs2l87azihn1alzajy9ak6ii0b
106 changes: 49 additions & 57 deletions default.nix
@@ -1,62 +1,54 @@
############################################################################
# Based on iohk-skeleton project at https://github.com/input-output-hk/iohk-nix/
############################################################################

{ system ? builtins.currentSystem
, crossSystem ? null
# allows to cutomize haskellNix (ghc and profiling, see ./nix/haskell.nix)
, config ? {}
# Import IOHK common nix lib
, iohkLib ? import ./nix/iohk-common.nix { inherit system crossSystem config; }
# Use nixpkgs pin from iohkLib
, pkgs ? iohkLib.pkgs
# allows to override dependencies of the project without modifications,
# eg. to test build against local checkout of iohk-nix:
# nix build -f default.nix cardano-node --arg sourcesOverride '{
# iohk-nix = ../iohk-nix;
# }'
, sourcesOverride ? {}
# pinned version of nixpkgs augmented with overlays (iohk-nix and our packages).
, pkgs ? import ./nix { inherit system crossSystem config sourcesOverride; }
, gitrev ? pkgs.iohkNix.commitIdFromGitRepoOrZero ./.git
}:

with pkgs; with commonLib;
let
haskell = pkgs.callPackage iohkLib.nix-tools.haskell {};
src = iohkLib.cleanSourceHaskell ./.;
util = pkgs.callPackage ./nix/util.nix {};

# Import the Haskell package set.
haskellPackages = import ./nix/pkgs.nix {
inherit pkgs haskell src;
# Provide cross-compiling secret sauce
inherit (iohkLib.nix-tools) iohk-extras iohk-module;
};

in {
inherit pkgs iohkLib src haskellPackages;

# Grab the executable components of our packages.
inherit (haskellPackages.non-integer.components.exes) nonInt;

tests = util.collectComponents "tests" util.isCardanoLedgerSpecs haskellPackages;
benchmarks = util.collectComponents "benchmarks" util.isCardanoLedgerSpecs haskellPackages;

# This provides a development environment that can be used with nix-shell or
# lorri. See https://input-output-hk.github.io/haskell.nix/user-guide/development/
shell = haskellPackages.shellFor {
name = "cardano-ledger-specs-shell";
# List all local packages in the project.
packages = ps: with ps; [
small-steps
cs-ledger
cs-blockchain
delegation
non-integer
];
# These programs will be available inside the nix-shell.
buildInputs =
with pkgs.haskellPackages; [ hlint stylish-haskell weeder ]
# Add your own packages to the shell.
++ [ ];
};

# Attributes of PDF builds of LaTeX documentation.
byronLedgerSpec = import ./byron/ledger/formal-spec { inherit pkgs; };
byronChainSpec = import ./byron/chain/formal-spec { inherit pkgs; };
semanticsSpec = import ./byron/semantics/formal-spec { inherit pkgs; };
shelleyLedgerSpec = import ./shelley/chain-and-ledger/formal-spec { inherit pkgs; };
delegationDesignSpec = import ./shelley/design-spec { inherit pkgs; };
nonIntegerCalculations = import ./shelley/chain-and-ledger/dependencies/non-integer/doc {inherit pkgs; };
blocksCDDLSpec = import ./byron/cddl-spec {inherit pkgs; };
}

haskellPackages = recRecurseIntoAttrs
# we are only intersted in listing the project packages:
(selectProjectPackages cardanoLedgerSpecsHaskellPackages);

self = {
inherit haskellPackages check-hydra;

# `tests` are the test suites which have been built.
tests = collectComponents' "tests" haskellPackages;
# `benchmarks` (only built, not run).
benchmarks = collectComponents' "benchmarks" haskellPackages;

libs = collectComponents' "library" haskellPackages;

exes = collectComponents' "exes" haskellPackages;

checks = recurseIntoAttrs {
# `checks.tests` collect results of executing the tests:
tests = collectChecks haskellPackages;
};

shell = import ./shell.nix {
inherit pkgs;
withHoogle = true;
};


# Attributes of PDF builds of LaTeX documentation.
byronLedgerSpec = import ./byron/ledger/formal-spec { inherit pkgs; };
byronChainSpec = import ./byron/chain/formal-spec { inherit pkgs; };
semanticsSpec = import ./byron/semantics/formal-spec { inherit pkgs; };
shelleyLedgerSpec = import ./shelley/chain-and-ledger/formal-spec { inherit pkgs; };
delegationDesignSpec = import ./shelley/design-spec { inherit pkgs; };
nonIntegerCalculations = import ./shelley/chain-and-ledger/dependencies/non-integer/doc {inherit pkgs; };
blocksCDDLSpec = import ./byron/cddl-spec {inherit pkgs; };
};
in self

0 comments on commit f6938ee

Please sign in to comment.