# porting-hare.md -rw-r--r-- 2.4 KiB View raw

#Porting Hare to your OS

Hare upstream expects to use ELF. You can work around this but YMMV.

The standard library expects a reasonably Unix-like environment. However, you can build your own standard library relatively easily and vendor or fork various portable bits of the stdlib. This can go a long ways, Mercury does this and provides a comfortable Hare environment with relatively little effort.

#Cross compiling

Configure Hare for your build host normally:

https://harelang.org/installation/

Then start porting the standard library. Start by porting rt, the runtime. The minimal port requires your target support code at rt/+target. Add the following:

This should be sufficient to build simple Hare programs that use syscall wrappers directly, such as this one for Linux:

use rt;

export fn main() void = {
	const bytes = tobytes("Hello world!\n");
	rt::write(0, &bytes[0], len(bytes))!;
};

fn tobytes(s: str) []u8 = *(&s: *[]u8);

You can cross-compile this for your target like so:

$ hare build -o example -X^ -T+target [-t $arch] main.ha

Then port other stdlib modules as you see fit. Many modules, such as bytes or ascii, are portable. Others, such as crypto and time, are mostly portable. Some are not portable and will need to be ported to your target, including notably:

Good luck!

#Native toolchain

You need:

The steps are:

  1. Port qbe to your target
  2. Port harec to your target
  3. Port the minimal rt to your target
    • Update rt/configure as necessary
    • mkdir rt/+target
    • Write an entry point at rt/+target/start+$arch.s
    • Add syscall wrappers and other required bits
  4. Get the test suite to pass