forked from crystal-lang/crystal
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crystal.1
444 lines (428 loc) · 16 KB
/
crystal.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
.\"Crystal Programming Language
.Dd
.Dt CRYSTAL(1) "" "Crystal Compiler Command Line Reference Guide"
.\".Dt CRYSTAL 1
.Os UNIX
.Sh NAME
.Nm crystal
.Nd Compiler for the Crystal language.
.Sh SYNOPSIS
.Nm
command
.Op switches
programfile
--
.Op arguments
.Sh DESCRIPTION
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
You can compile and run a program by invoking the compiler with a single filename:
.Bd -offset indent-two
.Nm
some_program.cr
.Ed
Crystal files usually end with the .cr extension, though this is not mandatory.
Alternatively you can use the run command:
.Bd -offset indent-two
.Nm
run
some_program.cr
.Ed
To create an executable use the build command:
.Bd -offset indent-two
.Nm
build
some_program.cr
.Ed
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:
.Bd -offset indent-two
.Nm
build
--release
some_program.cr
.Ed
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.
.Bl -tag -width "12345678" -compact
.Pp
.Sh OPTIONS
The crystal command accepts the following options
.Bl -tag -width "12345678" -compact
.Pp
.It
.Cm init
TYPE
.Op DIR | NAME DIR
.Pp
Generates a new Crystal project.
.Pp
TYPE is one of:
.Bl -tag -width "12345678" -compact
.Pp
.It Sy lib
Creates a library skeleton
.It Sy app
Creates an application skeleton
.El
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.
.Bd -literal -offset
DIR - directory where project will be generated
.Pp
NAME - name of project to be generated (default: basename of DIR)
.Ed
.Pp
Options:
.Bl -tag -width "12345678" -compact
.Pp
.It Fl f, Fl -force
Force overwrite existing files.
.It Fl s, Fl -skip-existing
Skip existing files.
.El
.Pp
.It
.Cm build
.Op options
.Op programfile
.Op --
.Op arguments
.Pp
Compile program.
.Pp
Options:
.Bl -tag -width "12345678" -compact
.Pp
.It Fl -cross-compile
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.
.It Fl d, Fl -debug
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.
.It Fl -no-debug
Generate the output without any symbolic debug symbols.
.It Fl D Ar FLAG, Fl -define Ar FLAG
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.
.It Fl -emit Op asm|llvm-bc|llvm-ir|obj
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.
.It Fl f Ar text|json, Fl -format Ar text|json
Format of output. Defaults to text. The json format can be used to get a more parser-friendly output.
.It Fl -error-trace
Show full error trace.
.It Fl -ll
Dump LLVM assembly file to output directory.
.It Fl -link-flags Ar FLAGS
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.
.It Fl -mcpu Ar CPU
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, invoke "llvm-as < /dev/null | llc -march=xyz -mcpu=help".
Passing --mcpu native will pass the host CPU name to tune performance for the host.
.It Fl -mattr Ar CPU
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".
.It Fl -mcmodel default|kernel|small|medium|large
Specifies a specific code model to generate code for. This will pass a --code-model flag to LLVM.
.It Fl -no-color
Disable colored output.
.It Fl -no-codegen
Don't do code generation, just parse the file.
.It Fl o
Specify filename of output.
.It Fl -prelude
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.
.It Fl -release
Turn on optimizations for the generated code, which are disabled by default.
.It Fl -error-trace
Show full stack trace. Disabled by default, as the full trace usually makes error messages less readable and not always deliver relevant information.
.It Fl s, -stats
Print statistics about the different compiler stages for the current build. Output time and used memory for each compiler process.
.It Fl p, -progress
Print statistics about the progress for the current build.
.It Fl t, -time
Print statistics about the execution time.
.It Fl -single-module
Generate a single LLVM module.
.It Fl -threads Ar NUM
Maximum number of threads to use for code generation. The default is 8 threads.
.It Fl -target Ar TRIPLE
Enable target triple; intended to use for cross-compilation. See llvm documentation for more information about target triple.
.It Fl -verbose
Display the commands executed by the system.
.It Fl -static
Create a statically linked executable.
.It Fl -stdin-filename Ar FILENAME
Source file name to be read from STDIN.
.El
.Pp
.It
.Cm docs
.Pp
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.
.Pp
Options:
.Bl -tag -width "12345678" -compact
.Pp
.It Fl -project-name Ar NAME
Set the project name. The default value is extracted from shard.yml if available.
In case no default can be found, this option is mandatory.
.It Fl -project-version Ar VERSION
Set the project version. The default value is extracted from current git commit or shard.yml if available.
In case no default can be found, this option is mandatory.
.It Fl -json-config-url Ar URL
Set the URL pointing to a config file (used for discovering versions).
.It Fl -source-refname Ar REFNAME
Set source refname (e.g. git tag, commit hash). The default value is extracted from current git commit if available.
If this option is missing and can't be automatically determined, the generator can't produce source code links.
.It Fl -source-url-pattern Ar URL
Set URL pattern for source code links. The default value is extracted from git remotes ("origin" or first one) if available and the provider's URL pattern is recognized.
.Pp
Supported replacement tags:
.Pp
.Bl -tag -width "%{refname}" -compact
.It Sy %{refname}
commit reference
.It Sy %{path}
path to source file inside the repository
.It Sy %{filename}
basename of the source file
.It Sy %{line}
line number
.El
.Pp
If this option is missing and can't be automatically determined, the generator can't produce source code links.
.It Fl o Ar DIR, Fl -output Ar DIR
Set the output directory (default: ./docs).
.It Fl b Ar URL, Fl -canonical-base-url Ar URL
Indicate the preferred URL with rel="canonical" link element.
.It Fl b Ar URL, Fl -sitemap-base-url Ar URL
Set the sitemap base URL. Sitemap will only be generated when this option is set.
.It Fl -sitemap-priority Ar PRIO
Set the priority assigned to sitemap entries (default: 1.0).
.It Fl -sitemap-changefreq Ar FREQ
Set the changefreq assigned to sitemap entries (default: never).
.El
.Pp
.It
.Cm env
.Op variables
.Pp
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.
.Pp
Variables:
.Bl -tag -width "12345678" -compact
.Pp
.It
.It Sy CRYSTAL_CACHE_DIR
Please see
.Sm "ENVIRONMENT VARIABLES".
.Pp
.It
.It Sy CRYSTAL_LIBRARY_PATH
Please see
.Sm "ENVIRONMENT VARIABLES".
.Pp
.It
.It Sy CRYSTAL_PATH
Please see
.Sm "ENVIRONMENT VARIABLES".
.Pp
.It
.It Sy CRYSTAL_VERSION
Contains Crystal version.
.El
.Pp
.It
.Cm eval
.Op options
.Op source
.Pp
Evaluate code from arguments or, if no arguments are passed, from the standard input. Useful for experiments.
.Pp
Options:
.Bl -tag -width "12345678" -compact
.Pp
.It Fl d, Fl -debug
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.
.It Fl -no-debug
Generate the output without any symbolic debug symbols.
.It Fl D Ar FLAG, Fl -define Ar FLAG
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.
.It Fl -error-trace
Show full error trace.
.It Fl -release
Turn on optimizations for the generated code, which are disabled by default.
.It Fl s, -stats
Print statistics about the different compiler stages for the current build. Output time and used memory for each compiler process.
.It Fl p, -progress
Print statistics about the progress for the current build.
.It Fl t, -time
Print statistics about the execution time.
.It Fl -no-color
Disable colored output.
.El
.Pp
.It
.Cm play
.Op options
.Op file
.Pp
Starts the crystal playground server on port 8080, by default.
.Pp
Options:
.Bl -tag -width "12345678" -compact
.Pp
.It Fl p Ar PORT, Fl -port Ar PORT
Run the playground on the specified port. Default is 8080.
.It Fl b Ar HOST, Fl -binding Ar HOST
Bind the playground to the specified IP.
.It Fl v, Fl -verbose
Display detailed information of the executed code.
.El
.Pp
.It
.Cm run
.Op options
.Op programfile
.Op --
.Op arguments
.Pp
The default command. Compile and run program.
.Pp
Options:
Same as the build options.
.Pp
.It
.Cm spec
.Op options
.Op files
.Pp
Compile and run specs (in spec directory).
.Pp
Options:
.Bl -tag -width "12345678" -compact
.Pp
.It Fl d, Fl -debug
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.
.It Fl -no-debug
Generate the output without any symbolic debug symbols.
.It Fl D Ar FLAG, Fl -define Ar FLAG
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.
.It Fl -error-trace
Show full error trace.
.It Fl -release
Turn on optimizations for the generated code, which are disabled by default.
.It Fl s, -stats
Print statistics about the different compiler stages for the current build. Output time and used memory for each compiler process.
.It Fl p, -progress
Print statistics about the progress for the current build.
.It Fl t, -time
Print statistics about the execution time.
.It Fl -no-color
Disable colored output.
.El
.Pp
.It
.Cm tool
.Op tool
.Op switches
.Op programfile
.Op --
.Op arguments
.Pp
Run a tool. The available tools are: context, dependencies, format, hierarchy, implementations, and types.
.Pp
Tools:
.Bl -tag -offset indent
.It Cm context
Show context for given location.
.It Cm dependencies
Show tree of required source files.
.Pp
Options:
.Bl -tag -width "12345678" -compact
.Pp
.It Fl D Ar FLAG, Fl -define= Ar FLAG
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.
.It Fl f Ar FORMAT, Fl -format= Ar FORMAT
Output format 'tree' (default), 'flat', 'dot', or 'mermaid'.
.It Fl i Ar PATH, Fl -include= Ar PATH
Include path in output.
.It Fl e Ar PATH, Fl -exclude= Ar PATH
Exclude path in output.
.It Fl -error-trace
Show full error trace.
.It Fl -prelude
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.
.It Fl -verbose
Show skipped and heads of filtered paths
.El
.It Cm expand
Show macro expansion for given location.
.It Cm format
Format project, directories and/or files with the coding style used in the standard library. You can use the
.Fl -check
flag to check whether the formatter would make any changes.
.It Cm hierarchy
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
.Fl e
flag.
.It Cm implementations
Show implementations for a given call. Use
.Fl -cursor
to specify the cursor position. The format for the cursor position is file:line:column.
.It Cm types
Show type of main variables of file.
.It Cm unreachable
Show methods that are never called. The output is a list of lines with columns
separated by tab. The first column is the location of the def, the second column
its reference name and the third column is the length in lines.
.El
.Pp
.It
.Cm clear_cache
.Pp
Clear the compiler cache (located at 'CRYSTAL_CACHE_DIR').
.El
.Pp
.It Cm help, Fl -help, h
.Pp
Show help. Option --help or -h can also be added to each command for command-specific help.
.Pp
.It Cm version, Fl -version, v
.Pp
Show version.
.El
.
.Sh ENVIRONMENT VARIABLES
.Bl -tag -width "12345678" -compact
.Pp
.It
.It Sy 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'.
.Pp
.It
.It Sy 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.
.Pp
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).
.Pp
.It
.It Sy CRYSTAL_PATH
Defines paths where Crystal searches for required source files. Multiple paths can be separated by ":".
.Pp
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).
.Pp
.It
.It Sy 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'.
.El
.Sh SEE ALSO
.Fn shards 1
.Bl -hang -compact -width "https://github.com/crystal-lang/crystal/1234"
.It https://crystal-lang.org/
The official web site.
.It https://github.com/crystal-lang/crystal
Official Repository.
.El