'\" t .\" Title: crystal .\" Author: [see the "AUTHOR(S)" section] .\" Generator: Asciidoctor 2.0.23 .\" Date: 2025-02-14 .\" Manual: Crystal Compiler Command Line Reference Guide .\" Source: crystal 1.16.0-dev .\" Language: English .\" .TH "CRYSTAL" "1" "2025-02-14" "crystal 1.16.0\-dev" "Crystal Compiler Command Line Reference Guide" .ie \n(.g .ds Aq \(aq .el .ds Aq ' .ss \n[.ss] 0 .nh .ad l .de URL \fI\\$2\fP <\\$1>\\$3 .. .als MTO URL .if \n[.g] \{\ . mso www.tmac . am URL . ad l . . . am MTO . ad l . . . LINKSTYLE blue R < > .\} .SH "NAME" crystal \- compiler for the Crystal language .SH "SYNOPSIS" .sp \fBcrystal\fP command [switches] programfile \(em [arguments] .SH "DESCRIPTION" .sp Crystal is a statically type\-checked programming language. It was created with the beauty of Ruby and the performance of C in mind. .SH "USAGE" .sp You can compile and run a program by invoking the compiler with a single filename: .sp .if n .RS 4 .nf .fam C crystal some_program.cr .fam .fi .if n .RE .sp Crystal files usually end with the .cr extension, though this is not mandatory. .sp Alternatively you can use the run command: .sp .if n .RS 4 .nf .fam C crystal run some_program.cr .fam .fi .if n .RE .sp To create an executable use the build command: .sp .if n .RS 4 .nf .fam C crystal build some_program.cr .fam .fi .if n .RE .sp This will create an executable named "some_program". .sp Note that by default the generated executables are not fully optimized. To turn optimizations on, use the \fB\-\-release\fP flag: .sp .if n .RS 4 .nf .fam C crystal build \-\-release some_program.cr .fam .fi .if n .RE .sp Make sure to always use \fB\-\-release\fP for production\-ready executables and when performing benchmarks. .sp 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 \fBcrystal\fP command almost to be used as if it was an interpreter. .SH "OPTIONS" .sp The \fBcrystal\fP command accepts the following options .SS "init" .sp \fBinit\fP TYPE [DIR | NAME DIR] .sp Generates a new Crystal project. .sp TYPE is one of: .sp \fBlib\fP Creates a library skeleton .br \fBapp\fP Creates an application skeleton .sp 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. .sp DIR \- directory where project will be generated .sp NAME \- name of project to be generated (default: basename of DIR) .sp Options: .sp \fB\-f, \-\-force\fP .RS 4 Force overwrite existing files. .RE .sp \fB\-s, \-\-skip\-existing\fP .RS 4 Skip existing files. .RE .SS "build" .sp \fBbuild\fP [options] [programfile] [\-\-] [arguments] .sp Compile program. .sp Options: .sp \fB\-\-cross\-compile\fP .RS 4 Generate an object file for cross compilation and prints the command to build the executable. The object file should be copied to the target system and the printed command should be executed there. This flag mainly exists for porting the compiler to new platforms, where possible run the compiler on the target platform directly. .RE .sp \fB\-d\fP, \fB\-\-debug\fP .RS 4 Generate the output with symbolic debug symbols. These are read when debugging the built program with tools like lldb, gdb, valgrind etc. and provide mappings to the original source code for those tools. .RE .sp \fB\-\-no\-debug\fP .RS 4 Generate the output without any symbolic debug symbols. .RE .sp \fB\-D\fP \fIFLAG\fP, \fB\-\-define\fP \fIFLAG\fP .RS 4 Define a compile\-time flag. This is useful to conditionally define types, methods, or commands based on flags available at compile time. The default flags are from the target triple given with \fB\-\-target\-triple\fP or the hosts default, if none is given. .RE .sp \fB\-\-emit\fP [asm|llvm\-bc|llvm\-ir|obj] .RS 4 Comma separated list of types of output for the compiler to emit. You can use this to see the generated LLVM IR, LLVM bitcode, assembly, and object files. .RE .sp \fB\-\-x86\-asm\-syntax\fP [att|intel] .RS 4 Select the assembly dialect for \fB\-\-emit=asm\fP. The default is \f(CRatt\fP, which stands for the AT&T syntax supported by tools like the GNU Assembler. \f(CRintel\fP selects the Intel syntax which is preferred for Windows tools. .RE .sp \fB\-\-frame\-pointers\fP [auto|always|non\-leaf] .RS 4 Control the preservation of frame pointers. The default value, \f(CR\-\-frame\-pointers=auto\fP, will preserve frame pointers on debug builds and try to omit them on release builds (certain platforms require them to stay enabled). \f(CR\-\-frame\-pointers=always\fP will always preserve them, and non\-leaf will only force their preservation on non\-leaf functions. .RE .sp \fB\-f\fP text|json, \fB\-\-format\fP text|json .RS 4 Format of output. Defaults to text. The json format can be used to get a more parser\-friendly output. .RE .sp \fB\-\-error\-trace\fP .RS 4 Show full error trace. Disabled by default, as the full trace usually makes error messages less readable and may not always deliver relevant information. .RE .sp \fB\-\-ll\fP .RS 4 Dump LLVM assembly file to output directory. .RE .sp \fB\-\-link\-flags\fP \fIFLAGS\fP .RS 4 Pass additional flags to the linker. Though you can specify those flags on the source code, this is useful for passing environment specific information directly to the linker, like non\-standard library paths or names. For more information on specifying linker flags on source, you can read the "C bindings" section of the documentation available on the official web site. .RE .sp \fB\-\-mcpu\fP \fICPU\fP .RS 4 Specify a specific CPU to generate code for. This will pass a \-mcpu flag to LLVM, and is only intended to be used for cross\- compilation. For a list of available CPUs, pass \-\-mcpu help when building any Crystal source code. Passing \-\-mcpu native will pass the host CPU name to tune performance for the host. .RE .sp \fB\-\-mattr\fP \fICPU\fP .RS 4 Override or control specific attributes of the target, such as whether SIMD operations are enabled or not. The default set of attributes is set by the current CPU. This will pass a \-mattr flag to LLVM, and is only intended to be used for cross\-compilation. For a list of available attributes, invoke "llvm\-as < /dev/null | llc \-march=xyz \-mattr=help". .RE .sp \fB\-\-mcmodel\fP default|kernel|tiny|small|medium|large .RS 4 Specifies a specific code model to generate code for. This will pass a \-\-code\-model flag to LLVM. .RE .sp \fB\-\-no\-color\fP .RS 4 Disable colored output. .RE .sp \fB\-\-no\-codegen\fP .RS 4 Don\(cqt do code generation, just parse the file. .RE .sp \fB\-o\fP .RS 4 Specify filename of output. .RE .sp \fB\-\-prelude\fP .RS 4 Specify prelude to use. The default one initializes the garbage collector. You can also use \-\-prelude=empty to use no preludes. This can be useful for checking code generation for a specific source code file. .RE .sp \fB\-O\fP \fILEVEL\fP .RS 4 Optimization mode: 0 (default), 1, 2, 3. See \fBOPTIMIZATIONS\fP for details. .RE .sp \fB\-\-release\fP .RS 4 Compile in release mode. Equivalent to \fB\-O3 \-\-single\-module\fP .RE .sp \fB\-s\fP, \fB\-\-stats\fP .RS 4 Print statistics about the different compiler stages for the current build. Output time and used memory for each compiler process. .RE .sp \fB\-p\fP, \fB\-\-progress\fP .RS 4 Print statistics about the progress for the current build. .RE .sp \fB\-t\fP, \fB\-\-time\fP .RS 4 Print statistics about the execution time. .RE .sp \fB\-\-single\-module\fP .RS 4 Generate a single LLVM module. By default, one LLVM module is created for each type in a program. \fB\-\-release\fP implies this option. .RE .sp \fB\-\-threads\fP \fINUM\fP .RS 4 Maximum number of threads to use for code generation. The default is 8 threads. .RE .sp \fB\-\-target\fP \fITRIPLE\fP .RS 4 Enable target triple; intended to use for cross\-compilation. See llvm documentation for more information about target triple. .RE .sp \fB\-\-verbose\fP .RS 4 Display the commands executed by the system. .RE .sp \fB\-\-static\fP .RS 4 Create a statically linked executable. .RE .sp \fB\-\-stdin\-filename\fP \fIFILENAME\fP .RS 4 Source file name to be read from STDIN. .RE .SS "docs" .sp 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 \c .URL "https://crystal\-lang.org/docs/conventions/documenting_code.html" "" "." .sp Options: .sp \fB\-\-project\-name\fP \fINAME\fP .RS 4 Set the project name. The default value is extracted from shard.yml if available. .sp In case no default can be found, this option is mandatory. .RE .sp \fB\-\-project\-version\fP \fIVERSION\fP .RS 4 Set the project version. The default value is extracted from current git commit or shard.yml if available. .sp In case no default can be found, this option is mandatory. .RE .sp \fB\-\-json\-config\-url\fP \fIURL\fP .RS 4 Set the URL pointing to a config file (used for discovering versions). .RE .sp \fB\-\-source\-refname\fP \fIREFNAME\fP .RS 4 Set source refname (e.g. git tag, commit hash). The default value is extracted from current git commit if available. .sp If this option is missing and can\(cqt be automatically determined, the generator can\(cqt produce source code links. .RE .sp \fB\-\-source\-url\-pattern\fP \fIURL\fP .RS 4 Set URL pattern for source code links. The default value is extracted from git remotes ("origin" or first one) if available and the provider\(cqs URL pattern is recognized. .sp Supported replacement tags: .sp \fB%{refname}\fP .RS 4 commit reference .RE .sp \fB%{path}\fP .RS 4 path to source file inside the repository .RE .sp \fB%{filename}\fP .RS 4 basename of the source file .RE .sp \fB%{line}\fP .RS 4 line number .RE .sp If this option is missing and can\(cqt be automatically determined, the generator can\(cqt produce source code links. .RE .sp \fB\-o\fP \fIDIR\fP, \fB\-\-output\fP \fIDIR\fP .RS 4 Set the output directory (default: ./docs). .RE .sp \fB\-b\fP \fIURL\fP, \fB\-\-canonical\-base\-url\fP \fIURL\fP .RS 4 Indicate the preferred URL with rel="canonical" link element. .RE .sp \fB\-b\fP \fIURL\fP, \fB\-\-sitemap\-base\-url\fP \fIURL\fP .RS 4 Set the sitemap base URL. Sitemap will only be generated when this option is set. .RE .sp \fB\-\-sitemap\-priority\fP \fIPRIO\fP .RS 4 Set the priority assigned to sitemap entries (default: 1.0). .RE .sp \fB\-\-sitemap\-changefreq\fP \fIFREQ\fP .RS 4 Set the changefreq assigned to sitemap entries (default: never). .RE .SS "env" .sp \fBenv\fP [variables] .sp 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. .sp Variables: .sp \fBCRYSTAL_CACHE_DIR\fP .RS 4 Please see ENVIRONMENT VARIABLES. .RE .sp \fBCRYSTAL_EXEC_PATH\fP .RS 4 Please see ENVIRONMENT VARIABLES. .RE .sp \fBCRYSTAL_LIBRARY_PATH\fP .RS 4 Please see ENVIRONMENT VARIABLES. .RE .sp \fBCRYSTAL_PATH\fP .RS 4 Please see ENVIRONMENT VARIABLES. .RE .sp \fBCRYSTAL_VERSION\fP .RS 4 Contains Crystal version. .RE .SS "eval" .sp \fBeval\fP [options] [source] .sp Evaluate code from arguments or, if no arguments are passed, from the standard input. Useful for experiments. .sp Options: .sp \fB\-d\fP, \fB\-\-debug\fP .RS 4 Generate the output with symbolic debug symbols. These are read when debugging the built program with tools like lldb, gdb, valgrind etc. and provide mappings to the original source code for those tools. .RE .sp \fB\-\-no\-debug\fP .RS 4 Generate the output without any symbolic debug symbols. .RE .sp \fB\-D\fP \fIFLAG\fP, \fB\-\-define\fP \fIFLAG\fP .RS 4 Define a compile\-time flag. This is useful to conditionally define types, methods, or commands based on flags available at compile time. The default flags are from the target triple given with \-\-target\-triple or the hosts default, if none is given. .RE .sp \fB\-\-error\-trace\fP .RS 4 Show full error trace. .RE .sp \fB\-O\fP \fILEVEL\fP .RS 4 Optimization mode: 0 (default), 1, 2, 3. See \fBOPTIMIZATIONS\fP for details. .RE .sp \fB\-\-release\fP .RS 4 Compile in release mode. Equivalent to \fB\-O3 \-\-single\-module\fP .RE .sp \fB\-s\fP, \fB\-\-stats\fP .RS 4 Print statistics about the different compiler stages for the current build. Output time and used memory for each compiler process. .RE .sp \fB\-p\fP, \fB\-\-progress\fP .RS 4 Print statistics about the progress for the current build. .RE .sp \fB\-t\fP, \fB\-\-time\fP .RS 4 Print statistics about the execution time. .RE .sp \fB\-\-no\-color\fP .RS 4 Disable colored output. .RE .SS "play" .sp \fBplay\fP [options] [file] .sp Starts the \fBcrystal\fP playground server on port 8080, by default. .sp Options: .sp \fB\-p\fP \fIPORT\fP, \fB\-\-port\fP \fIPORT\fP .RS 4 Run the playground on the specified port. Default is 8080. .RE .sp \fB\-b\fP \fIHOST\fP, \fB\-\-binding\fP \fIHOST\fP .RS 4 Bind the playground to the specified IP. .RE .sp \fB\-v\fP, \fB\-\-verbose\fP .RS 4 Display detailed information of the executed code. .RE .SS "run" .sp \fBrun\fP [options] [programfile] [\-\-] [arguments] .sp The default command. Compile and run program. .sp Options: Same as the build options. .SS "spec" .sp spec [options] [files] .sp Compile and run specs (in spec directory). .sp Options: .sp \fB\-d\fP, \fB\-\-debug\fP .RS 4 Generate the output with symbolic debug symbols. These are read when debugging the built program with tools like lldb, gdb, valgrind etc. and provide mappings to the original source code for those tools. .RE .sp \fB\-\-no\-debug\fP .RS 4 Generate the output without any symbolic debug symbols. .RE .sp \fB\-D\fP \fIFLAG\fP, \fB\-\-define\fP \fIFLAG\fP .RS 4 Define a compile\-time flag. This is useful to conditionally define types, methods, or commands based on flags available at compile time. The default flags are from the target triple given with \fB\-\-target\-triple\fP or the hosts default, if none is given. .RE .sp \fB\-\-error\-trace\fP .RS 4 Show full error trace. .RE .sp \fB\-O\fP \fILEVEL\fP .RS 4 Optimization mode: 0 (default), 1, 2, 3. See \fBOPTIMIZATIONS\fP for details. .RE .sp \fB\-\-release\fP .RS 4 Compile in release mode. Equivalent to \fB\-O3 \-\-single\-module\fP .RE .sp \fB\-s\fP, \fB\-\-stats\fP .RS 4 Print statistics about the different compiler stages for the current build. Output time and used memory for each compiler process. .RE .sp \fB\-p\fP, \fB\-\-progress\fP .RS 4 Print statistics about the progress for the current build. .RE .sp \fB\-t\fP, \fB\-\-time\fP .RS 4 Print statistics about the execution time. .RE .sp \fB\-\-no\-color\fP .RS 4 Disable colored output. .RE .SS "tool" .sp \fBtool\fP [tool] [switches] [programfile] [\-\-] [arguments] .sp Run a tool. The available tools are: context, dependencies, expand, flags, format, hierarchy, implementations, types, and unreachable. .sp Tools: .sp \fBcontext\fP .RS 4 Show context for given location. .RE .sp \fBdependencies\fP .RS 4 Show tree of required source files. .sp Options: .sp \fB\-D\fP \fIFLAG\fP, \fB\-\-define\fP=\fIFLAG\fP .RS 4 Define a compile\-time flag. This is useful to con ditionally define types, methods, or commands based on flags available at compile time. The default flags are from the target triple given with \fB\-\-tar\fP get\-triple or the hosts default, if none is given. .RE .sp \fB\-f\fP \fIFORMAT\fP, \fB\-\-format\fP=\fIFORMAT\fP .RS 4 Output format \*(Aqtree\*(Aq (default), \*(Aqflat\*(Aq, \*(Aqdot\*(Aq, or \*(Aqmermaid\*(Aq. .RE .sp \fB\-i\fP \fIPATH\fP, \fB\-\-include\fP=\fIPATH\fP .RS 4 Include path in output. .RE .sp \fB\-e\fP \fIPATH\fP, \fB\-\-exclude\fP=\fIPATH\fP .RS 4 Exclude path in output. .RE .sp \fB\-\-error\-trace\fP .RS 4 Show full error trace. .RE .sp \fB\-\-prelude\fP .RS 4 Specify prelude to use. The default one initializes the garbage collector. You can also use \fB\-\-pre\fP lude=empty to use no preludes. This can be useful for checking code generation for a specific source code file. .RE .sp \fB\-\-verbose\fP .RS 4 Show skipped and heads of filtered paths .RE .RE .sp \fBexpand\fP .RS 4 Show macro expansion for given location. .RE .sp \fBflags\fP .RS 4 Print all macro \*(Aqflag?\*(Aq values .RE .sp \fBformat\fP .RS 4 Format project, directories and/or files with the coding style used in the standard library. You can use the \fB\-\-checkflag\fP to check whether the formatter would make any changes. .RE .sp \fBhierarchy\fP .RS 4 Show hierarchy of types from file. Also show class and struct members, with type and size. Types can be filtered with a regex by using the \fB\-e\fP flag. .RE .sp \fBimplementations\fP .RS 4 Show implementations for a given call. Use \fB\-\-cursor\fP to specify the cursor position. The format for the cursor position is file:line:column. .RE .sp \fBtypes\fP .RS 4 Show type of main variables of file. .RE .sp \fBunreachable\fP .RS 4 Show methods that are never called. The text output is a list of lines with columns separated by tab. .sp Output fields: .sp \fBcount\fP .RS 4 sum of all calls to this method (only with \fB\-\-tallies\fP option; otherwise skipped) .RE .sp \fBlocation\fP .RS 4 pathname, line and column, all separated by colon name .RE .sp \fBlines\fP .RS 4 length of the def in lines annotations .RE .sp Options: .sp \fB\-D\fP \fIFLAG\fP, \fB\-\-define\fP=\fIFLAG\fP .RS 4 Define a compile\-time flag. This is useful to con ditionally define types, methods, or commands based on flags available at compile time. The default flags are from the target triple given with \fB\-\-target\-triple\fP or the hosts default, if none is given. .RE .sp \fB\-f\fP \fIFORMAT\fP, \fB\-\-format\fP=\fIFORMAT\fP .RS 4 Output format \*(Aqtext\*(Aq (default), \*(Aqjson\*(Aq, \*(Aqcodecov\*(Aq, or \*(Aqcsv\*(Aq. .RE .sp \fB\-\-tallies\fP .RS 4 Print reachable methods and their call counts as well. .RE .sp \fB\-\-check\fP .RS 4 Exit with error if there is any unreachable code. .RE .sp \fB\-i\fP \fIPATH\fP, \fB\-\-include\fP=\fIPATH\fP .RS 4 Include path in output. .RE .sp \fB\-e\fP \fIPATH\fP, \fB\-\-exclude\fP=\fIPATH\fP .RS 4 Exclude path in output (default: lib). .RE .sp \fB\-\-error\-trace\fP .RS 4 Show full error trace. .RE .sp \fB\-\-prelude\fP .RS 4 Specify prelude to use. The default one initializes the garbage collector. You can also use \fB\-\-prelude=empty\fP to use no preludes. This can be useful for checking code generation for a specific source code file. .RE .RE .SS "clear_cache" .sp Clear the compiler cache (located at \*(AqCRYSTAL_CACHE_DIR\*(Aq). .SS "help" .sp Show help. Option \fB\-\-help\fP or \fB\-h\fP can also be added to each command for command\-specific help. .SS "version" .sp Show version. .SH "OPTIMIZATIONS" .sp The optimization level specifies the codegen effort for producing optimal code. It\(cqs a trade\-off between compilation performance (decreasing per optimization level) and runtime performance (increasing per optimization level). .sp Production builds should usually have the highest optimization level. Best results are achieved with \fB\-\-release\fP which also implies \fB\-\-single\-module\fP .sp \fB\-O0\fP .RS 4 No optimization (default) .RE .sp \fB\-O1\fP .RS 4 Low optimization .RE .sp \fB\-O2\fP .RS 4 Middle optimization .RE .sp \fB\-O3\fP .RS 4 High optimization .RE .sp \fB\-Os\fP .RS 4 Middle optimization with focus on file size .RE .sp \fB\-Oz\fP .RS 4 Middle optimization aggressively focused on file size .RE .SH "ENVIRONMENT VARIABLES" .SS "CRYSTAL_CACHE_DIR" .sp 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 \*(Aq\fBcrystal\fP run\*(Aq rather than \*(Aq\fBcrystal\fP build\*(Aq. .SS "CRYSTAL_EXEC_PATH" .sp Determines the path where crystal looks for external sub-commands. .SS "CRYSTAL_LIBRARY_PATH" .sp Defines paths where Crystal searches for (binary) libraries. Multiple paths can be separated by ":". These paths are passed to the linker as \f(CR\-L\fP flags. .sp The pattern \*(Aq$ORIGIN\*(Aq at the start of the path expands to the directory where the compiler binary is located. For example, \*(Aq$ORIGIN/../lib/crystal\*(Aq 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). .SS "CRYSTAL_PATH" .sp Defines paths where Crystal searches for required source files. Multiple paths can be separated by ":". .sp The pattern \*(Aq$ORIGIN\*(Aq at the start of the path expands to the directory where the compiler binary is located. For example, \*(Aq$ORIGIN/../share/crystal/src\*(Aq 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). .SS "CRYSTAL_OPTS" .sp 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 \*(AqCRYSTAL_OPTS=\-\-debug make build\*(Aq. .SH "SEEALSO" .sp \fBshards\fP(1) .sp .URL "https://crystal\-lang.org/" "" "" The official web site. .sp .URL "https://github.com/crystal\-lang/crystal" "" "" Official Repository.