#Getting Started

Rig uses the same language for code that runs during compilation and code that runs in the finished program. Start with a small command, then move a value to compile time.

#Run Your First Program

Choose Run below. The project contains two files: main.rig defines the command, and io.rig provides a helper for writing output.

(require print:(Fn Text (Variant error:Null value:Null)) from="./io.rig") (provide run:(Fn (Variant error:Null value:Null)) as="wasi:cli/run@0.3.0") (define run:(Fn (Variant error:Null value:Null)) run=(fn do=(print "Hello, Rig!\n")))

You should see:

Hello, Rig!

Change the message in main.rig and run it again. Open sends all of the files, including your edits, to the playground for more room to experiment.

Use Chrome to build and run the examples. The first run takes longer because it loads the compiler.

#Read the Program

Parentheses group an expression. In (print "Hello, Rig!\n"), print is the function being called and the quoted text is its argument.

The three outer forms give the program its structure:

The type (Fn (Variant error:Null value:Null)) describes a function with no arguments. Its result is one of two cases: value for success or error for failure. Null means that neither case carries additional data. Here, run returns the result of print.

WASI defines standard interfaces between WebAssembly programs and their hosts. The host calls run, which uses the print helper in io.rig to write to WASI standard output.

#Compute During Compilation

Now run this version:

(require print:(Fn Text (Variant error:Null value:Null)) from="./io.rig") # Stage 1 computes the value embedded into the Stage 0 program. (define greeting:String_1 greeting="Hello from Stage 1!\n") (provide run:(Fn (Variant error:Null value:Null)) as="wasi:cli/run@0.3.0") (define run:(Fn (Variant error:Null value:Null)) run=(fn do=(print (text (inline (const greeting))))))

greeting:String_1 declares a string computed at Stage 1, during compilation. Text is the Stage 0 text type used by the running program.

Inside run, the message is produced by (text (inline (const greeting))).

const turns the compile-time value of greeting into checked code for a Stage 0 string. inline inserts that code into the Stage 0 expression, and text converts the string to the Text expected by print.

The resulting command prints Hello from Stage 1!. It does not look up the Stage 1 binding at runtime: its value has already been embedded during compilation. This separation is the starting point for staged programming, where ordinary Rig functions can compute values, construct types, and generate code.

#Install Rig

The installation commands below describe the intended distribution. Installers, Homebrew, and Cargo releases are not available yet; you can use the playground without them.

On macOS or Linux:

curl -LsSf https://rig-lang.org/install.sh | sh

On Windows, in PowerShell:

irm https://rig-lang.org/install.ps1 | iex

Alternatively, use Homebrew:

brew install rig-lang/tap/rig

Or with Cargo:

cargo install rig-cli

#Run and Build Locally

Save main.rig and io.rig from either example in the same directory.

These examples also need the WASI interface definitions. Download the interface package to vendor/wasi-cli.wasm, then create .rig/overrides.toml in your project directory:

[packages]
"wasi:cli@0.3.0" = "vendor/wasi-cli.wasm"

The override tells Rig where to find that exact package. The package contains interface definitions, not an output implementation: the host provides that. The playground supplies this setup automatically.

With Rig installed, run the command from your project directory:

rig run main.rig

To compile it without running it:

rig build main.rig

This writes main.wasm, a WebAssembly Component. A compatible command host can run it by providing its required WASI interfaces. The playground's Build button downloads the same kind of artifact.

#Next Steps