Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 3 years have passed since last update.

CrystalでAtCoder (Log #0: Apple Siliconにインストール)

Last updated at Posted at 2021-08-02

そのまんまのタイトルですが、CrystalでAtCoderしたい。
(Rustを辞めたわけではない)

  • CrystalをMacBook Pro (13-inch, M1, 2020)に
  • asdfを使用して(Rosseta2を通じて)インストールして
  • とりあえず動作してるので

公開します。

競プロしかしてないのでターミナルはあまり触らないけどApple SiliconでCrystalを動かしたい、だけどリリースページcrystal-x.x.x-darwin-arm64.tar.gzがないので困っている人が対象です。

AtCoderで言語アップデートがあったりCrystalがarm64に対応したときの移行コストが低そうだったのでHomebrewではなくasdfを選択しました。

説明を詳しくしようとすると永遠に公開できそうになかったので、簡潔にしました。もっといい記事が出来たら教えて下さい。

asdfのインストール

# まずターミナル.appを開く
# デフォルトではホームディレクトリにいる
# asdfバイナリを取得する(実際に打ち込むのはgit以降)
ytok@YTOK ~ % git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.8.1

# asdfのバージョンを表示
ytok@YTOK ~ % asdf version
# まだ有効でないので以下のように表示される(以下→で表す)
→ zsh: command not found: asdf
# ホームディレクトリ直下の`.zshrc`ファイルに1行追加する
echo -e "\n. $HOME/.asdf/asdf.sh" >> ~/.zshrc
source ~/.zshrc
#
ytok@YTOK ~ % asdf version
→ v0.8.1-a1ef92a

asdfのインストールが完了。

Crystalプラグインのインストール

# AtCoderと同じ0.33.0をインストールしようと試みる
# まだプラグインがないのでcrystalが認識されない
ytok@YTOK ~ % asdf install crystal 0.33.0
→ No such plugin: crystal
# Crystalのプラグインをインストール
ytok@YTOK ~ % asdf plugin-add crystal https://github.com/asdf-community/asdf-crystal.git

Crystalのインストール

# 改めてCrystalのインストールを試みる
# サポートされていないアーキテクチャとのエラーが表示される
ytok@YTOK ~ % asdf install crystal 0.33.0
→ \e[31mFail:\e[m Unsupported architecture
# アーキテクチャを表示させるコマンド
ytok@YTOK ~ % uname -m
→ arm64
# Intel Mac互換でzshを改めて立ち上げる
ytok@YTOK ~ % arch -x86_64 zsh
ytok@YTOK ~ % uname -m
→ x86_64
# このモードだとインストールに成功する
ytok@YTOK ~ % asdf install crystal 0.33.0
→ ∗ Downloading and installing Crystal...
→ The installation was successful!
# 0.33.0のインストールは成功したが、実行するバージョンが指定されていないのでエラーが出る
ytok@YTOK ~ % crystal version          
→ No version set for command crystal
→ Consider adding one of the following versions in your config file at 
→ crystal 0.33.0
# `0_33_0`というディレクトリを作成して0.33.0はそこで動かすことにする
# ディレクトリを作成して移動
ytok@YTOK ~ % mkdir 0_33_0
ytok@YTOK ~ % cd 0_33_0
# このディレクトリで使うバージョンを0.33.0に指定する
ytok@YTOK 0_33_0 % asdf local crystal 0.33.0
ytok@YTOK 0_33_0 % crystal version          
→ Crystal 0.33.0 (2020-02-14)
→ 
→ LLVM: 6.0.1
→ Default target: x86_64-apple-macosx
ytok@YTOK 0_33_0 % uname -m
→ x86_64
# arm64に戻しても動作する
ytok@YTOK 0_33_0 % arch -arm64 zsh
ytok@YTOK 0_33_0 % uname -m
→ arm64
ytok@YTOK 0_33_0 % crystal version
→ Crystal 0.33.0 (2020-02-14)
→ 
→ LLVM: 6.0.1
→ Default target: x86_64-apple-macosx
ytok@YTOK 0_33_0 % crystal eval 'puts "Hello, World!"'
→ Hello, World!

動きました。

参考にしたもの

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?