Fixing crystal openssl Problems on macOS

You may come across these while developing with crystal on macOS

ld: library not found for -lssl (this usually means you need to install the development package for libssl)
clang: error: linker command failed with exit code 1 (use -v to see invocation)

In crystal play context

crystal play
Listening on http://127.0.0.1:8080
ld: library not found for -lssl (this usually means you need to install the development package for libssl)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of command failed with code: 1: `cc "${@}" -o '/Users/crstin/.cache/crystal/crystal-run-play-1-1.tmp'  -rdynamic  -lz `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto'` -lpcre -lgc -lpthread /usr/local/Cellar/crystal/0.27.2/src/ext/libcrystal.a -levent -liconv -ldl -L/usr/lib -L/usr/local/lib`

Or in running a Kemal app context

crystal run src/kemal.cr
ld: library not found for -lssl (this usually means you need to install the development package for libssl)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of command failed with code: 1: `cc "${@}" -o '/Users/crstin/.cache/crystal/crystal-run-kemal.tmp'  -rdynamic  -lz `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto'` -lpcre -lgc -lpthread /usr/local/Cellar/crystal/0.27.2/src/ext/libcrystal.a -levent -liconv -ldl -L/usr/lib -L/usr/local/lib`

Fix

Prepend to the command

PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig" crystal play
PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig" crystal run src/kemal.cr

Make it permanent

alias crystal="PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig crystal"