Skip to content

Commit a93b20a

Browse files
authored
Merge pull request #2348 from alwaldend/dev/fix_bazel_8_compat
Add bazel 8 compatibility
2 parents 3346db7 + c5f9029 commit a93b20a

File tree

5 files changed

+48
-7
lines changed

5 files changed

+48
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ You'll need [Bazel >= 6.0][bazel-getting-started] installed.
2727

2828
If you are on NixOS, skip to the [Nixpkgs](#Nixpkgs) section.
2929

30+
> [!NOTE]
31+
> Bazel 8 users will need to add
32+
> `common --noincompatible_disallow_ctx_resolve_tools` to `.bazelrc`
33+
3034
### System dependencies
3135

3236
Refer to the "Before you begin" section in [the documentation](docs/haskell.rst).

haskell/cabal.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ load("@bazel_skylib//lib:dicts.bzl", "dicts")
44
load("@bazel_skylib//lib:paths.bzl", "paths")
55
load("@bazel_skylib//lib:sets.bzl", "sets")
66
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe", "read_netrc", "use_netrc")
7-
load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value")
87
load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain", "use_cc_toolchain")
98
load(":cc.bzl", "cc_interop_info", "ghc_cc_program_args")
109
load(":haddock.bzl", "generate_unified_haddock_info")
@@ -20,6 +19,7 @@ load(
2019
load(":private/context.bzl", "haskell_context")
2120
load(":private/dependencies.bzl", "gather_dep_info")
2221
load(":private/expansions.bzl", "expand_make_variables")
22+
load(":private/get_cpu_value.bzl", "get_cpu_value")
2323
load(":private/mode.bzl", "is_profiling_enabled")
2424
load(
2525
":private/path_utils.bzl",

haskell/ghc_bindist.bzl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
load("@bazel_skylib//lib:paths.bzl", "paths")
44
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "patch")
5-
load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value")
65
load("@rules_cc//cc:find_cc_toolchain.bzl", "CC_TOOLCHAIN_TYPE")
76
load("@rules_sh//sh:posix.bzl", "sh_posix_configure")
87
load("//haskell:ghc.bzl", "DEFAULT_GHC_VERSION")
98
load(":private/bazel_platforms.bzl", "bazel_platforms")
9+
load(":private/get_cpu_value.bzl", "get_cpu_value")
1010
load(
1111
":private/pkgdb_to_bzl.bzl",
1212
"pkgdb_to_bzl",
@@ -628,10 +628,7 @@ def _configure_python3_toolchain_impl(repository_ctx):
628628
else:
629629
stub_shebang = ""
630630
repository_ctx.file("BUILD.bazel", executable = False, content = """
631-
load(
632-
"@bazel_tools//tools/python:toolchain.bzl",
633-
"py_runtime_pair",
634-
)
631+
load("@rules_python//python:py_runtime_pair.bzl", "py_runtime_pair")
635632
py_runtime(
636633
name = "python3_runtime",
637634
interpreter_path = "{python3}",

haskell/private/get_cpu_value.bzl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Bazel 8 fix
2+
# Links:
3+
# - https://github.com/tweag/rules_sh/blob/4524d11e15bea61c0f6841cbc3ae0bc9c09835d8/sh/private/get_cpu_value.bzl#L4
4+
# - https://github.com/bazelbuild/rules_cc/blob/8395ec0172270f3bf92cd7b06c9b5b3f1f679e88/cc/private/toolchain/lib_cc_configure.bzl#L225
5+
def get_cpu_value(repository_ctx):
6+
"""Compute the cpu_value based on the OS name. Doesn't %-escape the result!
7+
8+
Args:
9+
repository_ctx: The repository context.
10+
Returns:
11+
One of (darwin, freebsd, x64_windows, ppc, s390x, arm, aarch64, k8, piii)
12+
"""
13+
os_name = repository_ctx.os.name
14+
arch = repository_ctx.os.arch
15+
if os_name.startswith("mac os"):
16+
# Check if we are on x86_64 or arm64 and return the corresponding cpu value.
17+
return "darwin_" + ("arm64" if arch == "aarch64" else "x86_64")
18+
if os_name.find("freebsd") != -1:
19+
return "freebsd"
20+
if os_name.find("openbsd") != -1:
21+
return "openbsd"
22+
if os_name.find("windows") != -1:
23+
if arch == "aarch64":
24+
return "arm64_windows"
25+
else:
26+
return "x64_windows"
27+
28+
if arch in ["power", "ppc64le", "ppc", "ppc64"]:
29+
return "ppc"
30+
if arch in ["s390x"]:
31+
return "s390x"
32+
if arch in ["mips64"]:
33+
return "mips64"
34+
if arch in ["riscv64"]:
35+
return "riscv64"
36+
if arch in ["arm", "armv7l"]:
37+
return "arm"
38+
if arch in ["aarch64"]:
39+
return "aarch64"
40+
return "k8" if arch in ["amd64", "x86_64", "x64"] else "piii"

tools/os_info.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value")
1+
load("//haskell:private/get_cpu_value.bzl", "get_cpu_value")
22

33
_os_info_bzl_template = """
44
cpu_value = "{CPU_VALUE}"

0 commit comments

Comments
 (0)