Workspace rules (GHC binary distributions)
Bazel

Workspace rules (GHC binary distributions)


bindist_info_for_version

bindist_info_for_version(ctx, version)

Attributes

ctx required
version required

configure_python3_toolchain

configure_python3_toolchain(name, register)

Autoconfigure python3 toolchain for GHC bindist

rules_haskell requires Python 3 to build Haskell targets. Under Nix we use rules_nixpkgs’s nixpkgs_python_configure repository rule to use a nixpkgs provisioned Python toolchain. However, outside of Nix we have to rely on whatever Python toolchain is installed on the system.

Bazel provides @bazel_tools//tools/python:autodetecting_toolchain for this purpose. However, in its current form, that toolchain does not support Python toolchains installed outside of standard system paths such as /usr/bin:/bin:/usr/sbin. The reason is that the toolchain does not look for a Python interpreter in a repository rule. Instead it uses wrapper scripts that look for a Python interpreter in $PATH within the sandboxed build actions.

On MacOS, which, at the time of writing, only includes Python 2.7, users will want to install Python 3 in a non-system path, e.g. via homebrew or py_env. The auto detecting toolchain will not find this interpreter and builds will fail with the following error:

Error occurred while attempting to use the default Python toolchain (@rules_python//python:autodetecting_toolchain).
According to '/usr/bin/python -V', version is 'Python 2.7.10', but we need version 3. PATH is:

/usr/bin:/bin:/usr/sbin

Please ensure an interpreter with version 3 is available on this platform as 'python3' or 'python', or else register an appropriate Python toolchain as per the documentation for py_runtime_pair (https://github.com/bazelbuild/rules_python/blob/master/docs/python.md#py_runtime_pair).

Note that prior to Bazel 0.27, there was no check to ensure that the interpreter's version matched the version declared by the target (#4815). If your build worked prior to Bazel 0.27, and you're sure your targets do not require Python 3, you can opt out of this version check by using the non-strict autodetecting toolchain instead of the standard autodetecting toolchain. This can be done by passing the flag `--extra_toolchains=@rules_python//python:autodetecting_toolchain_nonstrict` on the command line or adding it to your bazelrc.

This function defins a custom auto detcting Python toolchain that looks for a Python 3 interpreter within a repository rule, so that Bazel’s sandboxing does not restrict the visible installation paths. It then registers an appropriate Python toolchain, so that build actions themselves can still be sandboxed.

Attributes

name required

A unique name for the repository.

register optional; default is True

Whether to register the toolchains (must be set to False if bzlmod is enabled)


ghc_bindist

ghc_bindist(name, version, target, compiler_flags, ghcopts, haddock_flags, repl_ghci_args,
            cabalopts, locale, register)

Create a new repository from binary distributions of GHC.

The repository exports two targets:

  • a bin filegroup containing all GHC commands,
  • a threaded-rts CC library.

These targets are unpacked from a binary distribution specific to your platform. Only the platforms that have a “binary package” on the GHC download page are supported.

Examples

In WORKSPACE file:

load("@rules_haskell//haskell:ghc_bindist.bzl", "ghc_bindist")

# This repository rule creates @ghc repository.
ghc_bindist(
  name    = "ghc",
  version = "8.2.2",
)

Attributes

name required

A unique name for the repository.

version required

The desired GHC version.

target required
compiler_flags optional; default is None
ghcopts optional; default is None

see rules_haskell_toolchains

haddock_flags optional; default is None

see rules_haskell_toolchains

repl_ghci_args optional; default is None

see rules_haskell_toolchains

cabalopts optional; default is None

see rules_haskell_toolchains

locale optional; default is None

see rules_haskell_toolchains

register optional; default is True

Whether to register the toolchains (must be set to False if bzlmod is enabled)


ghc_bindist_toolchain_declaration

ghc_bindist_toolchain_declaration(target, bindist_name, toolchain_name)

Attributes

target required
bindist_name required
toolchain_name required

ghc_bindists_toolchain_declarations

ghc_bindists_toolchain_declarations(mctx, version)

Attributes

mctx required
version required

haskell_register_ghc_bindists

haskell_register_ghc_bindists(version, compiler_flags, ghcopts, haddock_flags, repl_ghci_args,
                              cabalopts, locale, register, targets)

Register GHC binary distributions for all platforms as toolchains.

See rules_haskell_toolchains.

Attributes

version optional; default is None

see rules_haskell_toolchains

compiler_flags optional; default is None
ghcopts optional; default is None

see rules_haskell_toolchains

haddock_flags optional; default is None

see rules_haskell_toolchains

repl_ghci_args optional; default is None

see rules_haskell_toolchains

cabalopts optional; default is None

see rules_haskell_toolchains

locale optional; default is None

see rules_haskell_toolchains

register optional; default is True

Whether to register the toolchains (must be set to False if bzlmod is enabled)

targets optional; default is ["darwin_amd64", "darwin_arm64", "linux_amd64", "linux_arm64", "windows_amd64"]

A list of target platforms to generate bindists for, e.g. ["linux_amd64", "windows_amd64"] (default: all)