LinuxCommandLibrary

crystal

Compile and run Crystal programming language code

TLDR

Run a Crystal file

$ crystal [path/to/file.cr]
copy

Compile a file and all dependencies to a single executable
$ crystal build [path/to/file.cr]
copy

Read Crystal source code from the command-line or stdin, and execute it
$ crystal eval '[code]'
copy

Generate API documentation from inline docstrings in Crystal files
$ crystal docs
copy

Compile and run a Crystal specification suite
$ crystal spec
copy

Start a local interactive server for testing the language
$ crystal play
copy

Create a project directory for a Crystal application
$ crystal init app [application_name]
copy

Display all help options
$ crystal help
copy

SYNOPSIS

crystal [options] filename.cr

PARAMETERS

filename.cr
    The Crystal source code file to be compiled or executed.

--version
    Displays the version of the Crystal compiler.

build
    Compiles the Crystal program into an executable. Use `crystal build filename.cr`.

run
    Compiles and immediately executes the Crystal program. Use `crystal run filename.cr`.

--error-details
    Show detailed error messages including type information and source locations.

--release
    Compiles the program with optimizations enabled for a production release.

--target triple
    Specifies the target architecture for cross-compilation (e.g., x86_64-linux-gnu).

--link-flags flags
    Passes additional flags to the linker.

--verbose
    Enable verbose output for debugging compilation process.

DESCRIPTION

The `crystal` command is the primary interface for the Crystal programming language. It's used for compiling, running, and managing Crystal projects. This includes tasks like compiling Crystal source code into executable binaries, executing Crystal programs directly, running tests, and managing dependencies using shards. The Crystal compiler is known for its focus on performance, type safety, and developer productivity. The `crystal` command provides various flags and options to control the compilation process, specify output files, enable debugging information, and optimize for different target architectures. Furthermore, it handles linking against external libraries and frameworks required by the Crystal program. It aims to be easy to use and provide clear error messages, helping developers build robust and efficient applications.

SHARDS INTEGRATION

Crystal uses 'shards' as its dependency manager. While `crystal` itself doesn't directly manage shards, it interacts with the `shards` command to resolve and include external libraries.
You typically use `shards install` to download dependencies before using `crystal build` or `crystal run`.

HISTORY

Crystal is a relatively new programming language, first announced in 2011 and reaching version 1.0 in 2021. The `crystal` command has evolved alongside the language, gaining features and stability with each release. Early versions focused on basic compilation and execution. As the language matured, dependency management via `shards` became integrated. Continuous efforts have been made to improve compilation speed, error reporting, and support for different platforms.

SEE ALSO

shards(1)

Copied to clipboard