Skip to content

Commit 03fd55d

Browse files
authored
Merge pull request #2298 from tweag/cb/fix-examples-bindist
Fix examples with ghc bindist
2 parents 18991f9 + bbc5a2f commit 03fd55d

File tree

13 files changed

+149
-64
lines changed

13 files changed

+149
-64
lines changed

.github/workflows/workflow.yaml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,90 @@ jobs:
252252
name: Logs ${{ matrix.os }} ${{ matrix.module }} ${{ matrix.bzlmod }}
253253
path: logs
254254

255+
examples-bindist:
256+
name: Build & Test Examples - bindist
257+
strategy:
258+
fail-fast: false
259+
matrix:
260+
os: [ubuntu-22.04, macos-13, macos-14, windows-latest]
261+
bzlmod: [true, false]
262+
bazel:
263+
- "6.x"
264+
- "7.x"
265+
exclude:
266+
# TODO(cb) add full support for Bazel 7
267+
- os: windows-latest
268+
bazel: "7.x"
269+
env:
270+
USE_BAZEL_VERSION: ${{ matrix.bazel }}
271+
runs-on: ${{ matrix.os }}
272+
steps:
273+
- uses: actions/checkout@v4
274+
- uses: ./.github/actions/free_disk_space_on_linux
275+
- uses: ./.github/actions/install_apt_pkgs
276+
with:
277+
packages: libtinfo5
278+
- name: Mount Bazel cache
279+
uses: actions/cache@v4
280+
with:
281+
path: ~/repo-cache
282+
key: repo-cache-${{ runner.os }}-bindist-${{ env.cache-version }}
283+
- uses: tweag/configure-bazel-remote-cache-auth@v0
284+
with:
285+
buildbuddy_api_key: ${{ secrets.BUILDBUDDY_API_KEY }}
286+
bazelrc_path: .bazelrc.auth
287+
- uses: ./.github/actions/set_tcp_keepalive_time
288+
- uses: extractions/netrc@v2
289+
with:
290+
machine: api.github.com
291+
password: ${{ secrets.GITHUB_TOKEN }}
292+
- name: Configure
293+
shell: bash
294+
run: |
295+
case "${{ runner.os }}" in
296+
macOS) BUILD_CONFIG=macos-bindist;;
297+
Linux) BUILD_CONFIG=linux-bindist;;
298+
Windows) BUILD_CONFIG=ci-windows-bindist;;
299+
esac
300+
if [[ ${{ runner.os }} == Windows ]]; then
301+
output_root_setting="startup --output_user_root=C:/_bzl"
302+
# On windows, we use a separate remote cache for bzlmod,
303+
# because the c dependency analysis is leaking absolute paths which are different
304+
if ${{ matrix.bzlmod }}; then
305+
bzlmod_cache_silo_key='build --remote_default_exec_properties=bzlmod-cache-silo-key=bzlmod'
306+
else
307+
bzlmod_cache_silo_key='build --remote_default_exec_properties=bzlmod-cache-silo-key=workspace'
308+
fi
309+
else
310+
output_root_setting=""
311+
bzlmod_cache_silo_key=""
312+
fi
313+
cat >>.bazelrc.local <<EOF
314+
common --config=ci
315+
build --config=$BUILD_CONFIG
316+
$output_root_setting
317+
$bzlmod_cache_silo_key
318+
common --enable_bzlmod=${{ matrix.bzlmod }}
319+
EOF
320+
- name: Build
321+
shell: bash
322+
working-directory: examples
323+
run: |
324+
# Quote the package specifier so that it works on Windows
325+
bazelisk build "//..."
326+
327+
- name: Test
328+
shell: bash
329+
working-directory: examples
330+
run: |
331+
# Quote the package specifier so that it works on Windows
332+
bazelisk build "//..."
333+
255334
all_ci_tests:
256335
runs-on: ubuntu-22.04
257336
needs:
258337
- lint
338+
- examples-bindist
259339
- test-nixpkgs
260340
- test-bindist
261341
if: ${{ always() }}

examples/.bazelrc.auth

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../.bazelrc.auth

examples/.bazelrc.bzlmod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
common:bzlmod --enable_bzlmod
2-
common:common --registry=file://%workspace%/../registry --registry=https://bcr.bazel.build
2+
common:common --registry=file:///%workspace%/../registry --registry=https://bcr.bazel.build

