Home Explore Blog Models CI



nixpkgs

doc/languages-frameworks/hare.section.md
6f079bede61431378d473648dbd644c9288682d708df70b60000000300000649
# Hare {#sec-language-hare}

## Building Hare programs with `hareHook` {#ssec-language-hare}

The `hareHook` package sets up the environment for building Hare programs by
doing the following:

1. Setting the `HARECACHE`, `HAREPATH` and `NIX_HAREFLAGS` environment variables;
1. Propagating `harec`, `qbe` and two wrapper scripts  for the hare binary.

It is not a function as is the case for some other languages --- *e. g.*, Go or
Rust ---, but a package to be added to `nativeBuildInputs`.

## Attributes of `hareHook` {#hareHook-attributes}

The following attributes are accepted by `hareHook`:

1. `hareBuildType`: Either `release` (default) or `debug`. It controls if the
   `-R` flag is added to `NIX_HAREFLAGS`.

## Example for `hareHook` {#ex-hareHook}

```nix
{
  hareHook,
  lib,
  stdenv,
}:
stdenv.mkDerivation {
  pname = "<name>";
  version = "<version>";
  src = "<src>";

  nativeBuildInputs = [ hareHook ];

  meta = {
    description = "<description>";
    inherit (hareHook) badPlatforms platforms;
  };
}
```

## Cross Compilation {#hareHook-cross-compilation}

`hareHook` should handle cross compilation out of the box. This is the main
purpose of `NIX_HAREFLAGS`: In it, the `-a` flag is passed with the architecture
of the `hostPlatform`.

However, manual intervention may be needed when a binary compiled by the build
process must be run for the build to complete --- *e. g.*, when using Hare's
`hare` module for code generation.

In those cases, `hareHook` provides the `hare-native` script, which is a wrapper
around the hare binary for using the native (`buildPlatform`) toolchain.

Chunks
e0033d14 (1st chunk of `doc/languages-frameworks/hare.section.md`)
Title: Building Hare Programs with `hareHook` in Nix
Summary
The `hareHook` package in Nix facilitates building Hare programs by setting up the necessary environment variables (`HARECACHE`, `HAREPATH`, `NIX_HAREFLAGS`) and propagating required tools like `harec` and `qbe`. It's included in `nativeBuildInputs` and accepts the `hareBuildType` attribute (defaulting to `release`) to control the `-R` flag in `NIX_HAREFLAGS`. `hareHook` is designed to handle cross-compilation automatically by passing the host platform's architecture via `NIX_HAREFLAGS`. For cases where a binary compiled during the build process needs to be executed, `hareHook` provides the `hare-native` script to use the native (buildPlatform) toolchain.