0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SingularityでNeoVimをビルドしてGPUサーバでも使えるようにする

Posted at

はじめに

ここでは,g++等NeoVimのビルドに必要なソフトウェアが無いGPUサーバ等の環境下で,Singularityを使うことで無理やりNeoVimをビルドして使えるようにする方法を紹介します.
面倒なのでVimのカスタムで乗り切れるのならそのようにした方が良いです.

全体の流れ

以下の2段階で作業します.

  1. Singularityイメージを作成し,NeoVimをビルドする.
  2. Singularityコンテナに入り,ビルドした実行ファイルとランタイムをホストマシンに移動する.

Singularityイメージの作成

まずは適当な作業ディレクトリを作ります.名前・場所は自由です.

$ mkdir hoge
$ cd hoge

この場所にSingularityのdefファイルを用意します.
viを使ってsingularity.defを作る場合は以下のようにします.

$ vi singularity.def

defファイルの内容は以下のとおりです.

singularity.def
Bootstrap: docker
From: ubuntu:22.04

%post
    # パッケージリストの更新
    apt-get update

    # 基本的なビルドツールをインストール
    apt-get install -y \
        build-essential \
        cmake \
        ninja-build \
        git \
        wget \
        curl \
        pkg-config \
        gettext \
        libtool \
        libtool-bin \
        autoconf \
        automake \
        g++ \
        unzip

    # Neovim のビルドに必要な依存関係
    apt-get install -y \
        libunibilium-dev \
        libtermkey-dev \
        libvterm-dev \
        libuv1-dev \
        libmsgpack-dev \
        libjemalloc-dev \
        libluajit-5.1-dev \
        lua5.1 \
        lua-bitop \
        lua-lpeg \
        lua-mpack

    # 追加のランタイム依存関係
    apt-get install -y \
        python3 \
        python3-pip \
        nodejs \
        npm \
        ripgrep \
        fd-find

    # キャッシュのクリーンアップ
    apt-get clean
    rm -rf /var/lib/apt/lists/*

    # nvimをクローンしてビルドする
    git clone https://github.com/neovim/neovim.git
    cd /neovim
    make CMAKE_BUILD_TYPE=Release CMAKE_INSTALL_PREFIX=/usr/local
    make install

%environment
    export PATH=/usr/local/bin:$PATH
    export CC=gcc
    export CXX=g++

%runscript
    exec /bin/bash "$@"

defファイルの用意ができたらイメージを作ります.defファイルの名前は作成したファイルと合わせてください.sifファイルの名前はご自由に.

$ singularity build --fakeroot singularity.sif singularity.def

イメージの作成には数分かかります.筆者環境では3~5分くらいかかったと記憶しています.

nvimをホストマシンに移す

イメージのビルドが終わったら,コンテナに入ります.sifファイルの名前は自分で作ったものと合わせてください.

$ singularity shell singularity.sif

実行ファイルはコンテナの中の/usr/local/bin/nvim,ランタイムは/usr/local/share/nvim/ディレクトリです.それぞれホストマシンにコピーします.

Singularity> cp /usr/local/bin/nvim ~/.local/bin/
Singularity> cp -a /usr/local/share/nvim/ ~/~/.local/share/

この例では~/.local/binに実行ファイルをコピーしています.もしパスが通っていない場合は.bashrcに以下の行をを追記します.

~/.bashrc
export PATH=$PATH:~/.local/bin

既にパスが通っている別のディレクトリがある場合は,その場所にコピーしても良いです.

確認

コマンドを叩いてNeoVimが起動すれば成功です.設定をすればプラグインを動かすこともできます.

$ nvim
0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?