examples/MODULE.bazel

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ bazel_dep(
3737
name = "bazel_skylib",
3838
version = "1.7.1",
3939
)
40+
bazel_dep(name = "platforms", version = "0.0.11")
4041

4142
non_module_deps = use_extension(":non_module_deps.bzl", "non_module_deps")
4243
use_repo(
@@ -83,13 +84,23 @@ stack_snapshot.package(
8384
"conduit",
8485
"conduit-extra",
8586
"hspec",
86-
# Remove hspec-* packages once https://github.com/tweag/rules_haskell/issues/1871 is resolved
87-
"hspec-core",
88-
"hspec-discover",
89-
"hspec-expectations",
9087
"optparse-applicative",
9188
"text",
9289
"text-show",
90+
# TODO(cb) remove these transitive deps once
91+
# https://github.com/tweag/rules_haskell/issues/1871 is resolved
92+
"bifunctors",
93+
"call-stack",
94+
"generic-deriving",
95+
"hspec-core",
96+
"hspec-discover",
97+
"hspec-expectations",
98+
"HUnit",
99+
"mono-traversable",
100+
"quickcheck-io",
101+
"transformers-compat",
102+
"typed-process",
103+
"unliftio-core",
93104
]
94105
]
95106

examples/WORKSPACE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,31 @@ stack_snapshot(
8080
"text",
8181
"text-show",
8282
],
83+
# TODO(cb) remove once we use Cabal >= 3.10.1 / GHC >= 9.6.1
84+
# See https://github.com/tweag/rules_haskell/issues/1871
85+
setup_deps = {
86+
pkg: ["@Cabal//:Cabal"]
87+
for pkg in [
88+
"bifunctors",
89+
"call-stack",
90+
"conduit",
91+
"conduit-extra",
92+
"generic-deriving",
93+
"hspec",
94+
"hspec-core",
95+
"hspec-discover",
96+
"hspec-expectations",
97+
"HUnit",
98+
"mono-traversable",
99+
"optparse-applicative",
100+
"quickcheck-io",
101+
"split",
102+
"text-show",
103+
"transformers-compat",
104+
"typed-process",
105+
"unliftio-core",
106+
]
107+
},
83108
# This example uses an unpinned version of stack_snapshot, meaning that stack is invoked on every build.
84109
# To switch to pinned stackage dependencies, run `bazel run @stackage-unpinned//:pin` and
85110
# uncomment the following line.

examples/nixpkgs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../nixpkgs/

