Usage / Getting started

Getting started

This page gets you from “a file” to “a runnable program”, and points you at the docs you’ll use most often.

If you already have a silk binary on your PATH, start with “Write a program”.

If you don’t, see “Build from source” for the reference compiler workflow.

Write a program#

Create hello.slk:

import { println } from "std/io";

fn main () -> int {
  println("hello from silk");
  return 0;
}

Run the normal loop:

silk check hello.slk
silk test hello.slk
silk build hello.slk -o build/hello
./build/hello

If you prefer a step-by-step walkthrough, start here:

Packages (silk.toml)#

For larger projects, describe the module set in silk.toml and use --package:

silk check --package .
silk test  --package .
silk build --package .
silk package inspect --package .
silk package lint --package .

Use inspect to confirm the package name, version, definitions, dependencies, and declared artifacts. Use lint before installation or publication to catch missing definition files, bad artifact paths, or incomplete [dist] coverage.

Reference:

Build from source (reference compiler)#

The reference Silk compiler/toolchain requires Zig 0.16.0 on PATH.

From the Silk compiler repository root:

zig version
make build
export PATH="$PWD/build/bin:$PATH"

This builds missing hosted dependencies on supported native hosts and stages a repo-local toolchain. Among its outputs are:

  • build/bin/silk (the CLI)
  • build/bin/silk-lsp (the language server)
  • build/lib/libsilk.a (the C ABI library)
  • build/lib/silk/std/libsilk_std.a (the prebuilt stdlib archive on supported native hosts)
  • build/share/silk/std/ and build/share/man/ (stdlib sources and manpages)

For a compiler-only Zig build or a custom staging prefix, use:

zig build
zig build install --prefix build

To fetch or rebuild only the pinned hosted dependency archives:

make deps

On Linux x86_64, Linux AArch64, and Apple Silicon macOS, make build stages the native toolchain and hosted libraries together. If a static Z3 archive is unavailable, select a dynamic solver with --z3-lib <path> or SILK_Z3_LIB.

Reference: Built-in dependencies

Troubleshooting#

  • If a command fails, look up the error code in: Diagnostics
  • If you hit backend/toolchain limits, start with: Limits

Where to go next#

Source repository · Edit this page · View Markdown

Quick links

Type to search across the site. Use the up and down arrow keys to choose a result, Enter to open it, and Escape to close.