Repository navigation
Getting Started
This guide covers building the H toolchain from source, installing it standalone with scripts/install.sh, running tests, and configuring projects with h.toml.
-
Zig 0.17.1+ — builds the frozen bootstrap seed compiler (
hlc) and C seed runtime (libhl_runtime.a) -
LLVM 19–23 (
libLLVM-19throughlibLLVM-23, orlibLLVM) — native IR verification, optimization (LLVMRunPasses), DWARF debug generation, and object emission.build.zigauto-detects the installed LLVM viallvm-config-23..llvm-config-19orllvm-config, and accepts explicit overrides-Dllvm-lib=<name>and-Dllvm-libdir=<dir> -
GCC (
gcc) — links emitted.oobject files with the runtime and system libraries -
Boehm GC (
libgc), standard math (libm), and POSIX threads (libpthread)
Only required if you build and run the corresponding interop examples or projects:
-
C++ (
g++with C++17 &libstdc++) — forhl-bindgen-cppshims (examples/cpp_interop/) -
LDC (
ldc2,libdruntime-ldc-shared,libphobos2-ldc-shared) — for GC-enabled D modules (examples/d_interop/) -
Objective-C runtime (
libobjc/ GNUsteplibobjc2) — forstd/interop/objc(examples/objc_interop/) -
.NET SDK +
libhostfxr— for CoreCLR C# and F# hosting (examples/dotnet_interop/)
Clone the repository and use build.zig to drive the bootstrap and self-hosting builds:
git clone https://github.com/buntatoes/h-lang.git
cd h-langzig build testThis builds the frozen Zig bootstrap seed (zig-out/bin/hlc) and C seed runtime (zig-out/lib/libhl_runtime.a), then runs the full compiler, runtime, interop, and fixed-point self-hosting test suite in src/tests.zig.
To target a non-default LLVM installation explicitly:
zig build self-host -Dllvm-lib=LLVM-20 -Dllvm-libdir=/usr/lib/llvm-20/libzig build self-hostThis executes the self-hosting sequence:
- Compiles
compiler/main.hlwith./zig-out/bin/hlc(linked against the detected LLVM shared library) intozig-out/bin/hlc-self. - Compiles
runtime/hl_runtime.hlwith./zig-out/bin/hlc-self -cinto the pure-H runtime objectzig-out/lib/libhl_runtime_h.o. - Compiles
compiler/with./zig-out/bin/hlc-selfagainstzig-out/lib/libhl_runtime_h.ointozig-out/bin/hlc-pure.
zig build fixed-pointCompiles compiler/ a second time using zig-out/bin/hlc-pure to produce zig-out/bin/hlc-pure2 and runs cmp zig-out/bin/hlc-pure zig-out/bin/hlc-pure2 to verify bit-for-bit identical ELF output.
zig build toolsCompiles the three pure-H tools in tools/ using hlc-pure and libhl_runtime_h.o:
-
zig-out/bin/hl-bindgen-cpp— C++ header shim and H binding generator -
zig-out/bin/hlfmt— canonical H source formatter -
zig-out/bin/hl-lsp— zero-LLVM Language Server Protocol server over stdio
zig build htestExecutes ./zig-out/bin/hlc-pure test tests/ --runtime zig-out/lib/libhl_runtime_h.o to run all *_test.hl test suites (tests/core_lang_test.hl, tests/stdlib_full_test.hl, and tests/http_and_ergonomics_test.hl).
Use scripts/install.sh to install the self-hosted H toolchain so hlc, hlfmt, hl-lsp, and hl-bindgen-cpp work from any directory:
./scripts/install.sh [--prefix=<dir>] [--no-build]By default PREFIX is $HOME/.local. Unless --no-build is passed, the script builds zig build self-host && zig build tools automatically if the binaries are missing, then installs:
-
$PREFIX/bin/hlc(installed fromzig-out/bin/hlc-pure) $PREFIX/bin/hlfmt$PREFIX/bin/hl-lsp$PREFIX/bin/hl-bindgen-cpp$PREFIX/share/h/libhl_runtime_h.o-
$PREFIX/share/h/std/(all standard library modules andstd/interop/)
Ensure $PREFIX/bin is on your PATH.
hlc does not require running from the repository root. At startup it resolves H_HOME in order:
-
$H_HOMEenvironment variable (if it containsstd/math.hlorlibhl_runtime_h.o) - Relative to the running binary's own path via
/proc/self/exe:-
<exe_dir>/../share/h(installed layout frominstall.sh) -
<exe_dir>/../..(repository checkout layoutzig-out/bin/hlc-pure) <exe_dir>
-
- Current working directory (
.)
Additional module search directories can always be passed with -I <dir>.
Create hello.hl:
def main() -> I32
name = "H"
puts("Hello from #{name}!")
0
endCompile and run immediately (using installed hlc, or ./zig-out/bin/hlc-pure from a repo checkout):
hlc run hello.hlCompile to a standalone native binary:
hlc hello.hl -o hello
./helloInspect the generated LLVM IR without linking:
hlc --emit-llvm hello.hlCompile with DWARF debug information (defaults to -O0 when -g is passed without an explicit -O* flag):
hlc -g hello.hl -o hello_dbgCompile a multi-file directory containing main.hl:
hlc examples/modules/ -o modules_demoWhen given a directory path, hlc checks for <dir>/h.toml first and otherwise resolves <dir>/main.hl.
The hlc test subcommand discovers *_test.hl files in a directory (or compiles a single .hl test file), finds every zero-parameter non-generic function whose name begins with test_, generates a temporary harness importing std/test, compiles and executes it, and reports per-test pass/fail status.
Example math_test.hl:
import test
import math
def test_gcd_and_pow() -> Void
test.assert_eq(math.gcd(84, 36), 12, "gcd(84, 36)")
test.assert_eq(math.pow_i64(2, 10), 1024, "2^10")
endRun it:
hlc test math_test.hl
hlc test tests/When hlc build or hlc run is invoked with no file argument (or with a directory path containing h.toml), the compiler reads h.toml from that directory.
| Key / Section | Type | Description |
|---|---|---|
name |
String | Default output binary name for hlc build (ignored if -o is passed or during hlc run) |
entry |
String | Relative path to the entry .hl source file (resolved relative to the manifest directory) |
opt |
Integer (0–3) |
Default optimization level (-O0 through -O3) unless overridden on the CLI |
debug |
Boolean (true / false) |
Enables -g DWARF debug emission when true
|
libs |
String | Space-separated libraries or linker flags (bare names like sqlite3 become -lsqlite3; flags starting with - such as -L/opt/lib are passed verbatim) |
[dependencies] |
Section | Maps package names to local directory paths (mylib = "../mylib"), resolved relative to the manifest directory |
For a dependency mylib = "../mylib", import mylib checks ../mylib/lib.hl, then ../mylib/mylib.hl, then ../mylib/main.hl; submodule imports such as import "mylib/util" as util resolve ../mylib/util.hl.
[package]
name = "myapp"
entry = "src/main.hl"
opt = 2
debug = false
libs = "z curl"
[dependencies]
mylib = "../mylib"With h.toml in the current directory:
# Compiles src/main.hl at -O2, resolves [dependencies], links -lz -lcurl, outputs ./myapp
hlc build
# Compiles to a temporary binary and runs it immediately
hlc run
# CLI flags override manifest defaults
hlc build -g -O0 -o myapp_dbgReady-to-use editor configurations are provided under editors/ for VS Code (editors/vscode/) and Neovim (editors/neovim/h.lua), integrating .hl syntax highlighting, hlfmt, and live semantic diagnostics from hl-lsp. See Tooling and LSP for installation steps.
Next: Language Guide