Qiita Markdownインストール時の依存関係解決

個人開発で`qiita-markdown` Gemをインストールしようとしたら、依存関係が足りてない場面があったのでまとめる。

https://github.com/increments/qiita-markdown

## ただインストールしようとすると...

```rb:Gemfile
# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem 'qiita-markdown'

```

```bash
$ bundle install

#8 1.697 Fetching gem metadata from https://rubygems.org/........
#8 2.268 Resolving dependencies...
#8 2.404 Fetching concurrent-ruby 1.1.9
#8 2.495 Installing concurrent-ruby 1.1.9
#8 2.567 Fetching i18n 1.8.11
#8 2.602 Installing i18n 1.8.11
#8 2.627 Fetching minitest 5.14.4
#8 2.675 Installing minitest 5.14.4
#8 2.695 Fetching tzinfo 2.0.4
#8 2.745 Installing tzinfo 2.0.4
#8 2.773 Fetching zeitwerk 2.5.1
#8 2.824 Installing zeitwerk 2.5.1
#8 2.843 Fetching activesupport 6.1.4.1
#8 2.923 Installing activesupport 6.1.4.1
#8 3.029 Fetching public_suffix 4.0.6
#8 3.084 Installing public_suffix 4.0.6
#8 3.112 Fetching addressable 2.8.0
#8 3.174 Installing addressable 2.8.0
#8 3.201 Using bundler 2.1.4
#8 3.202 Fetching charlock_holmes 0.7.7
#8 3.242 Installing charlock_holmes 0.7.7 with native extensions
#8 5.969 Fetching crass 1.0.6
#8 6.004 Installing crass 1.0.6
#8 6.021 Fetching escape_utils 1.1.1
#8 6.056 Installing escape_utils 1.1.1 with native extensions
#8 7.320 Fetching gemoji 3.0.1
#8 7.366 Installing gemoji 3.0.1
#8 7.392 Fetching mime-types-data 3.2021.1115
#8 7.476 Installing mime-types-data 3.2021.1115
#8 7.514 Fetching mime-types 3.4.0
#8 7.555 Installing mime-types 3.4.0
#8 7.580 Fetching rugged 1.2.0
#8 7.803 Installing rugged 1.2.0 with native extensions
#8 8.236 Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
#8 8.236
#8 8.236     current directory: /usr/local/bundle/gems/rugged-1.2.0/ext/rugged
#8 8.236 /usr/local/bin/ruby -I /usr/local/lib/ruby/2.7.0 -r
#8 8.236 ./siteconf20211116-8-bsnvbn.rb extconf.rb
#8 8.236 checking for gmake... no
#8 8.236 checking for make... yes
#8 8.236 checking for cmake... no
#8 8.236 ERROR: CMake is required to build Rugged.
#8 8.236 *** extconf.rb failed ***
#8 8.236 Could not create Makefile due to some reason, probably lack of necessary
#8 8.236 libraries and/or headers.  Check the mkmf.log file for more details.  You may
#8 8.236 need configuration options.
#8 8.236
#8 8.236 Provided configuration options:
#8 8.236        --with-opt-dir
#8 8.236        --without-opt-dir
#8 8.236        --with-opt-include
#8 8.236        --without-opt-include=${opt-dir}/include
#8 8.236        --with-opt-lib
#8 8.236        --without-opt-lib=${opt-dir}/lib
#8 8.236        --with-make-prog
#8 8.236        --without-make-prog
#8 8.236        --srcdir=.
#8 8.236        --curdir
#8 8.236        --ruby=/usr/local/bin/$(RUBY_BASE_NAME)
#8 8.236        --with-sha1dc
#8 8.236        --without-sha1dc
#8 8.236        --use-system-libraries
#8 8.236
#8 8.236 To see why this extension failed to compile, please check the mkmf.log which can
#8 8.236 be found here:
#8 8.236
#8 8.236   /usr/local/bundle/extensions/x86_64-linux/2.7.0/rugged-1.2.0/mkmf.log
#8 8.236
#8 8.236 extconf failed, exit code 1
#8 8.236
#8 8.236 Gem files will remain installed in /usr/local/bundle/gems/rugged-1.2.0 for
#8 8.236 inspection.
#8 8.236 Results logged to
#8 8.236 /usr/local/bundle/extensions/x86_64-linux/2.7.0/rugged-1.2.0/gem_make.out
#8 8.236
#8 8.236 An error occurred while installing rugged (1.2.0), and Bundler cannot continue.
#8 8.236 Make sure that `gem install rugged -v '1.2.0' --source 'https://rubygems.org/'`
#8 8.236 succeeds before bundling.
#8 8.236
#8 8.236 In Gemfile:
#8 8.236   qiita-markdown was resolved to 0.40.0, which depends on
#8 8.236     github-linguist was resolved to 4.8.18, which depends on
#8 8.236       rugged
------
executor failed running [/bin/sh -c bundle install]: exit code: 5
ERROR: Service 'app' failed to build : Build failed
```

## なぜエラーになるか？

`qiita-markdown`の依存関係（[qiita-markdown.gemspec](https://github.com/increments/qiita-markdown/blob/master/qiita-markdown.gemspec)を参照）に[github-linguist](https://github.com/github/linguist)というGemがあり、そのさらに依存関係に[rugged](https://github.com/libgit2/rugged)というGemがあります。
そして、`rugged`はビルド時に`cmake`が必要となっているため（[extconf.rb](https://github.com/libgit2/rugged/blob/master/ext/rugged/extconf.rb)を参照）、`ERROR: CMake is required to build Rugged.`とエラーが出てしまいます。

```
qiita-markdown
↓ 依存
github-linguist
↓ 依存
rugged ← cmakeが必要!!
```

そのため、`cmake`をインストールしてあげることで解決します。

```bash
$ apt update
$ apt install cmake

# or

$ brew install cmake

# cmakeをインストールして、bundle install
$ bundle install
```

すると無事使えました

```rb
require('qiita-markdown')
processor = Qiita::Markdown::Processor.new(hostname: "example.com")
processor.call('# Hello Qiita Markdown')[:output].to_s
# => "\n<h1>\n<span id=\"hello-qiita-markdown\" class=\"fragment\"></span><a href=\"#hello-qiita-markdown\"><i class=\"fa fa-link\"></i></a>Hello Qiita Markdown</h1>\n"
```