ござるのブログ

覚え書きいろいろ

M1 MacでDocker Desktopに頼らずにx86_64のlRubyを使うまで

はじめに

Docker Desktopと同様に、limaでも、M1 Macx86_64のIRubyが動作します。以下、その手順です。

limaを使えるようにする

前回の記事qemu-virglをインストールするところまで実施します。

5zalt.hatenablog.com

x86_64のlimaを起動

$ limactl start amd64

amd64の部分は何でもよいです。

以下のように表示されるので、矢印キーでOpen an editor to override the configurationを選択してreturn。

? Creating an instance "amd64"  [Use arrows to move, type to filter]
  Proceed with the default configuration
> Open an editor to override the configuration
  Exit

エディタが起動するので、以下のように書き換えて保存し終了。

@@ -4,7 +4,7 @@

 # Arch: "default", "x86_64", "aarch64".
 # "default" corresponds to the host architecture.
-arch: "default"
+arch: "x86_64"

 # An image must support systemd and cloud-init.
 # Ubuntu and Fedora are known to work.
@@ -49,7 +49,7 @@
   # A localhost port of the host. Forwarded to port 22 of the guest.
   # Currently, this port number has to be specified manually.
   # Default: none
-  localPort: 60022
+  localPort: 61022
   # Load ~/.ssh/*.pub in addition to $LIMA_HOME/_config/user.pub .
   # This option is useful when you want to use other SSH-based
   # applications such as rsync with the Lima instance.

x86_64のLinuxイメージのダウンロードと環境構築が始まります。結構時間がかかります。

IRubyの構築と起動

以下のようなDockerfileを用意。

FROM jupyter/base-notebook:latest
USER root
RUN apt-get update \
  && apt-get install --no-install-recommends -y \
  libczmq-dev \
  libtool \
  make \
  ruby-dev \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/*
RUN gem install --no-document \
  cztop \
  iruby
USER $NB_USER
RUN iruby register --force

Dockerfileを置いたディレクトリで以下を実行。

$ limactl shell amd64 nerdctl build -t iruby .

とても時間がかかります。私の環境では30分以上かかりました。コーヒーを飲みながら待ちます☕

無事完了したら、以下のコマンドでIRubyを起動。

$ mkdir /tmp/lima
$ limactl shell amd64 nerdctl run -it --rm -p 8888:8888 -e JUPYTER_ENABLE_LAB=yes -v /tmp/lima:/home/jovyan/work iruby

ブラウザでアクセス

表示されるhttp://127.0.0.1:8888/lab?token=…にブラウザでアクセス

f:id:gzalt:20210920141345p:plain
IRubyの画面

すばらしい。

おわりに

なぜこんなことをしているかというと、手元のIRuby notebookで使っている neilslater/convolverがaarch64では使えないから。

icm7216/narray-convolveを使えばいいのでは? まぁ、そうですね…