LoginSignup
41
43

More than 5 years have passed since last update.

cyg-fastの紹介とknife soloの実行環境の作り方

Posted at

apt-cygの代わりとなるcyg-fastを紹介しようと思います。それだけでは寂しいので、knife soloの実行環境を作り、vagrantと一緒に使って遊んでみることを目標にしていろいろ書いてみます。

cyg-fastの導入

cygwinで遊んでいて何かをインストールしたい!と思ったときにsetup.exeを使うのは面倒なのでapt-cygを導入しましょう。ということを以前に書きましたが、apt-cygを改良したcyg-fastというものがありますので今度からはこちらを使うようにしましょう。
どういった部分が良くなったのかはこちらに詳しく書いてあります。
fastという名前からわかる通り速くなっているようですね。

導入方法

  • wget
  • aria2

以上をsetup.exeでいれます。

wget https://raw.githubusercontent.com/lambdalice/cyg-fast/master/cyg-fast -P /usr/bin
chmod +x /usr/bin/cyg-fast
cyg-fast -m ftp://ftp.iij.ad.jp/pub/cygwin/ update

ミラーサイトを国内のサーバにしておきます。

knife-soloをインストールするまでの長い道のり

knife soloの実行環境にはrubyが必要です。rbenvを使って入れます。

必要そうなものをインストール

その前に、要らないのも混じってるかもしれないですが必要そうなものをまとめて入れてしまいます。

cyg-fast install gcc-core gcc-g++ make zlib-devel autoconf libiconv-devel libiconv-devel rsync patch openssh openssl-devel libxml2-devel libxslt-devel libffi-devel libgdbm-devel

rubyのインストール

それではrubyをインストールしましょう。

git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

rubyは2.1.0を入れます。私がやってみたときは1.9.0~2.2.0-devまでいろいろ試してはみましたが、2.1.0ならトラブルもなく行けました。ただ、別のバージョンでもいけるのかもしれないです。
インストール後はgem updateもします。

rbenv install 2.1.0
rbenv global 2.1.0
rbenv rehash
gem update

このへんは時間がかかりますので珈琲でも飲みながら待ちましょう。

--no-ri --no-rdocをデフォルトに

私はgem installするときは、ドキュメントいらないので--no-ri --no-rdocを付けるようにしてます。ですが、たまに付け忘れてドキュメントのインストールがはじまってぐはぁってなります。なので、gemrcを設定して--no-ri --no-rdocをデフォルトにします。
echo 'gem: --no-ri --no-rdoc' > ~/.gemrc

dep-selector-libgecodeをgem install

いくつか難所があるのですが、まずはこいつです。
http://qiita.com/yositani2002/items/6e9b765452676a40a2ef
http://qiita.com/DQNEO/items/207a2e7f6f32e8cc2f7f
こちらを参考にして入れました。

手順をまとめるとこんな感じです。以下はコピペです。

# gcc48.exe, g++48.exeという名前のシムリンクを作成
ln -s gcc.exe /usr/bin/gcc48.exe
ln -s g++.exe /usr/bin/g++48.exe

# gecode 3.7.3 を取得して解凍
wget "http://pkgs.fedoraproject.org/repo/pkgs/gecode/gecode-3.7.3.tar.gz/7a5cb9945e0bb48f222992f2106130ac/gecode-3.7.3.tar.gz"
tar xvfz gecode-3.7.3.tar.gz
cd gecode-3.7.3

