@Sunrise Hereās some explanation: āto buildā means compiling and linking an executable program.
The shards build
command makes sure dependencies are installed before building, then it calls crystal build
. Itās a mere convenience, and not required at all. Basically it does:
$ shards check || shards install
$ crystal build <target.main> -o bin/<target> <args>
The --production
and --frozen
options are shardsā options. They tell Shards to not install the development dependencies, and to install the locked dependencies. See shards install --help
for more details.
The crystal build
command is the command that builds your program. Thereās a plethora of arguments you can pass to customize the build. See crystal build --help
for details.
For building a production version of your program, youāll likely want --release
, that enables both --single-module
and -O3
that will enable the most aggressive optimizations. It also adds the :release
compile time flag that may be used to differentiate a development build vs a release build.
By default we only enable debug lines sections, in order to have file:line information in backtraces (exceptions and debuggers). This can be disabled with --no-debug
. On the opposite, you can enable full debug info with --debug
to be able to inspect variables in debuggers. I recommend to use neither unless you need to debug, in which case --debug
will be useful.
The --static
option will compile a static binary, that doesnāt need any shared library to run (theyāre embedded right into the executable). It can be useful but can be tricky.
The -Dpreview_mt
compile time flag enables a multi-threaded environment (by default crystal programs are single threaded). It makes the stdlib thread safe, and allows to run fibers in parallel in multiple threads. That being said itās still in preview, community shards arenāt necessarily thread safe, and itās under heavy refactor in RFC 0002 to finally make it official.
To build a program for production, you can configure a target in shard.yml
then call:
$ shards build --production --frozen <target> --release
Or decompose in two calls, which is less confusing:
$ shards install --production --frozen
$ crystal build src/myapp.cr -o bin/myapp --release
Sadly, I canāt help with macOS universal builds.