module Crystal

Defined in:

crystal/datum.cr
crystal/dwarf/addr.cr
crystal/dwarf/backtraces.cr
crystal/dwarf/str_offsets.cr
crystal/main.cr
crystal/once.cr
crystal/print_buffered.cr
crystal/small_deque.cr
crystal/tracing.cr

Constant Summary

ALL_FLAGS = ["x86_64", "suse", "linux", "gnu", "bits64", "unix", "debug", "docs"]

The combined flags of the user and the program, including the target triple and the user flags.

BUILD_COMMIT = nil

The build commit identifier of the Crystal compiler.

BUILD_DATE = "2026-10-23"

The build date of the Crystal compiler.

CACHE_DIR = "/home/abuild/.cache/crystal"

The cache directory configured for the Crystal compiler.

The value is defined by the environment variableCRYSTAL_CACHE_DIR and defaults to the user's configured cache directory.

DEFAULT_PATH = "/usr/share/crystal1.22/src"

The default Crystal path configured in the compiler. This value is baked into the compiler and usually points to the accompanying version of the standard library.

DESCRIPTION = "Crystal 1.22.1 (2026-10-23)\n\nLLVM: 22.1.8\nDefault target: x86_64-suse-linux-gnu\n"

Full version information of the Crystal compiler. Equivalent tocrystal --version.

HOST_TRIPLE = "x86_64-suse-linux-gnu"

The LLVM target triple of the host system (the machine that the compiler runs on).

LIBRARY_PATH = "/usr/lib64/crystal1.22"

Colon-separated pathswhere the compiler searches for (binary) libraries.

The value is defined by the environment variablesCRYSTAL_LIBRARY_PATH.

LLVM_VERSION = "22.1.8"

The version of LLVM used by the Crystal compiler.

PATH = "./lib:/home/abuild/rpmbuild/BUILD/crystal1.22-1.22.1-build/crystal-1.22.1/src"

Colon-separated pathswhere the compiler searches for required source files.

The value is defined by the environment variableCRYSTAL_PATH and defaults toDEFAULT_PATH.

TARGET_TRIPLE = "x86_64-suse-linux-gnu"

The LLVM target triple of the target system (the machine that the compiler builds for).

USER_FLAGS = ["docs"]

The flags provided by the user via the-D command line argument.

VERSION = "1.22.1"

The version of the Crystal compiler.

Class Method Summary

Class Method Detail

def self.main(&) #

Defines the main routine run by normal Crystal programs:

  • Initializes runtime requirements (GC, ...)
  • Invokes the givenblock
  • Handles unhandled exceptions
  • Invokesat_exit handlers
  • FlushesSTDOUT andSTDERR

This method can be invoked if you need to define a custom main (as in C main) function, doing all the above steps.

For example:

fun main(argc : Int32, argv : UInt8**) : Int32
  Crystal.main do
    elapsed = Time.measure do
      Crystal.main_user_code(argc, argv)
    end
    puts "Time to execute program: #{elapsed}"
  end
end

Note that the above is really just an example, almost the same can be accomplishedwithat_exit. But in some cases redefinition of C's main is needed.


def self.main(argc : Int32, argv : Pointer(Pointer(UInt8))) #

Main method run by all Crystal programs at startup.

This setups up the GC, invokes your program, rescuing any handled exception, and then runsat_exit handlers.

This method is automatically invoked for you, so you don't need to invoke it.

However, if you need to define a special main C function, you can redefine main and invokeCrystal.main from it:

fun main(argc : Int32, argv : UInt8**) : Int32
  # some setup before Crystal main
  Crystal.main(argc, argv)
  # some cleanup logic after Crystal main
end

TheCrystal.main can also be passed as a callback:

fun main(argc : Int32, argv : UInt8**) : Int32
  LibFoo.init_foo_and_invoke_main(argc, argv, ->Crystal.main(Int32, UInt8**))
end

Note that beforeCrystal.main is invoked the GC is not setup yet, so nothing that allocates memory in Crystal (likenew for classes) can be used.


def self.main_user_code(argc : Int32, argv : Pointer(Pointer(UInt8))) #

Executes the main user code. This normally is executed after initializing the GC and before executingat_exit handlers.

You should never invoke this method unless you need to redefine C's main function. SeeCrystal.main for more details.


def self.print_buffered(message : String, *args, to io : IO, exception = nil, backtrace = nil) : Nil #

Prepares an error message,with an optional exception or backtrace, to an in-memory buffer, beforewriting to an IO, usually STDERR, in a singlewrite operation.

Avoids intermingled messages caused by multiple threadswriting to a STDIO in parallel. This may still happen, sincewrites may not be atomicwhen the overall size is larger than PIPE_BUF, buf it should at leastwrite 512 bytes atomically.


def self.print_error_buffered(message : String, *args, exception = nil, backtrace = nil) : Nil #

Identical to#print_buffered but eventually callsSystem.print_error(bytes) towrite to stderrwithout going through the event loop.


def self.trace(section : Tracing::Section, operation : String, time : UInt64 | Nil = nil, **metadata, &) #

def self.trace(section : Tracing::Section, operation : String, time : UInt64 | Nil = nil, **metadata) #