# コンパイル
./configure CC="gcc48"  --disable-doc-dot --disable-doc-search --disable-doc-tagfile --disable-doc-chm --disable-doc-docset --disable-qt --disable-examples --disable-flatzinc
make -j4
make install
# ライブラリを手動で配置
cp libgecode* /lib/
cp -r gecode/* /usr/include/

# dep-selector-libgecodeのインストール
USE_SYSTEM_GECODE=1 gem install dep-selector-libgecode

ffiをgem install

次の難所はffiです。
https://github.com/ffi/ffi/issues/284#issuecomment-33752957
http://qiita.com/DQNEO/items/207a2e7f6f32e8cc2f7f

こちらを参考にして入れました。

cyg-fast install libffi6 libffi-devel pkg-config
export PKG_CONFIG_PATH="/lib/pkgconfig"
gem install ffi

nokogiriをgem install

その次の難所がこいつです。難所と言ってもgem install nokogiriで入るのですが、インストール時にこんなメッセージが表示され、とても時間がかかってしまいます。

Building nokogiri using packaged libraries.
Building libxml2-2.8.0 for nokogiri with the following patches applied:
        - 0001-Fix-parser-local-buffers-size-problems.patch
        - 0002-Fix-entities-local-buffers-size-problems.patch
        - 0003-Fix-an-error-in-previous-commit.patch
        - 0004-Fix-potential-out-of-bound-access.patch
        - 0005-Detect-excessive-entities-expansion-upon-replacement.patch
        - 0006-Do-not-fetch-external-parsed-entities.patch
        - 0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch
        - 0008-Improve-handling-of-xmlStopParser.patch
        - 0009-Fix-a-couple-of-return-without-value.patch
        - 0010-Keep-non-significant-blanks-node-in-HTML-parser.patch
        - 0011-Do-not-fetch-external-parameter-entities.patch
************************************************************************
IMPORTANT!  Nokogiri builds and uses a packaged version of libxml2.

If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri as
follows:

    gem install nokogiri -- --use-system-libraries

If you are using Bundler, tell it to use the option:

    bundle config build.nokogiri --use-system-libraries
    bundle install

However, note that nokogiri does not necessarily support all versions
of libxml2.

For example, libxml2-2.9.0 and higher are currently known to be broken
and thus unsupported by nokogiri, due to compatibility problems and
XPath optimization bugs.
************************************************************************
Building libxslt-1.1.28 for nokogiri with the following patches applied:
        - 0001-Adding-doc-update-related-to-1.1.28.patch
        - 0002-Fix-a-couple-of-places-where-f-printf-parameters-wer.patch
        - 0003-Initialize-pseudo-random-number-generator-with-curre.patch
        - 0004-EXSLT-function-str-replace-is-broken-as-is.patch
        - 0006-Fix-str-padding-to-work-with-UTF-8-strings.patch
        - 0007-Separate-function-for-predicate-matching-in-patterns.patch
        - 0008-Fix-direct-pattern-matching.patch
        - 0009-Fix-certain-patterns-with-predicates.patch
        - 0010-Fix-handling-of-UTF-8-strings-in-EXSLT-crypto-module.patch
        - 0013-Memory-leak-in-xsltCompileIdKeyPattern-error-path.patch
        - 0014-Fix-for-bug-436589.patch
        - 0015-Fix-mkdir-for-mingw.patch
************************************************************************
IMPORTANT!  Nokogiri builds and uses a packaged version of libxslt.

If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri as
follows:

    gem install nokogiri -- --use-system-libraries

If you are using Bundler, tell it to use the option:

    bundle config build.nokogiri --use-system-libraries
    bundle install
************************************************************************

installに時間がかかる理由ですが、nokogiriはlibxml2,libxsltを同梱して、環境に合わせてビルドするからです。なので、gem install nokogiriの時にライブラリが無いため止まってしまう、ということは起きません。
このライブラリのビルドを回避するためには以下のコマンドでいけます。

gem install nokogiri -- --use-system-libraries

ですが、最新のlibxml2にはバグがあるため、これを回避するためにgem install時にlibxmlバージョン2.8.0をビルドするようにしているみたいなんですね。
https://github.com/sparklemotion/nokogiri/issues/829

なので素直にgem innstall nokogiriのときには、--use-system-librariesは付けずに、libxml 2.8.0をビルドしてもらったほうがいいのかもしれません。紅茶でも飲みながら待ちましょう。

bundlerをインストール

以上3つを入れたら満を持してbundlerをインストールします。

gem install bundler
rbenv rehash

knife-soloをインストール

knife-soloにはサブモジュールが含まれていますので、--recursiveをつけて一緒にcloneします。その前にgettextをインストールしておきましょう。

knife-soloリポジトリのclone

cyg-fast install gettext 
git clone --recursive git@github.com:matschaffer/knife-solo.git 

gettextがないと、以下のようなエラーが出てサブモジュールのcloneに失敗してしますので気を付けましょう。

/usr/lib/git-core/git.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory

knife-soloをビルドしてインストール

cd knife-solo
bundle && bundle exec rake install
rbenv rehash

この辺も時間がかかりますのでドクターペッパーでも飲みながら待ちましょう。

できた!

% knife -v
Chef: 11.6.2

長かった・・・。かかった時間はだいたい2時間かそれくらいでしょうか。
最初に立てた目標がまだ達成できないですが、さすがに長くなったのでここで一度切ろうと思います。

41
43
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
41
43