Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Tooling Reference

Rock applications use one project command: rock. Run it from the directory containing rock.toml so it can resolve the entry source, path dependencies, standard library, and build outputs.

Create a project

Create a project directory containing this rock.toml:

[crate]
name = "rock_book_project"
version = "0.1.0"

[[bin]]
path = "main.rk"

Create main.rk beside it:

main = !->
    "rock-book-project".println!

[[bin]] declares a binary target; an omitted name defaults to the package name. That binary defaults to src/main.rk; the explicit path above selects a file beside the manifest. A differently named binary defaults to src/bin/<name>.rk. A package may declare one [lib], defaulting to src/lib.rk, and any number of [[bin]] targets. At least one target is required, binary names must be unique, and each target may override path.

Everyday commands

$ rock format
$ rock build
$ rock run -- 7
$ rock expand
$ rock clean

format rewrites the library entry, or the first binary entry when there is no library. Inspect formatter changes before committing them, then compile again.

build resolves the manifest and path dependencies, then builds the library and all binaries. It writes a reusable .rkca artifact and object for the library, and one executable per binary, printing each output path. Binaries require main; the library does not. Executables are named after their binary targets, and intermediate outputs are isolated per target even when several entry files are called main.rk.

run builds and executes the only binary, or selects one with rock run --bin <name> -- <arguments>. With several binaries and no selection, it lists the choices and fails rather than choosing arbitrarily. Only the selected binary, the package library, and their dependencies are built. For a library-only package, it builds, reports that there is no binary to execute, and exits successfully. A failed build still fails the command. Values after -- are application arguments rather than options to the build tool.

expand prints macro-expanded source for the package’s library, or its first binary when there is no library. It is useful when a diagnostic points into generated declarations or when a repetition does not produce the expected items.

Path dependencies must provide a library target. Their binaries are not built when they are used as dependencies. A package’s binaries can import its own library using the package name, just like an external dependency.

There is no rock test command. Use a complete Rock executable as an application smoke test, or use the Rust integration suite when changing the compiler itself.

Lint levels

rock build and rock run report warnings for unused code from three lints: unused_imports, unused_variables, and dead_code. The group unused names all three. Every lint warns by default:

$ rock build -A unused_imports
$ rock build -W dead_code
$ rock run -D unused
FlagLong formEffect
-A <lint>--allowSilence the lint
-W <lint>--warnReport it as a warning (the default)
-D <lint>--denyReport it as an error and fail the build

Flags may be repeated and are applied in command-line order, so a later flag overrides an earlier one for the same lint. An unknown lint name is an error. The levels apply to the project’s own crate; dependencies are not linted. rockc accepts the same flags. Prefixing a binding or parameter with _ silences unused_variables for that name. Editors and Diagnostics explains each lint with examples.

Debug and release builds

rock build and rock run use the debug profile by default for both binary and library crates. This profile disables optimization; you can also select it explicitly with --debug. Use --release to enable full optimization for the project and its source-built dependencies:

$ rock build
$ rock build --debug
$ rock build --release
$ rock run --release -- 7

Debug outputs live in build/debug/, and release outputs live in build/release/. Each profile has its own dependency artifacts and objects, so switching profiles does not reuse products built with different optimization settings. The toolchain’s precompiled standard library is shared between profiles. --debug and --release cannot be combined.

Source-built dependencies use build/<profile>/deps/ inside the current project, not build directories beside dependency sources. Each dependency gets a directory identified by its name, version, and source-path hash, so object files with the same entry filename do not overwrite one another.

For compiler contributors and artifact-level workflows, rockc accepts the same flags. Unlike rock, it takes an entry file and explicit dependency artifacts rather than resolving rock.toml:

$ rockc --entry-file main.rk --extern-artifact std=build/std.rkca --debug
$ rockc --entry-file main.rk --extern-artifact std=build/std.rkca --release

rockc writes to its configured --output-dir (default: build/); rock chooses the profile-specific directories. cargo build --release optimizes the Rust compiler executable itself; use rock build --release, rock run --release, or rockc --release to optimize the Rock program being compiled.

When building a reusable .rkca directly with rockc, use --emit-artifact PATH with both --crate-type lib and --no-link. Binary targets cannot emit reusable crate artifacts. Package builds select the crate type and output flags for you.

For compiler performance investigations, set ROCK_TIME_PHASES=1 when running rockc to print per-phase wall-clock timings. scripts/bench_phases.sh collects timings and LLVM IR sizes for std and selected examples.

Cleaning build output

Run this from the directory containing the project’s rock.toml:

$ rock clean

clean removes the whole project build/ directory, including debug and release products and their dependency caches. It preserves source files, other projects’ build directories, and the installed standard library. The next build recompiles source-built dependencies. Cleaning an already-clean project succeeds without doing anything; a symlink or regular file named build is rejected rather than followed or removed.

Build directories left in dependency trees by earlier builds are not deleted automatically. To remove one explicitly, run rock clean from that dependency’s project directory.

Standard library selection

The active toolchain supplies a matching precompiled standard library. rock loads it automatically for ordinary projects and makes the prelude available. A package can opt out explicitly:

