マリオ/ゼビウスの背景配置ツールをRuby+QT4で試す

マリオ/ゼビウスの背景配置ツールをRuby+QT4で試す

2023/08/19 16:00:00
Program
Wsl, Ubuntu, Game

ubuntu20.04 on wsl2 環境で試す #

wsl2 + ubuntu20.04 + ruby + qt4 で背景配置ツールを動作させてみる。
tilemapエディタは大昔に自作したやつで試す。
ruby から qt4 を動作させるには qtbindings を利用する必要があるが、
qtbindings 公式サイトを見ると、ruby 2.5.x + qt4 が最後のサポートらしい。。。

以下の手順は、wsl2 + ubuntu20.04 + rbenv の環境が構築済みであることが前提
開発環境はバージョンが違うが以下が参考になるはず。 ubuntu22.04開発環境構築

$ sudo apt install cmake
$ sudo add-apt-repository ppa:rock-core/qt4
$ sudo apt install qt4-default

# ruby_tools を取得
$ git clone https://github.com/oya3/ruby_tools
# qt4 サンプルに移動(ruby 2.5.8用)
$ cd ruby_tools/tilemap_editor

# ruby 2.5.8 インストール
$ rbenv install 2.5.8

# bundler インストール。が失敗する
$ gem install bundler
Fetching: bundler-2.4.19.gem (100%)
ERROR:  Error installing bundler:
        The last version of bundler (>= 0) to support your Ruby & RubyGems was 2.3.26. Try installing it with `gem install bundler -v 2.3.26`
        bundler requires Ruby version >= 2.6.0. The current ruby version is 2.5.0.
# 指示に従い、bundler 2.3.26 をインストール
$ gem install bundler -v 2.3.26
Fetching: bundler-2.3.26.gem (100%)
/home/developer/.anyenv/envs/rbenv/rbenv.d/exec/gem-rehash/rubygems_plugin.rb:6: warning: Insecure world writable dir /mnt/c in PATH, mode 040777
Successfully installed bundler-2.3.26
Parsing documentation for bundler-2.3.26
Installing ri documentation for bundler-2.3.26
Done installing documentation for bundler after 0 seconds
1 gem installed

# gem install
$ bundle config set path 'vendor/bundle'
$ bundle i
Your RubyGems version (2.7.6.2) has a bug that prevents `required_ruby_version` from working for Bundler. Any scripts that use `gem install bundler` will break as soon as Bundler drops support for your Ruby version. Please upgrade RubyGems to avoid future breakage and silence this warning by running `gem update --system 3.2.3`
Fetching gem metadata from https://rubygems.org/.......
Using bundler 2.3.26
Fetching method_source 1.0.0
Fetching yard 0.9.34
Fetching coderay 1.1.3
Fetching qtbindings 4.8.6.5
Fetching byebug 11.1.3
Installing method_source 1.0.0
Installing byebug 11.1.3 with native extensions
Installing coderay 1.1.3
Installing yard 0.9.34
Installing qtbindings 4.8.6.5 with native extensions
Fetching pry 0.14.2
Installing pry 0.14.2
Fetching pry-doc 1.4.0
Fetching pry-byebug 3.8.0
Installing pry-byebug 3.8.0
Installing pry-doc 1.4.0
Bundle complete! 4 Gemfile dependencies, 9 gems now installed.
Bundled gems are installed into `./vendor/bundle`

# 時間がかかるが成功するはず。
# 実行
$ bundle exec ruby main.rb
# phaserゲーム用の背景配置ツールが起動するはず

ubuntu22.04 on wsl2 環境で試すが動作せず #

ubuntu22.04 環境でも試してみたが、セグメンテーションフォルトが発生して起動させることができない。。。
ubuntu20.04 では実施していなかった enable-shared オプションを有効にしてrubyをインストールしても状況変わらず。

RUBY_CONFIGURE_OPTS=–enable-shared rbenv install 2.5.8

また、以下を実施後にqt4-default をインストールしてもダメだった。

sudo apt install libxcb-xinerama0 libglu1-mesa-dev

$ sudo apt install cmake
$ sudo add-apt-repository ppa:ubuntuhandbook1/pp   # <--- ここは ubuntu20.04 と違うので注意
$ sudo apt install qt4-default

# ruby_tools を取得
$ git clone https://github.com/oya3/ruby_tools
# qt4 サンプルに移動(ruby 2.5.8用)
$ cd ruby_tools/tilemap_editor

# ruby 2.5.8 インストール
$ rbenv install 2.5.8

# bundler インストール。が失敗する
$ gem install bundler
Fetching: bundler-2.4.19.gem (100%)
ERROR:  Error installing bundler:
        The last version of bundler (>= 0) to support your Ruby & RubyGems was 2.3.26. Try installing it with `gem install bundler -v 2.3.26`
        bundler requires Ruby version >= 2.6.0. The current ruby version is 2.5.0.
# 指示に従い、bundler 2.3.26 をインストール
$ gem install bundler -v 2.3.26
Fetching: bundler-2.3.26.gem (100%)
/home/developer/.anyenv/envs/rbenv/rbenv.d/exec/gem-rehash/rubygems_plugin.rb:6: warning: Insecure world writable dir /mnt/c in PATH, mode 040777
Successfully installed bundler-2.3.26
Parsing documentation for bundler-2.3.26
Installing ri documentation for bundler-2.3.26
Done installing documentation for bundler after 0 seconds
1 gem installed