examples/non_module_deps.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ haskell_cabal_library(
6868
name = "Cabal",
6969
srcs = glob(["Cabal/**"]),
7070
verbose = False,
71-
version = "3.6.3.0",
71+
version = "3.8.1.0",
7272
visibility = ["//visibility:public"],
7373
)
7474
""",
75-
sha256 = "f69b46cb897edab3aa8d5a4bd7b8690b76cd6f0b320521afd01ddd20601d1356",
76-
strip_prefix = "cabal-gg-8220-with-3630",
77-
urls = ["https://github.com/tweag/cabal/archive/refs/heads/gg/8220-with-3630.zip"],
75+
sha256 = "b697b558558f351d2704e520e7dcb1f300cd77fea5677d4b2ee71d0b965a4fe9",
76+
strip_prefix = "cabal-ghc-9.4-paths-module-relocatable",
77+
urls = ["https://github.com/tweag/cabal/archive/refs/heads/ghc-9.4-paths-module-relocatable.zip"],
7878
)
7979

8080
def _non_module_deps_impl(_ctx):

examples/rts/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ haskell_toolchain_library(name = "rts")
1212
haskell_library(
1313
name = "add-one-hs",
1414
srcs = ["One.hs"],
15+
# FIXME: this is broken on Windows, see https://github.com/tweag/rules_haskell/issues/2299
16+
target_compatible_with = select({
17+
"@platforms//os:windows": ["@platforms//:incompatible"],
18+
"//conditions:default": [],
19+
}),
1520
deps = [":base"],
1621
)
1722

haskell/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ exports_files(
3232
"private/coverage_wrapper.sh.tpl",
3333
"private/ghci_repl_wrapper.sh",
3434
"private/hie_bios_wrapper.sh",
35-
"private/haddock_wrapper.sh.tpl",
3635
"private/cc_wrapper.py.tpl",
3736
"private/cc_wrapper_windows.sh.tpl",
3837
"private/pkgdb_to_bzl.py",

haskell/haddock.bzl

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -135,26 +135,7 @@ def _haskell_doc_aspect_impl(target, ctx):
135135
[lib for li in target[CcInfo].linking_context.linker_inputs.to_list() for lib in li.libraries],
136136
)
137137

138-
# TODO(mboes): we should be able to instantiate this template only
139-
# once per toolchain instance, rather than here.
140-
# TODO(aherrmann): Convert to a standalone sh_binary.
141-
# Executable shell script files don't work on Windows.
142-
# This fails with `%1 is not a valid Win32 application.`.
143-
haddock_wrapper = ctx.actions.declare_file("haddock_wrapper-{}".format(hs.name))
144-
ctx.actions.expand_template(
145-
template = ctx.file._haddock_wrapper_tpl,
146-
output = haddock_wrapper,
147-
substitutions = {
148-
"%{ghc-pkg}": hs.tools.ghc_pkg.path, # not mentioned in bash XXX delete?
149-
"%{haddock}": shell.quote(hs.tools.haddock.path),
150-
# XXX Workaround
151-
# https://github.com/bazelbuild/bazel/issues/5980.
152-
"%{env}": render_env(hs.env),
153-
},
154-
is_executable = True,
155-
)
156-
157-
ctx.actions.run(
138+
ctx.actions.run_shell(
158139
inputs = depset(transitive = [
159140
target[HaskellInfo].package_databases,
160141
target[HaskellInfo].interface_dirs,
@@ -177,7 +158,21 @@ def _haskell_doc_aspect_impl(target, ctx):
177158
outputs = [haddock_file, html_dir],
178159
mnemonic = "HaskellHaddock",
179160
progress_message = "HaskellHaddock {}".format(ctx.label),
180-
executable = haddock_wrapper,
161+
command = """
162+
set -eo pipefail
163+
164+
{env}
165+
166+
# BSD and GNU mktemp are very different; attempt GNU first
167+
TEMP=$(mktemp -d 2>/dev/null || mktemp -d -t 'haddock_wrapper')
168+
trap cleanup 1 2 3 6
169+
cleanup() {{ rm -rf "$TEMP"; }}
170+
# XXX Override TMPDIR to prevent race conditions on certain platforms.
171+
# This is a workaround for
172+
# https://github.com/haskell/haddock/issues/894.
173+
TMPDIR=$TEMP {haddock} "$@"
174+
cleanup
175+
""".format(env = render_env(hs.env), haddock = shell.quote(hs.tools.haddock.path)),
181176
arguments = [
182177
args,
183178
compile_flags,
@@ -201,12 +196,6 @@ def _haskell_doc_aspect_impl(target, ctx):
201196

202197
haskell_doc_aspect = aspect(
203198
_haskell_doc_aspect_impl,
204-
attrs = {
205-
"_haddock_wrapper_tpl": attr.label(
206-
allow_single_file = True,
207-
default = Label("@rules_haskell//haskell:private/haddock_wrapper.sh.tpl"),
208-
),
209-
},
210199
attr_aspects = ["deps", "exports"],
211200
required_aspect_providers = [HaskellCcLibrariesInfo],
212201
toolchains = [

haskell/private/cabal_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def distdir_prefix():
245245
for db in deps_package_databases:
246246
try:
247247
ps = subprocess.Popen([ghc_pkg, "dump", "--expand-pkgroot", "-f", os.path.dirname(os.path.join(execroot,db))], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
248-
subprocess.check_output([ghc_pkg, "update", "-f", deps_package_db, "-"], stdin=ps.stdout, stderr=subprocess.PIPE)
248+
subprocess.check_output([ghc_pkg, "update", "--force", "-f", deps_package_db, "-"], stdin=ps.stdout, stderr=subprocess.PIPE)
249249
ps.wait()
250250
except subprocess.CalledProcessError as err:
251251
sys.stdout.buffer.write(err.stdout)

haskell/private/haddock_wrapper.sh.tpl

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/shellcheck/BUILD.bazel

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ shellcheck(
2828
sh_flavor = "bash",
2929
)
3030

31-
shellcheck(
32-
name = "haddock_wrapper.sh",
33-
args = ["$(location @rules_haskell//haskell:private/haddock_wrapper.sh.tpl)"],
34-
data = ["@rules_haskell//haskell:private/haddock_wrapper.sh.tpl"],
35-
sh_flavor = "bash",
36-
)
37-
3831
shellcheck(
3932
name = "netlify-build",
4033
args = ["$(location @rules_haskell//:.netlify/build.sh)"],

0 commit comments

Comments
 (0)