Creating production binaries
While foreshadowed in Chapter 6, Concurrency, we have mainly been building binaries with the crystal build file.cr
command and its run equivalent. These commands are fine during development but they do not produce a fully optimized binary for a production workload/environment that would be suitable for distribution.
To build a release binary, we need to pass the --release
flag. This will tell the LLVM backend that it should apply all the optimizations it can to the code. Another option that we can pass is --no-debug
. This will tell the Crystal compiler to not include any debug symbols, resulting in a smaller binary. Further symbols can be removed via the strip
command. See https://man7.org/linux/man-pages/man1/strip.1.html for more information.
After building with these two options, you would end up with a smaller, more performant binary that would be suitable for benchmarking or use within a production environment. However, it would not be portable...