# gem install
$ bundle config set path 'vendor/bundle'
$ bundle i
... 
# ubuntu20.04 とは違い以下のエラーが発生する。。。
[ 24%] Built target smokebase
make[3]: Entering directory '/home/developer/work/ruby_tools/tilemap_editor/vendor/bundle/ruby/2.5.0/gems/qtbindings-4.8.6.5/ext/build'
[ 25%] Generating smokedata.cpp, x_1.cpp, x_2.cpp, x_3.cpp, x_4.cpp, x_5.cpp, x_6.cpp, x_7.cpp, x_8.cpp, x_9.cpp, x_10.cpp, x_11.cpp, x_12.cpp, x_13.cpp, x_14.cpp, x_15.cpp, x_16.cpp, x_17.cpp, x_18.cpp, x_19.cpp, x_20.cpp
using generator "/home/developer/work/ruby_tools/tilemap_editor/vendor/bundle/ruby/2.5.0/gems/qtbindings-4.8.6.5/ext/build/generator/bin/generator_smoke.so"
parsing "/home/developer/work/ruby_tools/tilemap_editor/vendor/bundle/ruby/2.5.0/gems/qtbindings-4.8.6.5/ext/smoke/qtcore/qtcore_includes.h"
Generating SMOKE sources...
preparing SMOKE data [qtcore]
writing out smokedata.cpp [qtcore]
Segmentation fault
make[3]: *** [smoke/qtcore/CMakeFiles/smokeqtcore.dir/build.make:75: smoke/qtcore/smokedata.cpp] Error 139
make[3]: *** Deleting file 'smoke/qtcore/smokedata.cpp'
make[3]: Leaving directory '/home/developer/work/ruby_tools/tilemap_editor/vendor/bundle/ruby/2.5.0/gems/qtbindings-4.8.6.5/ext/build'
make[2]: *** [CMakeFiles/Makefile2:827: smoke/qtcore/CMakeFiles/smokeqtcore.dir/all] Error 2
make[2]: Leaving directory '/home/developer/work/ruby_tools/tilemap_editor/vendor/bundle/ruby/2.5.0/gems/qtbindings-4.8.6.5/ext/build'
make[1]: *** [Makefile:136: all] Error 2
make[1]: Leaving directory '/home/developer/work/ruby_tools/tilemap_editor/vendor/bundle/ruby/2.5.0/gems/qtbindings-4.8.6.5/ext/build'
make: *** [Makefile:48: build] Error 2

make failed, exit code 2

Gem files will remain installed in /home/developer/work/ruby_tools/tilemap_editor/vendor/bundle/ruby/2.5.0/gems/qtbindings-4.8.6.5 for inspection.
Results logged to /home/developer/work/ruby_tools/tilemap_editor/vendor/bundle/ruby/2.5.0/extensions/x86_64-linux/2.5.0/qtbindings-4.8.6.5/gem_make.out

  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/2.5.0/rubygems/ext/builder.rb:92:in `run'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/2.5.0/rubygems/ext/builder.rb:52:in `block in make'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/2.5.0/rubygems/ext/builder.rb:44:in `each'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/2.5.0/rubygems/ext/builder.rb:44:in `make'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/2.5.0/rubygems/ext/ext_conf_builder.rb:61:in `block in build'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/2.5.0/tempfile.rb:295:in `open'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/2.5.0/rubygems/ext/ext_conf_builder.rb:30:in `build'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/2.5.0/rubygems/ext/builder.rb:164:in `block (2 levels) in build_extension'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/2.5.0/rubygems/ext/builder.rb:163:in `chdir'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/2.5.0/rubygems/ext/builder.rb:163:in `block in build_extension'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/2.5.0/monitor.rb:235:in `mon_synchronize'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/2.5.0/rubygems/ext/builder.rb:162:in `build_extension'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/2.5.0/rubygems/ext/builder.rb:201:in `block in build_extensions'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/2.5.0/rubygems/ext/builder.rb:198:in `each'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/2.5.0/rubygems/ext/builder.rb:198:in `build_extensions'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/2.5.0/rubygems/installer.rb:791:in `build_extensions'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/rubygems_gem_installer.rb:72:in `build_extensions'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/source/rubygems.rb:207:in `install'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/installer/gem_installer.rb:54:in `install'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/installer/gem_installer.rb:16:in `install_from_spec'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/installer/parallel_installer.rb:186:in `do_install'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/installer/parallel_installer.rb:177:in `block in worker_pool'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/worker.rb:62:in `apply_func'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/worker.rb:57:in `block in process_queue'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/worker.rb:54:in `loop'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/worker.rb:54:in `process_queue'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/worker.rb:91:in `block (2 levels) in create_threads'

An error occurred while installing qtbindings (4.8.6.5), and Bundler cannot continue.

In Gemfile:
  qtbindings

/home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/installer/parallel_installer.rb:220:in `handle_error'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/installer/parallel_installer.rb:102:in `call'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/installer/parallel_installer.rb:71:in `call'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/installer.rb:254:in `install_in_parallel'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/installer.rb:209:in `install'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/installer.rb:89:in `block in run'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/process_lock.rb:12:in `block in lock'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/process_lock.rb:9:in `open'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/process_lock.rb:9:in `lock'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/installer.rb:71:in `run'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/installer.rb:23:in `install'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/cli/install.rb:62:in `run'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/cli.rb:257:in `block in install'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/settings.rb:131:in `temporary'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/cli.rb:256:in `install'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/cli.rb:31:in `dispatch'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/cli.rb:25:in `start'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/exe/bundle:48:in `block in <top (required)>'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/lib/bundler/friendly_errors.rb:120:in `with_friendly_errors'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bundler-2.3.26/exe/bundle:36:in `<top (required)>'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/bin/bundle:23:in `load'
  /home/developer/.anyenv/envs/rbenv/versions/2.5.8/bin/bundle:23:in `<main>'