Skip to content

Commit 668f826

Browse files
committed
feat(Makefile): add stack support, default to cabal
1 parent e09615c commit 668f826

3 files changed

Lines changed: 81 additions & 13 deletions

File tree

.github/workflows/haskell-nix.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ permissions:
88
contents: read
99

1010
jobs:
11-
nix-ci:
11+
cabal:
1212
runs-on: ubuntu-latest
1313

1414
steps:
@@ -23,7 +23,7 @@ jobs:
2323
- name: Enable Nix cache
2424
uses: DeterminateSystems/magic-nix-cache-action@565684385bcd71bad329742eefe8d12f2e765b39 # v13
2525

26-
- name: Build and test
26+
- name: Build and test (cabal)
2727
run: |
2828
nix develop --command bash -c '
2929
# hsc2hs-generated test binaries crash in nix shells on Linux
@@ -36,3 +36,18 @@ jobs:
3636
chmod +x /tmp/bin/hsc2hs
3737
CABAL_CONFIGURE_FLAGS="--with-hsc2hs=/tmp/bin/hsc2hs" make ci
3838
'
39+
40+
stack:
41+
runs-on: ubuntu-latest
42+
43+
steps:
44+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
45+
46+
- name: Install Nix
47+
uses: DeterminateSystems/nix-installer-action@c5a866b6ab867e88becbed4467b93592bce69f8a # v21
48+
49+
- name: Enable Nix cache
50+
uses: DeterminateSystems/magic-nix-cache-action@565684385bcd71bad329742eefe8d12f2e765b39 # v13
51+
52+
- name: Build and test (stack)
53+
run: nix develop --command make stack-ci

Makefile

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
HS_FILES := $(shell git ls-files '*.hs')
22

3+
# BUILD_TOOL selects the Haskell build tool: cabal (default) or stack.
4+
BUILD_TOOL ?= cabal
5+
6+
# --- Shared ---
7+
38
.PHONY: format
49
format:
510
@test -n "$(HS_FILES)" || { echo "No tracked .hs files found"; exit 0; }
@@ -10,6 +15,8 @@ format-check:
1015
@test -n "$(HS_FILES)" || { echo "No tracked .hs files found"; exit 0; }
1116
fourmolu -m check $(HS_FILES)
1217

18+
# --- Cabal ---
19+
1320
.PHONY: cabal-check
1421
cabal-check:
1522
cabal check
@@ -18,26 +25,71 @@ cabal-check:
1825
cabal-update:
1926
cabal update
2027

21-
.PHONY: configure
22-
configure:
28+
.PHONY: cabal-configure
29+
cabal-configure:
2330
cabal configure --enable-tests --enable-benchmarks --disable-documentation $(CABAL_CONFIGURE_FLAGS)
2431
cabal build --dry-run
2532

26-
.PHONY: deps
27-
deps:
33+
.PHONY: cabal-deps
34+
cabal-deps:
2835
cabal build --only-dependencies
2936

30-
.PHONY: build
31-
build:
37+
.PHONY: cabal-build
38+
cabal-build:
3239
cabal build all
3340

34-
.PHONY: test
35-
test:
41+
.PHONY: cabal-test
42+
cabal-test:
3643
cabal test all
3744

38-
.PHONY: docs
39-
docs:
45+
.PHONY: cabal-docs
46+
cabal-docs:
4047
cabal haddock all --disable-documentation
4148

49+
.PHONY: cabal-ci
50+
cabal-ci: format-check cabal-check cabal-update cabal-configure cabal-deps cabal-build cabal-test cabal-docs
51+
52+
# --- Stack ---
53+
54+
.PHONY: stack-update
55+
stack-update:
56+
stack update
57+
58+
.PHONY: stack-deps
59+
stack-deps:
60+
stack build --only-dependencies --test --no-run-tests
61+
62+
.PHONY: stack-build
63+
stack-build:
64+
stack build
65+
66+
.PHONY: stack-test
67+
stack-test:
68+
stack test
69+
70+
.PHONY: stack-docs
71+
stack-docs:
72+
stack haddock --no-haddock-deps
73+
74+
.PHONY: stack-ci
75+
stack-ci: format-check stack-update stack-deps stack-build stack-test stack-docs
76+
77+
# ── Generic (delegates to BUILD_TOOL) ────────────────────────────────
78+
79+
.PHONY: update
80+
update: $(BUILD_TOOL)-update
81+
82+
.PHONY: deps
83+
deps: $(BUILD_TOOL)-deps
84+
85+
.PHONY: build
86+
build: $(BUILD_TOOL)-build
87+
88+
.PHONY: test
89+
test: $(BUILD_TOOL)-test
90+
91+
.PHONY: docs
92+
docs: $(BUILD_TOOL)-docs
93+
4294
.PHONY: ci
43-
ci: format-check cabal-check cabal-update configure deps build test docs
95+
ci: $(BUILD_TOOL)-ci

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# Haskell Tools
1616
hsPkgs.ghc
1717
pkgs.cabal-install
18+
pkgs.stack
1819
hsPkgs.fourmolu
1920
hsPkgs.hlint
2021
hsPkgs.haskell-language-server

0 commit comments

Comments
 (0)