Skip to content

Commit e82309f

Browse files
committed
add Buck build
Change-Id: Ia3d5cca3998af155bcdc78e72effdb6dcdc21af0
1 parent b98b6cd commit e82309f

516 files changed

Lines changed: 61630 additions & 6 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.buckconfig

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[cells]
2+
root = .
3+
prelude = prelude
4+
toolchains = toolchains
5+
none = none
6+
ghc_persistent_worker = ghc_persistent_worker
7+
8+
[cell_aliases]
9+
config = prelude
10+
ovr_config = prelude
11+
fbcode = none
12+
fbsource = none
13+
fbcode_macros = none
14+
buck = none
15+
16+
[external_cells]
17+
prelude = git
18+
19+
[external_cell_prelude]
20+
git_origin = https://github.com/MercuryTechnologies/buck2-prelude.git
21+
# branch: tek/only-spawn-make
22+
commit_hash = 97ee3e1e62605ef78b49cb8a1362634d96119a4a
23+
24+
[parser]
25+
target_platform_detector_spec = target:root//...->prelude//platforms:default
26+
27+
[project]
28+
ignore = .git, tmp, ghcHEAD-toolchains
29+
30+
[buck2]
31+
materializations = deferred
32+
hash_all_commands = true
33+
34+
[build]
35+
execution_platforms = root//platforms:host-persistent-worker

.buckconfig.d/01-default-platform

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# configure the default execution platform here
2+
#
3+
# Note: this file has a lower precedence than .buckconfig and .buckconfig.local (which has the highest)
4+
5+
[build]
6+
execution_platforms = prelude//platforms:default
7+
8+
[test]
9+
re_profile = default

.github/workflows/buck-test.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Buck Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- tek/debug
7+
workflow_dispatch:
8+
9+
jobs:
10+
11+
tests:
12+
name: Run tests
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
id-token: write
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: DeterminateSystems/nix-installer-action@v16
20+
with:
21+
github-token: ${{ secrets.GITHUB_TOKEN }}
22+
- uses: cachix/cachix-action@v16
23+
with:
24+
name: tek
25+
- run: nix run .#hybrid
26+
- run: nix run .#three-layers

