Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
7c351e8
[cabal buck2] Initial basic functionality
simonmar Sep 23, 2026
7434c1a
[cabal buck2] Subsume gen-haskell-prebuit.py
simonmar Sep 23, 2026
5995b52
[cabal buck2] Support .x/.y, named sub-libraries, extra-libraries
simonmar Sep 24, 2026
bef5e27
[cabal buck2] Resolve Alex/Happy to paths in the store
simonmar Sep 24, 2026
513227d
[cabal buck2] Now builds & tests the Cabal repo itself
simonmar Sep 24, 2026
8e369ba
[cabal buck2] Reorganise generated files and update .gitignore
simonmar Sep 24, 2026
60166e1
[cabal buck2] Update a comment
simonmar Sep 25, 2026
9ecaa58
[cabal buck2] Fix HLints
simonmar Sep 25, 2026
096a3a5
[cabal buck2] One more lint
simonmar Sep 25, 2026
4086eea
[cabal buck2] Generate LocalBuildInfo and use it
simonmar Sep 25, 2026
37c7756
[cabal buck2] Fix ElabPackage case
simonmar Sep 25, 2026
ddb2071
[cabal buck2] Simplify a couple of comments
simonmar Sep 25, 2026
057b045
[cabal buck2] Parallelise component configuration
simonmar Sep 26, 2026
9d6ffe0
[cabal buck2] Test case
simonmar Sep 26, 2026
e614aa8
[cabal buck2] benchmark support
simonmar Sep 26, 2026
7245bc4
[cabal buck2] Handle detailed-0.9 testsuites
simonmar Sep 27, 2026
ac95c86
[cabal buck2] Fix race in parallel configure
simonmar Sep 27, 2026
c2e6ed2
[cabal buck2] trim comment
simonmar Sep 28, 2026
6bdd963
[cabal buck2] Improvements to autogen files
simonmar Sep 28, 2026
803e297
[cabal buck2] Fix for include-dirs
simonmar Sep 28, 2026
5de5469
Support build-tool-depends
simonmar Sep 29, 2026
dd84fa4
[cabal buck2] Fix dependencies from omitted components
simonmar Sep 29, 2026
104f76d
[cabal buck2] Don't build any local packages during `cabal buck2`
simonmar Sep 30, 2026
b5abce2
[cabal buck2] Use -jN to control parallelism for cabal buck2
simonmar Sep 30, 2026
7407b43
[cabal buck2] Handle global ghc-options and test-options
simonmar Oct 1, 2026
33bc76e
[cabal buck2] Simplify: srcs is now keyed on module name
simonmar Oct 1, 2026
2c6bb5b
[cabal buck2] Add buck2 as a submodule
simonmar Oct 1, 2026
d559df7
[cabal buck2] Add a CI check
simonmar Oct 1, 2026
0b870a8
[cabal buck2] Update the prelude and move the buck2 version forwards
simonmar Oct 1, 2026
b59f8e8
[cabal buck2] Refactor, build-spec interpreter
simonmar Oct 2, 2026
3e1e45c
[cabal buck2] A bit of tidying up
simonmar Oct 3, 2026
cd99b81
[cabal buck2] Refactoring, modularisation
simonmar Oct 3, 2026
6ad7fa5
[cabal buck2] Make the core of package generation pure
simonmar Oct 3, 2026
19e2082
[cabal buck2] CabalToBuck -> Generate, Generate -> Write
simonmar Oct 4, 2026
464ebd7
[cabal buck2] make style
simonmar Oct 4, 2026
6d6df7d
[cabal buck2] Tidy up comments
simonmar Oct 4, 2026
b367eec
[cabal buck2] Simplify - remove filtered store DB
simonmar Oct 5, 2026
0172d71
[cabal buck2] sync buck2 submodule
simonmar Oct 5, 2026
5036059
[cabal buck2] lint
simonmar Oct 5, 2026
1b119f7
[cabal buck2] Produce proper data types in Generate
simonmar Oct 5, 2026
1028321
[cabal buck2] make style
simonmar Oct 5, 2026
f496806
[cabal buck2] Fix test failure during validate
simonmar Oct 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions .github/workflows/buck2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: buck2

