diff --git a/README.md b/README.md index 344111f90..40f9d3fc8 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,10 @@ You'll need [Bazel >= 6.0][bazel-getting-started] installed. If you are on NixOS, skip to the [Nixpkgs](#Nixpkgs) section. +> [!NOTE] +> Bazel 8 users will need to add +> `common --noincompatible_disallow_ctx_resolve_tools` to `.bazelrc` + ### System dependencies Refer to the "Before you begin" section in [the documentation](docs/haskell.rst). diff --git a/haskell/cabal.bzl b/haskell/cabal.bzl index d9f92908d..281fc1c2a 100644 --- a/haskell/cabal.bzl +++ b/haskell/cabal.bzl @@ -4,7 +4,6 @@ load("@bazel_skylib//lib:dicts.bzl", "dicts") load("@bazel_skylib//lib:paths.bzl", "paths") load("@bazel_skylib//lib:sets.bzl", "sets") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe", "read_netrc", "use_netrc") -load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value") load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain", "use_cc_toolchain") load(":cc.bzl", "cc_interop_info", "ghc_cc_program_args") load(":haddock.bzl", "generate_unified_haddock_info") @@ -20,6 +19,7 @@ load( load(":private/context.bzl", "haskell_context") load(":private/dependencies.bzl", "gather_dep_info") load(":private/expansions.bzl", "expand_make_variables") +load(":private/get_cpu_value.bzl", "get_cpu_value") load(":private/mode.bzl", "is_profiling_enabled") load( ":private/path_utils.bzl", diff --git a/haskell/ghc_bindist.bzl b/haskell/ghc_bindist.bzl index 6c2732dea..f09d456fa 100644 --- a/haskell/ghc_bindist.bzl +++ b/haskell/ghc_bindist.bzl @@ -2,11 +2,11 @@ load("@bazel_skylib//lib:paths.bzl", "paths") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "patch") -load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value") load("@rules_cc//cc:find_cc_toolchain.bzl", "CC_TOOLCHAIN_TYPE") load("@rules_sh//sh:posix.bzl", "sh_posix_configure") load("//haskell:ghc.bzl", "DEFAULT_GHC_VERSION") load(":private/bazel_platforms.bzl", "bazel_platforms") +load(":private/get_cpu_value.bzl", "get_cpu_value") load( ":private/pkgdb_to_bzl.bzl", "pkgdb_to_bzl", @@ -628,10 +628,7 @@ def _configure_python3_toolchain_impl(repository_ctx): else: stub_shebang = "" repository_ctx.file("BUILD.bazel", executable = False, content = """ -load( - "@bazel_tools//tools/python:toolchain.bzl", - "py_runtime_pair", -) +load("@rules_python//python:py_runtime_pair.bzl", "py_runtime_pair") py_runtime( name = "python3_runtime", interpreter_path = "{python3}", diff --git a/haskell/private/get_cpu_value.bzl b/haskell/private/get_cpu_value.bzl new file mode 100644 index 000000000..625404cf7 --- /dev/null +++ b/haskell/private/get_cpu_value.bzl @@ -0,0 +1,40 @@ +# Bazel 8 fix +# Links: +# - https://github.com/tweag/rules_sh/blob/4524d11e15bea61c0f6841cbc3ae0bc9c09835d8/sh/private/get_cpu_value.bzl#L4 +# - https://github.com/bazelbuild/rules_cc/blob/8395ec0172270f3bf92cd7b06c9b5b3f1f679e88/cc/private/toolchain/lib_cc_configure.bzl#L225 +def get_cpu_value(repository_ctx): + """Compute the cpu_value based on the OS name. Doesn't %-escape the result! + + Args: + repository_ctx: The repository context. + Returns: + One of (darwin, freebsd, x64_windows, ppc, s390x, arm, aarch64, k8, piii) + """ + os_name = repository_ctx.os.name + arch = repository_ctx.os.arch + if os_name.startswith("mac os"): + # Check if we are on x86_64 or arm64 and return the corresponding cpu value. + return "darwin_" + ("arm64" if arch == "aarch64" else "x86_64") + if os_name.find("freebsd") != -1: + return "freebsd" + if os_name.find("openbsd") != -1: + return "openbsd" + if os_name.find("windows") != -1: + if arch == "aarch64": + return "arm64_windows" + else: + return "x64_windows" + + if arch in ["power", "ppc64le", "ppc", "ppc64"]: + return "ppc" + if arch in ["s390x"]: + return "s390x" + if arch in ["mips64"]: + return "mips64" + if arch in ["riscv64"]: + return "riscv64" + if arch in ["arm", "armv7l"]: + return "arm" + if arch in ["aarch64"]: + return "aarch64" + return "k8" if arch in ["amd64", "x86_64", "x64"] else "piii" diff --git a/tools/os_info.bzl b/tools/os_info.bzl index 5fd021e7a..cb87e3354 100644 --- a/tools/os_info.bzl +++ b/tools/os_info.bzl @@ -1,4 +1,4 @@ -load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value") +load("//haskell:private/get_cpu_value.bzl", "get_cpu_value") _os_info_bzl_template = """ cpu_value = "{CPU_VALUE}"