0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Rust】ビルドする時に"Error finalizing incremental compilation session directory `path`: Permission denied (os error 13)" と警告される

Last updated at Posted at 2021-10-26

環境

  • Windows 10
  • Ubuntu 18.04 LTS (WSLで実行)
  • VSCodeを使用

エラー

Rustのチュートリアル(https://www.rust-lang.org/ja/learn/get-started)でフェリス:crab:を表示させるプログラムをビルドすると以下のような警告が出る。

warning: Error finalizing incremental compilation session directory `/home/hoge/hello-rust/target/debug/incremental/hello_rust-299femrl6jqky/s-g37i7q3wft-lcl3r5-working`: Permission denied (os error 13)

warning: `hello-rust` (bin "hello-rust") generated 1 warning

Finished dev [unoptimized + debuginfo] target(s) in 35.92s

ビルドは正常に終了してるし、実行も問題なくできていますが、毎回警告されると鬱陶しいので解決します。

原因

とりあえずググってみると以下のようなトピックを見つけました。
https://users.rust-lang.org/t/strange-cargo-build-file-permission-warnings/46980
https://github.com/rust-lang/rust/issues/62031
どうやらVSCodeを使っていることが問題らしい。

解決方法

WSLを使っていたので、WSL2にすれば解決しました。

WSL -> WSL2への移行方法

まずpower shellを開き、現在使っているWSLバージョンを確認。

PS C:\Users\hoge> wsl --list --verbose
NAME            STATE           VERSION
Ubuntu-18.04    Stopped         1   

VERSIONが1なのでWSL1を使っていると分かる。

https://docs.microsoft.com/ja-jp/windows/wsl/install-manual#step-4---download-the-linux-kernel-update-package
にアクセスし、書いてある通りにLinux カーネル更新プログラムパッケージをダウンロードします。
続けて以下を実行すると、今後Linuxをインストールする時にWSLのバージョンが2で固定されます。

PS C:\Users\hoge> wsl --set-default-version 2

ただこの状態では以前インストールしたLinuxでのWSLのバージョンは1のままなので

PS C:\Users\hoge> wsl --list --verbose
NAME            STATE           VERSION
Ubuntu-18.04    Stopped         1   

ここから以下を実行して変更します。

PS C:\Users\hoge> wsl --set-version Ubuntu-18.04 2
変換中です。この処理には数分かかることがあります... 
WSL 2 との主な違いについては、https://aka.ms/wsl2 を参照してください 
変換が完了しました。

変換は数分で終わると書かれていますが、環境によってはもっと長い時間がかかるので気長に待ちましょう。
最後に変更が完了しているか確かめます。

PS C:\Users\hoge> wsl --list --verbose
NAME            STATE           VERSION
Ubuntu-18.04    Stopped         2   

VERSIONが2になっており、無事に変更が完了したことが分かります。

Rustで警告が表示されないことを確認

./targetを削除してから、ビルドしなおし、実行します。

user@DESKTOP:~/rust_program/hello-rust$ cargo run
   Compiling smawk v0.3.1
   Compiling unicode-width v0.1.9
   Compiling smallvec v0.4.5
   Compiling textwrap v0.13.4
   Compiling ferris-says v0.2.1
   Compiling hello-rust v0.1.0 (/home/hoge/rust_program/hello-rust)
    Finished dev [unoptimized + debuginfo] target(s) in 1.98s
     Running `target/debug/hello-rust`
 ___________________________
< Hello fellow Rustaceans! >
 ---------------------------
        \
         \
            _~^~^~_
        \) /  o o  \ (/
          '_   -   _'
          / '-----' \

無事に警告なしでフェリスを表示することができました。

最後に

よいRustライフを!:crab:

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?