# Builds cabal-install with cabal, uses it to generate a buck2 build of this
# very project (`cabal buck2`), then builds and tests the project with buck2.

# See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#concurrency.
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

on:
push:
branches:
- buck2
pull_request:
workflow_dispatch:

env:
GHC_VERSION: 9.6.7
# A dated release of https://github.com/facebook/buck2/releases
# This is chosen to be compatible with the prelude in the buck2
# submodule; earlier or later versions are not guaranteed to work.
BUCK2_VERSION: "2026-10-01"

jobs:
buck2:
name: cabal buck2
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v7
with:
# The buck2 prelude and support code (buck2/).
submodules: true

- name: Install GHC and cabal
uses: haskell-actions/setup@v2
with:
ghc-version: ${{ env.GHC_VERSION }}
cabal-version: latest

- name: Install buck2
run: |
mkdir -p "$HOME/.local/bin"
curl -fsSL "https://github.com/facebook/buck2/releases/download/${BUCK2_VERSION}/buck2-x86_64-unknown-linux-gnu.zst" \
| zstd -d > "$HOME/.local/bin/buck2"
chmod +x "$HOME/.local/bin/buck2"
echo "$HOME/.local/bin" >> "$GITHUB_PATH"

- name: Tool versions
run: |
ghc --version
cabal --version
buck2 --version
# The buck2 toolchain looks the compiler up by versioned name.
ghc-${GHC_VERSION} --version
ghc-pkg-${GHC_VERSION} --version

- name: Update Hackage index
run: cabal v2-update

- name: Generate build plan for correct cache key
run: cabal build all --dry-run

- name: Get runner OS/version for cache keys
id: get-osver
run: echo "osver=$ImageOS" >> "$GITHUB_OUTPUT"

- name: Restore cached dependencies
uses: actions/cache/restore@v6
id: cache
with:
path: ~/.local/state/cabal
key: ${{ steps.get-osver.outputs.osver }}-store-buck2-${{ hashFiles('dist-newstyle/cache/plan.json') }}
restore-keys: ${{ steps.get-osver.outputs.osver }}-store-buck2-

- name: Build cabal-install
run: cabal build cabal-install:exe:cabal

# Dependencies are built by cabal as part of `cabal buck2` (as a plain
# `cabal build --only-dependencies` would); everything in this project
# is built by buck2. Run a copy of the binary so that the build
# directory it operates on isn't the one it lives in.
- name: Generate buck2 build (cabal buck2)
run: |
cp "$(cabal list-bin cabal-install:exe:cabal)" "$RUNNER_TEMP/cabal"
"$RUNNER_TEMP/cabal" buck2

- name: Cache dependencies
uses: actions/cache/save@v6
if: always() && steps.cache.outputs.cache-hit != 'true'
with:
path: ~/.local/state/cabal
key: ${{ steps.cache.outputs.cache-primary-key }}

- name: buck2 build
run: buck2 build //...

# Tests that are known not to pass under buck2, and so
# are left out:
# - cabal-install:mem-use-tests runs under a deliberately tiny RTS
# stack limit (-K1K) that only optimised code fits in, and needs
# `--num-threads 1`; the default (unoptimised) buck2 build fails it.
# - cabal-benchmarks opens files relative to the project root, but
# like `cabal test` buck2 runs a test in its package's directory.
- name: buck2 test
run: |
mapfile -t tests < <(buck2 uquery "kind(sh_test, //...) - set(//cabal-install:mem-use-tests //cabal-benchmarks:cabal-benchmarks)")
buck2 test "${tests[@]}"
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,12 @@ bench.html

# ignore the downloaded binary files
scripts/release/binary-downloads/

