FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

RISC-V向けRust-Toolchain試行(2. Repositoryの修正試行)

f:id:msyksphinz:20171129020950p:plain

前回、RISC-V Rust Toolchainが公開されていたので早速ビルドしようとしていたのだが上手く行かなかった。

msyksphinz.hatenablog.com

$ make build
xargo build --target riscv32-unknown-none
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names -C link-arg=-Tlink.x -C linker=riscv32-unknown-elf-ld --target riscv32-unknown-none --crate-type bin --crate-type rlib` (exit code: 101)
--- stderr
error: Could not create LLVM TargetMachine for triple: riscv32: No available targets are compatible with this triple.


Makefile:5: recipe for target 'build' failed
make: *** [build] Error 101

Rustの環境のことは良く分かっていないが、どうもriscv-rust-toolchainがそもそもちゃんとビルドできていない気がする。 もう一度見直してみよう。

riscv-rust-toolchainリポジトリの修正

まず、ビルド中にno such file or directory : "llvm/Target/TargetSubtargetInfo.h" みたいな感じで怒られたので(ログ取り忘れた)、無理やりfindして当該ソースコードの場所を見つけ、ヘッダファイルの位置を修正した。

diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp
index fafa119498..7d5026cc52 100644
--- a/src/rustllvm/PassWrapper.cpp
+++ b/src/rustllvm/PassWrapper.cpp
@@ -22,7 +22,8 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Target/TargetMachine.h"
-#include "llvm/Target/TargetSubtargetInfo.h"
+// #include "llvm/Target/TargetSubtargetInfo.h"
+#include "llvm/CodeGen/TargetSubtargetInfo.h"
 #include "llvm/Transforms/IPO/PassManagerBuilder.h"

 #if LLVM_VERSION_GE(4, 0)

ビルド中にライブラリが無いと怒られる

これも同様に、ビルド中にerror while loading shared libraries: "libLLVM-6.0svn.so"みたいな感じで怒られるので、同じようにファイルを探してLD_LIBRARY_PATHに追加した。

export LD_LIBRARY_PATH=/home/msyksphinz/work/riscv-rust-toolchain/build/llvm/lib/:${LD_LIBRARY_PATH}

これでビルド再開。

make -j4 toolchain

自宅のPCは4コアしかVirtualBoxに割り当てていないので4並列でビルドしている。これで2時間程度ずっとビルドしっぱなしだ!Rustってこんなに時間がかかるの?

と思ったら途中でビルドに失敗した。まじかー。

   Compiling syn v0.11.11
   Compiling aho-corasick v0.6.3
   Compiling tar v0.4.13
error: failed to run custom build command for `openssl-sys v0.9.15`
process didn't exit successfully: `/home/msyksphinz/work/riscv-rust-toolchain/rust/build/x86_64-unknown-linux-gnu/stage2-tools/debug/build/openssl-sys-2f2ffb2ab3e0d9d3/build-sc$
ipt-build` (exit code: 101)
--- stdout
cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
cargo:rerun-if-env-changed=OPENSSL_DIR
run pkg_config fail: "`\"pkg-config\" \"--libs\" \"--cflags\" \"openssl\"` did not exit successfully: exit code: 1\n--- stderr\nPackage openssl was not found in the pkg-config $
earch path.\nPerhaps you should add the directory containing `openssl.pc\'\nto the PKG_CONFIG_PATH environment variable\nNo package \'openssl\' found\n"

--- stderr
thread 'main' panicked at '

Could not find directory of OpenSSL installation, and this `-sys` crate cannot
proceed without this knowledge. If OpenSSL is installed and this crate had
trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
compilation process.

If you're in a situation where you think the directory *should* be found
automatically, please open a bug at https://github.com/sfackler/rust-openssl
and include information about your system as well as this message.

    $HOST = x86_64-unknown-linux-gnu
    $TARGET = x86_64-unknown-linux-gnu
    openssl-sys = 0.9.15

', /home/msyksphinz/work/riscv-rust-toolchain/build/cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.15/build.rs:198:4
note: Run with `RUST_BACKTRACE=1` for a backtrace.

warning: build failed, waiting for other jobs to finish...
error: build failed


command did not execute successfully: "/home/msyksphinz/work/riscv-rust-toolchain/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "-j" "4" "--target" "x86_64-unkno
wn-linux-gnu" "--manifest-path" "/home/msyksphinz/work/riscv-rust-toolchain/rust/src/tools/cargo/Cargo.toml"
expected success, got: exit code: 101

f:id:msyksphinz:20171201012136p:plain

まだビルド試行は続く。