BUCK

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
filegroup(
2+
name = "nix_overlays",
3+
srcs = glob([
4+
"flake.lock",
5+
"**/*.nix",
6+
"buck-proxy/**",
7+
"ghc-worker/**",
8+
"grpc/**",
9+
"instrument/**",
10+
"internal/**",
11+
"proto/**",
12+
"types/**",
13+
]),
14+
visibility = ["PUBLIC"],
15+
)

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,15 @@ $ cabal run ghc-persistent-worker-server -- --ghc ~/repo/srcc/ghcHEAD/_build/sta
3030
$ GHC_PERSISTENT_WORKER_SOCKET=/tmp/ghc_server.ipc cabal run ghc-persistent-worker-client -- test/A.hs
3131
```
3232
(optionally, one can set `--package-db (pkg_db_path)`. One can have multiple `--package-db`.)
33+
34+
Buck
35+
====
36+
37+
The flake provides a test environment for Buck with a locally Nix-built worker.
38+
Enter the shell `buck` to use it:
39+
40+
```
41+
$ nix develop .#buck
42+
$ buck build //test/three-layers/project/...
43+
44+
```

flake.lock

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
url = "github:tek/ghc-debug/59198910da4573612bf5c6f9969c64fa620db396";
77
flake = false;
88
};
9+
inputs.fenix = {
10+
url = "github:nix-community/fenix/9d17341a4f227fe15a0bca44655736b3808e6a03";
11+
inputs.nixpkgs.follows = "hix/nixpkgs";
12+
};
913

10-
outputs = {hix, ghc-debug, ...}: let
14+
outputs = {hix, ghc-debug, fenix, ...}: let
1115

1216
testEnv = config: {
1317
ghc_dir = "${config.toolchain.vanilla.ghc}";
@@ -38,7 +42,15 @@
3842
ghc-worker = notest;
3943
};
4044

41-
in hix ({config, build, lib, ...}: {
45+
in hix ({config, build, lib, util, ...}: let
46+
47+
buckTest = dir: {
48+
expose = true;
49+
env = "buck";
50+
command = "${import ./ops/buck-test/${dir} { inherit util; }}";
51+
};
52+
53+
in {
4254

4355
compiler = "ghc910";
4456
ghcVersions = [];
@@ -64,6 +76,14 @@
6476
source.build.flavour = "release+split_sections+ipe";
6577
};
6678

79+
mwb-hybrid.source.build = {
80+
version = "9.10.1";
81+
url = "https://gitlab.haskell.org/ghc/ghc";
82+
rev = "f9587b0fcc14565953326d0032a3e92a871d0468";
83+
hash = "sha256-eSFKCb2jgcxdNuy1NaLgkmjkZrr1FD09RbNm+c8FUW4=";
84+
flavour = "release+split_sections+ipe";
85+
};
86+
6787
};
6888

6989
envs.dev = args: {
@@ -100,6 +120,18 @@
100120
];
101121
};
102122

123+
envs.hybrid = args: {
124+
expose.scoped = true;
125+
env = testEnv args.config;
126+
package-set.compiler = "mwb-hybrid";
127+
overrides = [
128+
sharedExeOverrides
129+
ipeOverrides
130+
(envOverrides args.config)
131+
buckBinOverrides
132+
];
133+
};
134+
103135
envs.profiled = args: {
104136
env = testEnv args.config;
105137
overrides = [
@@ -109,12 +141,63 @@
109141
package-set.compiler = "mwb-ipe";
110142
};
111143

144+
# ------------------------------------------------------------------------------------------------------------------
145+
# Buck
146+
147+
# The environment for the CLI tool `buck`, using the Buck overlay extracted from MWB.
148+
# `fenix` is a dep of Buck.
149+
# Exposes a devShell named `buck` that should be used to gain access to the CLI tool.
150+
envs.buck = {
151+
expose.shell = true;
152+
packages = [];
153+
buildInputs = pkgs: [pkgs.buck2-source];
154+
155+
package-set.compiler.nixpkgs.overlays = [
156+
fenix.overlays.default
157+
(import ./ops/buck/overlay.nix)
158+
];
159+
};
160+
161+
# The environment for our Buck nixpkgs integration, from which GHC and the package set are taken when exposing them
162+
# in `outputs.packages` below.
163+
# Uses our custom GHC build and injects a hook into all Haskell derivations that creates `package.cache` in the
164+
# store dir, which is needed because Buck supplies individual package DBs to GHC.
165+
envs.buck-build = {config, ...}: {
166+
packages = [];
167+
package-set.compiler = "mwb-ipe";
168+
env = testEnv config;
169+
170+
overrides = api@{override, ...}: let
171+
testDeps = import ./ops/test-deps.nix { inherit util; };
172+
in testDeps.overrides api // {
173+
__all = override (drv: {
174+
postInstall = (drv.postInstall or "") + ''
175+
ghc-pkg recache --package-db $packageConfDir
176+
'';
177+
});
178+
};
179+
};
180+
181+
# The interface that Buck expects when loading Nix packages in `toolchains/BUCK` using those `nix.rules.flake`
182+
# rules.
183+
# Exposes the toolchain Haskell packages listed in `./ops/ghc-toolchain-libraries.nix` in the attribute
184+
# `haskellPackages.libs` as well as Python and the GHC compiler derivation.
185+
outputs.packages =
186+
import ./ops/buck/packages.nix { inherit config lib; };
187+
188+
# ------------------------------------------------------------------------------------------------------------------
189+
112190
envs.hls-db = {};
113191

114192
commands.hls.env = "hls-db";
115193

116194
output.extraPackages = ["ghc-debug-brick" "eventlog2html" "hp2pretty" "ghc-events"];
117195

196+
commands.comparison-1 = buckTest "comparison1";
197+
commands.comparison-2 = buckTest "comparison2";
198+
commands.three-layers = buckTest "three-layers";
199+
commands.hybrid = buckTest "hybrid";
200+
118201
packages = {
119202

120203
ghc-worker = {
@@ -170,6 +253,20 @@
170253
source-dirs = "test";
171254
dependOnLibrary = false;
172255
};
256+
257+
executables.batch-worker = {};
258+
259+
executables.ghc-bin = {
260+
dependencies = [
261+
"containers"
262+
"filepath"
263+
"ghc"
264+
"ghc-boot"
265+
"transformers"
266+
];
267+
dependOnLibrary = false;
268+
};
269+
173270
};
174271

175272
debug = {
@@ -349,4 +446,5 @@
349446
};
350447

351448
});
449+
352450
}

ghc-worker/batch-worker/Main.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Main where
2+
3+
import GhcWorker.Batch (batchCompile)
4+
import System.Environment (getArgs)
5+
import System.IO (BufferMode (..), hSetBuffering, stderr, stdout)
6+
7+
main :: IO ()
8+
main = do
9+
hSetBuffering stdout LineBuffering
10+
hSetBuffering stderr LineBuffering
11+
paths <- getArgs
12+
batchCompile paths

0 commit comments

Comments
 (0)