# Output of cabal buck2
BUCK
BUCK.cabal.bzl
cabal-buck2/
/.buckconfig
/PACKAGE
/buck-out
/third-party/haskell
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "buck2"]
path = buck2
url = https://github.com/simonmar/haskell-buck2
branch = cabal
1 change: 1 addition & 0 deletions buck2
Submodule buck2 added at d19202
11 changes: 11 additions & 0 deletions cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,19 @@ library
Distribution.Client.BuildReports.Storage
Distribution.Client.BuildReports.Types
Distribution.Client.BuildReports.Upload
Distribution.Client.Buck2.BuildDependencies
Distribution.Client.Buck2.Configure
Distribution.Client.Buck2.Generate
Distribution.Client.Buck2.LocalPackages
Distribution.Client.Buck2.Prebuilt
Distribution.Client.Buck2.Schedule
Distribution.Client.Buck2.Setup
Distribution.Client.Buck2.Spec
Distribution.Client.Buck2.Starlark
Distribution.Client.Buck2.Write
Distribution.Client.Check
Distribution.Client.CmdBench
Distribution.Client.CmdBuck2
Distribution.Client.CmdBuild
Distribution.Client.CmdClean
Distribution.Client.CmdConfigure
Expand Down
73 changes: 73 additions & 0 deletions cabal-install/src/Distribution/Client/Buck2/BuildDependencies.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
-- | Building the dependencies of a project, and nothing else: everything
-- @cabal build all --only-dependencies@ would build, except the packages
-- that buck2 builds from source itself (see 'isBuiltLocally').
module Distribution.Client.Buck2.BuildDependencies
( buildDependencies
) where

import Distribution.Client.Compat.Prelude
import Prelude ()

import qualified Data.Map as Map
import qualified Data.Set as Set

import qualified Distribution.Client.CmdBuild as CmdBuild
import Distribution.Client.CmdErrorMessages (renderCannotPruneDependencies, reportTargetProblems)
import qualified Distribution.Client.InstallPlan as InstallPlan
import Distribution.Client.ProjectBuilding (unpackInplaceSources)
import Distribution.Client.ProjectConfig (projectConfigWithBuilderRepoContext)
import Distribution.Client.ProjectOrchestration

import Distribution.Client.ProjectPlanning hiding
( pruneInstallPlanToTargets -- we want the one from 'ProjectOrchestration'.
)

import Distribution.Simple.Utils (dieWithException, notice)

import Distribution.Client.Buck2.LocalPackages (isBuiltLocally)
import Distribution.Client.Errors (CabalInstallException (ReportCannotPruneDependencies))

-- | Build every dependency of the selected targets, excluding packages
-- that are forced to build locally (see 'isBuiltLocally').
-- This is similar but not quite the same as the code for @CmdBuild@.
buildDependencies :: Verbosity -> ProjectBaseContext -> [TargetSelector] -> IO ProjectBuildContext
buildDependencies verbosity baseCtx targetSelectors = do
buildCtx@ProjectBuildContext{elaboratedPlanOriginal, elaboratedShared} <-
runProjectPreBuildPhase verbosity baseCtx $ \elaboratedPlan -> do
targets <-
either (reportTargetProblems verbosity "buck2") return $
resolveTargetsFromSolver
CmdBuild.selectPackageTargets
CmdBuild.selectComponentTarget
elaboratedPlan
Nothing
targetSelectors
let elaboratedPlan' = pruneInstallPlanToTargets TargetActionBuild targets elaboratedPlan
excluded =
Map.keysSet targets
<> Set.fromList
[ elabUnitId elab
| InstallPlan.Configured elab <- InstallPlan.toList elaboratedPlan'
, isBuiltLocally elab
]
elaboratedPlan'' <-
either (dieWithException verbosity . ReportCannotPruneDependencies . renderCannotPruneDependencies) return $
pruneInstallPlanToDependencies excluded elaboratedPlan'
return (elaboratedPlan'', targets)

notice verbosity "cabal buck2: building dependencies"
printPlan verbosity baseCtx buildCtx
buildOutcomes <- runProjectBuildPhase verbosity baseCtx buildCtx
runProjectPostBuildPhase verbosity baseCtx buildCtx buildOutcomes

unpackInplaceSources
verbosity
(distDirLayout baseCtx)
elaboratedShared
(projectConfigWithBuilderRepoContext verbosity (buildSettings baseCtx))
[ elab
| InstallPlan.Configured elab <- InstallPlan.toList elaboratedPlanOriginal
, isBuiltLocally elab
, not (elabLocalToProject elab)
]
return buildCtx
Loading
Loading