[crate]
name = "bare"
version = "0.1.0"
no_std = true

[lib]
path = "lib.rk"

Without the standard library, familiar operators, collections, strings, and prelude traits are unavailable unless the package supplies alternatives through explicit dependencies.

rockup

rockup installs and selects local Rock toolchains. A source checkout can be packaged and installed with:

$ cargo build --release
$ target/release/rockup dev std package \
    --path std \
    --sysroot target/release
$ target/release/rockup install dev --path target/release
$ target/release/rockup default dev
$ target/release/rockup list

The first installed toolchain becomes the default automatically; rockup default switches it explicitly. Toolchain shims keep the user workflow on rock while selecting matching compiler and standard-library components behind the project command.

Language server

rock-lsp communicates over standard input and output. Configure an LSP client to launch it for .rk files with language identifier rock; it is not a replacement for the application command rock.

CapabilityCurrent behavior
DiagnosticsRefresh on open, change, and save using source frontend analysis; messages include available codes, notes, help, and related locations.
HoverInferred variable and expression types, function signatures, and supported type, field, variant, and generic symbols.
Signature helpCall signature and active parameter information; a comma is the automatic trigger. Clients can also request it explicitly.
Inlay type hintsInferred types after unannotated local binding names in the requested range; requires successful analysis of the current buffer version.
Project discoveryNearest ancestor rock.toml; uses its entry graph, path dependency artifacts, and toolchain standard library.
Unsaved sourceOpen buffers overlay files in the entry graph; unopened files come from disk.

The server does not advertise completion, go-to-definition, references, rename, code actions, semantic tokens, or document formatting. Use rock format for the configured entry file and rock build for full validation, including borrow checking and linking.

Diagnostics are currently published to open documents, not as a complete workspace problem index. Hover and signature help require a successful analysis snapshot; during an invalid edit they may use the last successful snapshot and can be stale. Project resolution is cached until a Rock document is saved or the server restarts; there is no manifest/dependency file-watcher refresh. Save dependency changes and restart if feedback remains out of date.

The server accepts these explicit overrides:

ArgumentMeaning
--extern-artifact name=/absolute/path/to/crate.rkcaAdd an artifact or override a discovered artifact with the same crate name; repeat for multiple crates.
--no-preludeDisable dependency-provided prelude injection. This does not disable project dependency resolution.

These options are for standalone or compiler-development workflows, not normal application setup. Outside a project, the server uses the opened file as its entry and does not discover a standard library automatically. Within a project, [crate].no_std = true also disables automatic standard-library/prelude use.

Neovim plugin

The plugin lives in rock.nvim. It requires Neovim 0.11 or newer and uses vim.lsp.config and vim.lsp.enable, without an additional Lua dependency. Clone that repository, then add its root in init.lua (replace the path with your checkout):

vim.opt.runtimepath:prepend("/absolute/path/to/rock.nvim")
require("rock").setup()

The plugin registers .rk as filetype rock. Its client root markers are rock.toml and then .git, and standalone buffers are allowed; a Git root alone does not supply project dependencies.

Setup optionMeaning
cmdServer command string or argument list; overrides automatic executable selection.
extern_artifactsTable mapping crate names to artifact paths; becomes repeated --extern-artifact arguments.
no_preludePass --no-prelude; defaults to false.
autostartEnable the LSP configuration during setup; defaults to true.
serverAdditional native vim.lsp.Config fields; server.cmd is used only when top-level cmd is absent.

The default server is rock-lsp from PATH. To use a compiler-development build instead, set cmd to its absolute executable path.

Use :checkhealth rock to check prerequisites, :RockLspInfo to inspect the resolved configuration and clients, and :RockLspRestart to restart Rock clients. See Editors and Diagnostics for local-checkout setup and explicit hover/diagnostic commands.

Reading diagnostics

Source diagnostics carry a primary location and may include secondary labels in other files. Available diagnostic families include parser, resolve, type, borrow, artifact, and toolchain; these classify the failure rather than identify a unique error number. Notes explain context, while help messages suggest a next step. Neither is present on every error.

File, project, artifact, and toolchain failures need not have a source underline. When source text is unavailable, the terminal fallback can show a path and byte range instead of a source excerpt. In the editor, non-source project or toolchain messages can appear at the start of a buffer; that position is not evidence of an error on its first line. Use the message and named path to decide whether to fix source or setup.

The diagnostics walkthrough includes deliberately incorrect programs and their corrections. There is no rock JSON-diagnostic flag documented by the current project CLI.

Tree-sitter grammar

Clone the separate tree-sitter-rock repository to develop the grammar:

$ git clone https://github.com/rock-lang-org/tree-sitter-rock.git
$ cd tree-sitter-rock
$ tree-sitter generate
$ tree-sitter build
$ tree-sitter test

It contains highlight and indentation queries for editor integrations. Tree-sitter installation is separate from the native LSP plugin: require("rock").setup() does not install a parser or enable Tree-sitter highlighting. Syntax highlighting does not perform type or borrow checking. There is still no package-registry workflow.