ESC
No recent searches
Search by
Reference  /  The Grain CLI

The Grain CLI

The Grain CLI is an all-in-one tool for compiling, running, documenting, and formatting all of your Grain programs.

Edit on GitHub

grain

The top level grain command will compile and run a Grain program. This can be useful during development for quick iteration cycles. The flags available for this command are equivalent to the flags for grain compile.

grain hello.gr

grain compile

Compiles a Grain program to WebAssembly.

grain compile hello.gr

All of the supported flags can be found below:

Flag: -I, —include-dirs
Description: add additional dependency include directories
Flag: -S, —stdlib
Description: override the standard libary with your own
Flag: —initial-memory-pages
Description: initial number of WebAssembly memory pages
Flag: —maximum-memory-pages
Description: maximum number of WebAssembly memory pages
Flag: —compilation-mode
Description: compilation mode (advanced use only)
Flag: —elide-type-info
Description: don’t include runtime type information used by toString/print
Flag: —release
Description: compile using the release profile (production mode)
Flag: —experimental-wasm-tail-call
Description: enables tail-call optimization
Flag: —debug
Description: compile with debugging information
Flag: —wat
Description: additionally produce a WebAssembly Text (.wat) file
Flag: —hide-locs
Description: hide locations from intermediate trees. Only has an effect with --verbose
Flag: —no-color
Description: disable colored output
Flag: —no-gc
Description: turn off reference counting garbage collection
Flag: —no-bulk-memory
Description: polyfill WebAssembly bulk memory instructions
Flag: —wasi-polyfill
Description: path to custom WASI implementation
Flag: —use-start-section
Description: replaces the _start export with a start section during linking
Flag: —no-link
Description: disable static linking
Flag: —no-pervasives
Description: don’t automatically import the Grain Pervasives module
Flag: —parser-debug-level
Description: debugging level for parser output
Flag: —memory-base
Description: set the base address for the Grain heap
Flag: —source-map
Description: generate source maps
Flag: —strict-sequence
Description: enable strict sequencing
Flag: —verbose
Description: print critical information at various stages of compilation
Flag: -h, —help
Description: display help for command

grain run

Runs a WebAssembly file. The grain run command can also run WebAssembly files produced by other compilers.

grain run hello.gr.wasm

It should be noted that grain run is used here on the WebAssembly file produced via grain compile.

grain doc

Produces documentation for a Grain program. See the full Graindoc page to learn more!

Generating docs for a single file on stdout:

grain doc hello.gr

Generating docs for a single file:

grain doc hello.gr -o hello.md

Generating docs for an entire project:

grain doc . -o .

grain format

Formats Grain files. Running grain format on a single file will write the formatted file on stdout, and the result can be written to a file via the -o flag. grain format can also be used on a directory to format all of the Grain files in a project.

Formatting a single file to stdout:

grain format hello.gr

Formatting a single file in place:

grain format hello.gr -o hello.gr

Formatting a project in place:

grain format . -o .

grain lsp

Starts a Grain language server. Generally, this command is used by your code editor to display information about your programs as you write them, and you never need to worry about using this command manually. You can learn more about the Language Server Protocol here.


Sign up for farm-to-inbox developer news

You can unsubscribe at any time. Read our privacy policy.

Copyright © 2024 The Grain Programming Language