Crystal

Resources

Extension of vscode

  • https://marketplace.visualstudio.com/items?itemName=crystal-lang-tools.crystal-lang
    • https://github.com/elbywan/crystalline (Language Server)
  • https://marketplace.visualstudio.com/items?itemName=veelenga.crystal-ameba

Shards

  • Amber
    • A full-featured web framework
    • Like Rails
  • Lucky
    • A full-featured web framework
    • Like Rails
  • Kemal
    • Simple Web Framework
    • Like Sinatra
  • Ameba
    • Code style linter
    • Like Ruby’s Rubocop
  • Crest
    • HTTP Client
    • Like Ruby’s RestClient

TroubleShooting

SSL Error in Installation

Problem

Undefined symbols for architecture arm64:
  "_EVP_CIPHER_block_size", referenced from:
      _*OpenSSL::Cipher#block_size:Int32 in O-penS-S-L-5858C-ipher.o
  "_EVP_CIPHER_iv_length", referenced from:
      _*OpenSSL::Cipher#iv_len:Int32 in O-penS-S-L-5858C-ipher.o
  "_EVP_CIPHER_key_length", referenced from:
      _*OpenSSL::Cipher#key_len:Int32 in O-penS-S-L-5858C-ipher.o
ld: symbol(s) not found for architecture arm64

Solution

brew install openssl
grep PKG $(which crystal)
export PKG_CONFIG_PATH="${PKG_CONFIG_PATH:+$PKG_CONFIG_PATH:}/opt/homebrew/opt/openssl@3/lib/pkgconfig"

Snipppets

Build project

# using crystal
crystal build --no-debug --release

# using shards
shards build --no-debug --release

Release build

shards build --release --no-debug --production

#    --frozen                         Strictly installs locked versions from shard.lock.
#    --without-development            Does not install development dependencies.
#    --production                     same as `--frozen --without-development`

Unit test

# Basic
crystal spec

# Verbose
crsytal spec -v

Format

crystal tool format

Linting with ameba

# Installation
# brew tap crystal-ameba/ameba
# brew install ameba

ameba

# Auto fix
ameba --fix

Check Dependencies

crystal tool dependencies ./main.cr