Linux 将棋ソフト「apery_rust」のビルド

2020年11月4日
manjaro

 Linux ディストリビューションである manjaro で将棋ソフト「apery_rust」をビルドする方法について書いてみる。まずはじめにプログラミング言語 rust をインストールする。

$ sudo pacman -S rustup

 次に「apery_rust」のページに従い、下記のコマンドを実行してソースコードをビルドする。

$ git clone https://github.com/HiraokaTakuya/apery_rust.git
Cloning into 'apery_rust'...
remote: Enumerating objects: 359, done.
remote: Counting objects: 100% (359/359), done.
remote: Compressing objects: 100% (121/121), done.
remote: Total 738 (delta 246), reused 331 (delta 233), pack-reused 379
Receiving objects: 100% (738/738), 312.99 KiB | 504.00 KiB/s, done.
Resolving deltas: 100% (498/498), done.
$ cd apery_rust
$ git submodule init
Submodule 'eval/20190617' (https://bitbucket.org/hiraoka64/apery-evaluation-binaries-2019-06-17.git) registered for path 'eval/20190617'
$ git submodule update
Cloning into '/home/nakada/shogi/apery_rust/eval/20190617'...
Submodule path 'eval/20190617': checked out 'c587e811c2275f9b6034f5db1aec7839258ae0c1'
$ cargo build --release
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2020-10-08, rust version 1.47.0 (18bf6b4f0 2020-10-07)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: Defaulting to 500.0 MiB unpack ram
info: installing component 'clippy'
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: installing component 'rustfmt'
    Updating crates.io index
  Downloaded crossbeam-queue v0.2.1
  Downloaded rayon-core v1.7.0
  Downloaded crossbeam-utils v0.7.2
  Downloaded ryu v1.0.4
  Downloaded unicode-xid v0.2.0
  Downloaded serde v1.0.106
  Downloaded num-integer v0.1.42
  Downloaded regex v1.3.7
  Downloaded custom_derive v0.1.7
  Downloaded aho-corasick v0.7.10
  Downloaded crossbeam-deque v0.7.3
  Downloaded crossbeam-epoch v0.8.2
  Downloaded autocfg v1.0.0
  Downloaded serde_derive v1.0.106
  Downloaded proc-macro2 v1.0.10
  Downloaded ppv-lite86 v0.2.6
  Downloaded libc v0.2.69
  Downloaded regex-syntax v0.6.17
  Downloaded itoa v0.4.5
  Downloaded maybe-uninit v2.0.0
  Downloaded cfg-if v0.1.10
  Downloaded memchr v2.3.3
  Downloaded arrayvec v0.5.1
  Downloaded num-complex v0.2.4
  Downloaded num-rational v0.2.4
  Downloaded num_cpus v1.13.0
  Downloaded rand v0.7.3
  Downloaded scopeguard v1.1.0
  Downloaded thread_local v1.0.1
  Downloaded either v1.5.3
  Downloaded rand_core v0.5.1
  Downloaded getrandom v0.1.14
  Downloaded lazy_static v1.4.0
  Downloaded rand_chacha v0.2.2
  Downloaded derive_more v0.99.5
  Downloaded num-traits v0.2.11
  Downloaded serde_json v1.0.52
  Downloaded num v0.2.1
  Downloaded rayon v1.3.0
  Downloaded memoffset v0.5.4
  Downloaded syn v1.0.18
  Downloaded num-bigint v0.2.6
  Downloaded quote v1.0.3
  Downloaded num-iter v0.1.40
  Downloaded enum_derive v0.1.7
  Downloaded 45 crates (2.6 MB) in 1.04s
   Compiling autocfg v1.0.0
   Compiling cfg-if v0.1.10
   Compiling libc v0.2.69
   Compiling proc-macro2 v1.0.10
   Compiling lazy_static v1.4.0
   Compiling unicode-xid v0.2.0
   Compiling maybe-uninit v2.0.0
   Compiling syn v1.0.18
   Compiling getrandom v0.1.14
   Compiling scopeguard v1.1.0
   Compiling memchr v2.3.3
   Compiling ryu v1.0.4
   Compiling serde v1.0.106
   Compiling rayon-core v1.7.0
   Compiling ppv-lite86 v0.2.6
   Compiling itoa v0.4.5
   Compiling regex-syntax v0.6.17
   Compiling either v1.5.3
   Compiling arrayvec v0.5.1
   Compiling custom_derive v0.1.7
   Compiling enum_derive v0.1.7
   Compiling thread_local v1.0.1
   Compiling num-traits v0.2.11
   Compiling crossbeam-utils v0.7.2
   Compiling num-integer v0.1.42
   Compiling memoffset v0.5.4
   Compiling crossbeam-epoch v0.8.2
   Compiling num-bigint v0.2.6
   Compiling num-iter v0.1.40
   Compiling num-rational v0.2.4
   Compiling num-complex v0.2.4
   Compiling aho-corasick v0.7.10
   Compiling crossbeam-queue v0.2.1
   Compiling quote v1.0.3
   Compiling num_cpus v1.13.0
   Compiling crossbeam-deque v0.7.3
   Compiling rand_core v0.5.1
   Compiling rand_chacha v0.2.2
   Compiling rand v0.7.3
   Compiling rayon v1.3.0
   Compiling regex v1.3.7
   Compiling num v0.2.1
   Compiling serde_derive v1.0.106
   Compiling derive_more v0.99.5
   Compiling serde_json v1.0.52
   Compiling apery v1.0.3 (/home/nakada/shogi/apery_rust)
    Finished release [optimized] target(s) in 1m 00s
$ ./target/release/apery <<EOF
> isready
> go byoyomi 5000
> wait
> EOF
readyok
info depth 1 seldepth 1 multipv 1 score cp 95 nodes 32 nps 2461 time 13 pv 2g2f
info depth 2 seldepth 2 multipv 1 score cp 114 nodes 70 nps 5384 time 13 pv 2g2f 1c1d
info depth 3 seldepth 3 multipv 1 score cp 118 nodes 123 nps 9461 time 13 pv 2g2f 3c3d 2f2e
info depth 4 seldepth 4 multipv 1 score cp 171 nodes 191 nps 14692 time 13 pv 2g2f 3c3d 2f2e
info depth 5 seldepth 5 multipv 1 score cp 304 nodes 318 nps 22714 time 14 pv 2g2f 3c3d 2f2e
info depth 6 seldepth 6 multipv 1 score cp 87 nodes 1006 nps 71857 time 14 pv 2g2f 3c3d 6i7h 2b3c 5i6i 3a3b
info depth 7 seldepth 8 multipv 1 score cp 47 nodes 2516 nps 157250 time 16 pv 2g2f 3c3d 6i7h 8c8d 2f2e 2b3c 7g7f 3a2b 8h3c+ 2b3c
info depth 8 seldepth 13 multipv 1 score cp 71 nodes 3234 nps 190235 time 17 pv 2g2f 3c3d 6i7h 2b3c 5i6i 8c8d 2f2e 3a2b 2e2d
info depth 9 seldepth 12 multipv 1 score cp 87 nodes 10110 nps 439565 time 23 pv 7g7f 3c3d 6i7h 2b3c 8h3c+ 2a3c 7i8h 3a2b 2g2f 4a3b 2f2e 8c8d
info depth 17 seldepth 24 multipv 1 score cp 8 nodes 193483 nps 830399 time 233 pv 2g2f 4a3b 6i7h 8c8d 2f2e 8d8e 2e2d 2c2d 2h2d P*2c 2d2f 3c3d 2f3f 8b8d 7g7f 8e8f 8g8f 8d8f 3f3d 2b8h+ 7i8h
info depth 20 seldepth 26 multipv 1 score cp 46 nodes 444367 nps 838428 time 530 pv 7g7f 4a3b 6i7h 8c8d 2g2f 8d8e 8h7g 3c3d 7i8h 2b7g+ 8h7g 3a2b 3g3f B*6d B*3g 9c9d 2f2e 5a4b 1g1f 6d3g+ 2i3g 2b3c 3i3h
info depth 21 seldepth 29 multipv 1 score cp 51 nodes 685355 nps 844033 time 812 pv 7g7f 4a3b 8h7g 3c3d 7i8h 2b7g+ 8h7g 5a4b 3i3h 3a2b 6i7h 2b3c 3g3f 7a7b 5i6h 7c7d 3h3g 7b7c 3g4f 7c6d 2i3g 8a7c
info depth 22 seldepth 27 multipv 1 score cp 50 nodes 962330 nps 846376 time 1137 pv 7g7f 4a3b 8h7g 3c3d 7i8h 2b7g+ 8h7g 5a4b 3i3h 3a2b 6i7h 2b3c 3g3f 7a7b 5i6h 7c7d 3h3g 7b7c 3g4f 7c6d 2g2f 8a7c 2i3g
info depth 23 seldepth 28 multipv 1 score cp 48 nodes 1516364 nps 864025 time 1755 pv 7g7f 4a3b 8h7g 3c3d 7i8h 2b7g+ 8h7g 3a2b 3i3h 7a7b 6i7h 5a4b 4g4f 7c7d 3h4g 2b3c 4i3h 7b7c 2g2f 7c6d 6g6f 8a7c 4g5f
info depth 24 seldepth 30 multipv 1 score cp 90 nodes 2363045 nps 877151 time 2694 pv 7g7f 4a3b 2g2f 8c8d 2f2e 8d8e 8h7g 3c3d 7i8h 2b3c 7g3c+ 3b3c 6i7h 7a7b 8h7g 7c7d 3i3h 7b7c 3g3f 4c4d 3h3g 7c6d 6g6f 5a4b 5i6h 8a7c
info depth 25 seldepth 32 multipv 1 score cp 66 upperbound nodes 3178630 nps 876621 time 3626 pv 7g7f 3c3d 2g2f 8c8d 2f2e 8d8e 2e2d 2c2d 2h2d 2b8h+ 7i8h B*3c 2d2h P*2g
info depth 25 seldepth 35 multipv 1 score cp 75 nodes 3571486 nps 878162 time 4067 pv 7g7f 8c8d 2g2f 4a3b 2f2e 8d8e 8h7g 3c3d 7i8h 2b7g+ 8h7g 3a2b 3g3f 2b3c 2i3g 7a7b 6i7h 7c7d 3i3h 5a4b 2h2i 1c1d 4i4h 8a7c 6g6f 6c6d 4g4f 7b6c 3h4g
info depth 26 seldepth 35 multipv 1 score cp 75 nodes 3939355 nps 875217 time 4501 pv 7g7f 8c8d 2g2f 4a3b 2f2e 8d8e 8h7g 3c3d 7i8h 2b7g+ 8h7g 3a2b 3g3f 2b3c 2i3g 7a7b 6i7h 7c7d 3i3h 5a4b 2h2i 1c1d 4i4h 8a7c 6g6f 6c6d 4g4f 7b6c 3h4g
info depth 25 seldepth 35 multipv 1 score cp 75 nodes 3939355 nps 875217 time 4501 pv 7g7f 8c8d 2g2f 4a3b 2f2e 8d8e 8h7g 3c3d 7i8h 2b7g+ 8h7g 3a2b 3g3f 2b3c 2i3g 7a7b 6i7h 7c7d 3i3h 5a4b 2h2i 1c1d 4i4h 8a7c 6g6f 6c6d 4g4f 7b6c 3h4g
bestmove 7g7f ponder 8c8d

 ビルドしたファイル apery を実行してUSIコマンドで応答があるかを確認する。

$ ./apery 
usi
id name Apery_WCSC30
id author HiraokaTakuya
option name Book_Enable type check default false
option name Book_File type filename default book/20191216/book.json
option name Byoyomi_Margin type spin default 500 min 0 max 9223372036854775807
option name Clear_Hash type button
option name Eval_Dir type string default eval/20190617
option name Eval_Hash type spin default 256 min 1 max 1048576
option name Minimum_Thinking_Time type spin default 20 min 0 max 5000
option name MultiPV type spin default 1 min 1 max 500
option name Slow_Mover type spin default 84 min 10 max 1000
option name Threads type spin default 1 min 1 max 8192
option name Time_Margin type spin default 500 min 0 max 9223372036854775807
option name USI_Hash type spin default 256 min 1 max 1048576
option name USI_Ponder type check default true
usiok
isready
No such file or directory (os error 2)
File name: eval/20190617/KPP.bin

 「File name: eval/20190617/KPP.bin」が無いというエラーが出るので apery_rust ディレクトリ内にある eval ディレクトリを実行ファイル apery と同じディレクトリ内にリンクを貼る。これでUSIプロトコルで通信ができる。

$ ls
./   .cargo-lock    apery*   build/  examples/     libapery.d
../  .fingerprint/  apery.d  deps/   incremental/  libapery.rlib
$ ln -s ../../eval/ .
$ ls
./   .cargo-lock    apery*   build/  eval@      incremental/  libapery.rlib
../  .fingerprint/  apery.d  deps/   examples/  libapery.d
$ cd eval
$ ls
./  ../  .gitkeep  20190617/
$ cd 20190617/
$ ls -l
合計 797912
drwxr-xr-x 3 nakada nakada      4096 11月  4 13:12 ./
drwxr-xr-x 3 nakada nakada      4096 11月  4 13:04 ../
-rw-r--r-- 1 nakada nakada        41 11月  4 13:11 .git
-rw-r--r-- 1 nakada nakada  40625712 11月  4 13:11 KKP.bin
-rw-r--r-- 1 nakada nakada 776402496 11月  4 13:12 KPP.bin
-rw-r--r-- 1 nakada nakada      1022 11月  4 13:12 LICENSE-MIT
-rw-r--r-- 1 nakada nakada       283 11月  4 13:12 README.md
drwxr-xr-x 2 nakada nakada      4096 11月  4 13:12 log/