iovxw

在 ubuntu 上编译安装 Crystal

水晶

Crystal 是一个语法像 Ruby,性能堪比C的语言

详细就不介绍了,直接去官网看吧

正文


其实直接参考里面的Vagrantfile就行(Dockerfile太久没更新就无视吧)

curl -s http://dist.crystal-lang.org/apt/setup.sh | bash
apt-get install -y crystal git libgmp3-dev zlib1g-dev libedit-dev libxml2-dev libssl-dev libyaml-dev libreadline-dev
curl -s http://crystal-lang.s3.amazonaws.com/llvm/llvm-3.5.0-1-linux-x86_64.tar.gz | tar xz -C /opt
echo 'export LIBRARY_PATH="/opt/crystal/embedded/lib"' > /etc/profile.d/crystal.sh
echo 'export PATH="$PATH:/opt/llvm-3.5.0-1/bin"' >> /etc/profile.d/crystal.sh
git clone https://github.com/manastech/crystal.git
make

顺便照着写了个Dockerfile

FROM ubuntu:14.04
RUN apt-key adv --keyserver keys.gnupg.net --recv-keys 09617FD37CC06B54 && \
    echo "deb http://dist.crystal-lang.org/apt crystal main" > /etc/apt/sources.list.d/crystal.list && \
    apt-get update && \
    apt-get install -y build-essential crystal curl git libgmp3-dev zlib1g-dev libedit-dev libxml2-dev libssl-dev libyaml-dev libreadline-dev && \
    apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
    curl -s http://crystal-lang.s3.amazonaws.com/llvm/llvm-3.5.0-1-linux-x86_64.tar.gz | tar xz -C /opt
ENV LIBRARY_PATH=/opt/crystal/embedded/lib
ENV PATH=$PATH:/opt/llvm-3.5.0-1/bin
RUN git clone https://github.com/manastech/crystal.git /root/crystal
WORKDIR /root/crystal

也可以直接docker pull iovxw/crystal我build好的

默认只是配置好环境,进去之后make什么都随便


顺带一提里面的轻量级线程还有channel好顺手啊,还带select

def generator(n : T)
  channel = Channel(T).new
  spawn do
    loop do
      sleep n
      channel.send n
    end
  end
  channel
end

ch1 = generator(1)
ch2 = generator(1.5)
ch3 = generator(5)

loop do
  case ch = Channel.select(ch1, ch2, ch3)
  when ch3
    break
  else
    puts ch.receive
  end
end