Start

Getting started

Build the compiler, point it at a .ts file, and run the native binary it writes.

Prefer not to build it yourself? Grab a prebuilt klainmain with the one-line installer on the Installation page, then skip straight to Compile and run a file — you'll still need clang on PATH.

Requirements

  • Go 1.26+ — to build the compiler itself.
  • clang (LLVM 15+, opaque-pointer support) — the backend that turns emitted IR into a binary.
  • Optional, linked only when your program uses the feature: libcurl (for fetch / http.listen), libnghttp2 (for http.listen), libpcre2 (for RegExp), OpenSSL 3 (for crypto.subtle / tls), bdw-gc (only for -mm=gc).

Build the compiler

shell
$ make build            # produces ./klainmain

Compile and run a file

Compiling produces a native binary next to the source — it does not run it.

shell
$ ./klainmain examples/basics/basics.ts   # → examples/basics/basics
$ ./examples/basics/basics                # run it yourself
$ ./klainmain -o myapp app.ts             # custom output name
$ ./klainmain --static -o myapp app.ts    # one self-contained binary (no external libs)

By default the binary links its non-libc dependencies (e.g. libcurl, pcre2) dynamically, so the target machine must have them — the same as any dynamically-linked program. To ship one self-contained binary that runs anywhere with nothing installed, add --static (works on Linux and Windows; see the CLI reference). It's how the showcase apps are built.

Your first program

const who: string = "native world";
console.log("hello, " + who);

Then:

shell
$ ./klainmain hello.ts
$ ./hello
hello, native world

Handy make targets

TargetDescription
make buildCompile the compiler to ./klainmain
make run FILE=f.tsCompile and run a single file
make compile FILE=f.tsCompile a file to a binary (don't run it)
make ir FILE=f.tsEmit LLVM IR only, no binary
make examplesCompile and run every example — the readable regression suite
make appsBuild every showcase app as a self-contained --static binary (asserts no external DLLs on Windows)