CRYSTAL(1) | Crystal Compiler Command Line Reference Guide | CRYSTAL(1) |
NAME
crystal - compiler for the Crystal language
SYNOPSIS
crystal command [switches] programfile — [arguments]
DESCRIPTION
Crystal is a statically type-checked programming language. It was created with the beauty of Ruby and the performance of C in mind.
USAGE
You can compile and run a program by invoking the compiler with a single filename:
crystal some_program.cr
Crystal files usually end with the .cr extension, though this is not mandatory.
Alternatively you can use the run command:
crystal run some_program.cr
To create an executable use the build command:
crystal build some_program.cr
This will create an executable named "some_program".
Note that by default the generated executables are not fully optimized. To turn optimizations on, use the --release flag:
crystal build --release some_program.cr
Make sure to always use --release for production-ready executables and when performing benchmarks.
The optimizations are not turned on by default because the compile times are much faster without them and the performance of the program is still pretty good without them, so it allows to use the crystal command almost to be used as if it was an interpreter.
OPTIONS
The crystal command accepts the following options
init
init TYPE [DIR | NAME DIR]
Generates a new Crystal project.
TYPE is one of:
lib Creates a library skeleton
app Creates an application skeleton
This initializes the lib/app project folder as a git repository, with a license file, a README file, a shard.yml for use with shards (the Crystal dependency manager), a .gitignore file, and src and spec folders.
DIR - directory where project will be generated
NAME - name of project to be generated (default: basename of DIR)
Options:
-f, --force
-s, --skip-existing
build
build [options] [programfile] [--] [arguments]
Compile program.
Options:
--cross-compile
-d, --debug
--no-debug
-D FLAG, --define FLAG
--emit [asm|llvm-bc|llvm-ir|obj]
--frame-pointers [auto|always|non-leaf]
-f text|json, --format text|json
--error-trace
--ll
--link-flags FLAGS
--mcpu CPU
--mattr CPU
--mcmodel default|kernel|tiny|small|medium|large
--no-color
--no-codegen
-o
--prelude
-O LEVEL
--release
--error-trace
-s, --stats
-p, --progress
-t, --time
--single-module
--threads NUM
--target TRIPLE
--verbose
--static
--stdin-filename FILENAME
docs
Generate documentation from comments using a subset of markdown. The output is saved in html format on the created docs/ folder. More information about documentation conventions can be found at https://crystal-lang.org/docs/conventions/documenting_code.html.
Options:
--project-name NAME
In case no default can be found, this option is mandatory.
--project-version VERSION
In case no default can be found, this option is mandatory.
--json-config-url URL
--source-refname REFNAME
If this option is missing and can’t be automatically determined, the generator can’t produce source code links.
--source-url-pattern URL
Supported replacement tags:
%{refname}
%{path}
%{filename}
%{line}
If this option is missing and can’t be automatically determined, the generator can’t produce source code links.
-o DIR, --output DIR
-b URL, --canonical-base-url URL
-b URL, --sitemap-base-url URL
--sitemap-priority PRIO
--sitemap-changefreq FREQ
env
env [variables]
Print Crystal-specific environment variables in a format compatible with shell scripts. If one or more variable names are given as arguments, it prints only the value of each named variable on its own line.
Variables:
CRYSTAL_CACHE_DIR
CRYSTAL_EXEC_PATH
CRYSTAL_LIBRARY_PATH
CRYSTAL_PATH
CRYSTAL_VERSION
eval
eval [options] [source]
Evaluate code from arguments or, if no arguments are passed, from the standard input. Useful for experiments.
Options:
-d, --debug
--no-debug
-D FLAG, --define FLAG
--error-trace
-O LEVEL
--release
-s, --stats
-p, --progress
-t, --time
--no-color
play
play [options] [file]
Starts the crystal playground server on port 8080, by default.
Options:
-p PORT, --port PORT
-b HOST, --binding HOST
-v, --verbose
run
run [options] [programfile] [--] [arguments]
The default command. Compile and run program.
Options: Same as the build options.
spec
spec [options] [files]
Compile and run specs (in spec directory).
Options:
-d, --debug
--no-debug
-D FLAG, --define FLAG
--error-trace
-O LEVEL
--release
-s, --stats
-p, --progress
-t, --time
--no-color
tool
tool [tool] [switches] [programfile] [--] [arguments]
Run a tool. The available tools are: context, dependencies, expand, flags, format, hierarchy, implementations, types, and unreachable.
Tools:
context
dependencies
Options:
-D FLAG, --define=FLAG
-f FORMAT, --format=FORMAT
-i PATH, --include=PATH
-e PATH, --exclude=PATH
--error-trace
--prelude
--verbose
expand
flags
format
hierarchy
implementations
types
unreachable
Output fields:
count
location
lines
Options:
-D FLAG, --define=FLAG
-f FORMAT, --format=FORMAT
--tallies
--check
-i PATH, --include=PATH
-e PATH, --exclude=PATH
--error-trace
--prelude
clear_cache
Clear the compiler cache (located at 'CRYSTAL_CACHE_DIR').
help
Show help. Option --help or -h can also be added to each command for command-specific help.
version
Show version.
OPTIMIZATIONS
The optimization level specifies the codegen effort for producing optimal code. It’s a trade-off between compilation performance (decreasing per optimization level) and runtime performance (increasing per optimization level).
Production builds should usually have the highest optimization level. Best results are achieved with --release which also implies --single-module
-O0
-O1
-O2
-O3
-Os
-Oz
ENVIRONMENT VARIABLES
CRYSTAL_CACHE_DIR
Defines path where Crystal caches partial compilation results for faster subsequent builds. This path is also used to temporarily store executables when Crystal programs are run with 'crystal run' rather than 'crystal build'.
CRYSTAL_EXEC_PATH
Determines the path where crystal looks for external sub-commands.
CRYSTAL_LIBRARY_PATH
Defines paths where Crystal searches for (binary) libraries. Multiple paths can be separated by ":". These paths are passed to the linker as -L flags.
The pattern '$ORIGIN' at the start of the path expands to the directory where the compiler binary is located. For example, '$ORIGIN/../lib/crystal' resolves the standard library path relative to the compiler location in a generic way, independent of the absolute paths (assuming the relative location is correct).
CRYSTAL_PATH
Defines paths where Crystal searches for required source files. Multiple paths can be separated by ":".
The pattern '$ORIGIN' at the start of the path expands to the directory where the compiler binary is located. For example, '$ORIGIN/../share/crystal/src' resolves the standard library path relative to the compiler location in a generic way, independent of the absolute paths (assuming the relative location is correct).
CRYSTAL_OPTS
Defines options for the Crystal compiler to be used besides the command line arguments. The syntax is identical to the command line arguments. This is handy when using Crystal in build setups, for example 'CRYSTAL_OPTS=--debug make build'.
SEEALSO
https://crystal-lang.org/ The official web site.
https://github.com/crystal-lang/crystal Official Repository.
2025-02-14 | crystal 1.16.0-dev |