Skip to content

Commit

Permalink
Revamp build: remove Nix, have a single cabal project
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Dec 9, 2023
1 parent 554459a commit 5355623
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 391 deletions.
5 changes: 3 additions & 2 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
use nix
source_env_if_exists .envrc.private # allow custom extensions
PATH_add $HOME/.ghcup/bin
PATH_add $(pwd)/bin/cabal
PATH_add $(pwd)/bin/ghc/bin
33 changes: 0 additions & 33 deletions .github/workflows/ci.yaml

This file was deleted.

75 changes: 75 additions & 0 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Stripped down version of https://github.com/haskell-actions/setup#model-cabal-workflow-with-caching

name: Haskell build
on:
push:
branches: [main]
pull_request:

jobs:
build:
name: GHC ${{ matrix.ghc-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: ./slides
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
ghc-version: ['9.4.7']

steps:
- uses: actions/checkout@v4

- name: Extract Haskell snippets from slides
working-directory: slides
run: |
git clone https://github.com/smelc/exdown
EXDOWN=exdown/exdown.py ./extract_hs.sh
- name: Set up GHC ${{ matrix.ghc-version }}
uses: haskell-actions/setup@v2
id: setup
with:
ghc-version: ${{ matrix.ghc-version }}
# Defaults, added for clarity:
cabal-version: '3.6.2.0'
cabal-update: true

- name: Configure the build
run: |
cabal configure --enable-tests --enable-benchmarks --disable-documentation
cabal build all --dry-run
# The last step generates dist-newstyle/cache/plan.json for the cache key.

- name: Restore cached dependencies
uses: actions/cache/restore@v3
id: cache
env:
key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }}
with:
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }}
restore-keys: ${{ env.key }}-

- name: Install dependencies
# If we had an exact cache hit, the dependencies will be up to date.
if: steps.cache.outputs.cache-hit != 'true'
run: cabal build all --only-dependencies

# Cache dependencies already here, so that we do not have to rebuild them should the subsequent steps fail.
- name: Save cached dependencies
uses: actions/cache/save@v3
# If we had an exact cache hit, trying to save the cache would error because of key clash.
if: steps.cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ steps.cache.outputs.cache-primary-key }}

- name: Build
run: cabal build all

# No tests
# - name: Run tests
# run: cabal test all
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
.direnv
.venv
ghc
hls
tps/dist-newstyle
bin
dist-newstyle
slides/*.java
slides/app/Course*.hs
slides/dist-newstyle
slides/Course*.hs
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,24 @@ But I've never done it.

### Development instruction

- GHC and hls are installed in an isolated manner at the top-level of the repo
- The Haskell compiler (GHC) is installed in an isolated manner, in `bin/ghc` (see below)
- This requires [ghcup](https://www.haskell.org/ghcup) in `PATH` and that's all
- When started from this directory, the [vscode Haskell extension](https://github.com/haskell/vscode-haskell)
will install the required [language server](https://github.com/haskell/haskell-language-server) on its own,
so nothing to do here.

```
# Populate GHC, this matches PATH_ADD $(pwd)/ghc/bin in .envrc
ghcup install ghc 8.10.7 --isolate $(pwd)/ghc
# Populate hls, this matches PATH_ADD $(pwd)/hls/bin in .envrc
ghcup install hls --isolate $(pwd)/hls
mkdir -p bin/ghc
# Instal cabal, this matches PATH_ADD $(pwd)/bin/ghc/bin in .envrc
ghcup install cabal --isolate $(pwd)/bin/cabal
# Populate GHC, this matches PATH_ADD $(pwd)/bin/ghc/bin in .envrc
# Note that GHC's version number is also in .github/workflows/haskell.yml
ghcup install ghc 9.4.7 --isolate $(pwd)/bin/ghc
```

Because there is a [cabal.project](./cabal.project) file that pins the set of packages to a specific
timestamp, this project is highly reproducible.

---

This course is funded by my employer: [Tweag](https://www.tweag.io/)
2 changes: 2 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages: .
index-state: 2023-08-22T10:00:00Z
26 changes: 0 additions & 26 deletions nix/sources.json

This file was deleted.

174 changes: 0 additions & 174 deletions nix/sources.nix

This file was deleted.

29 changes: 0 additions & 29 deletions shell.nix

This file was deleted.

4 changes: 0 additions & 4 deletions slides/app/Main.hs

This file was deleted.

Loading

0 comments on commit 5355623

Please sign in to comment.