LoginSignup
5
3

More than 3 years have passed since last update.

rustで作ったツールをシングルバイナリにするまでメモ

Posted at

まずは https://doc.rust-jp.rs/book/second-edition/ch01-03-hello-cargo.html
を参考にインストールから実装方法の確認までを行う

rustインストール

$ curl https://sh.rustup.rs -sSf | sh
$ export PATH="$HOME/.cargo/bin:$PATH"

をbashrcもしくはbash_profileにセットしておく

実装

$ cargo new hoge_project --bin
$ cd hoge_project

そしてsrc/main.rsに実装していく。

あとはCargo.tomlに依存ライブラリを追加し読み込むように設定したりする

$ cargo build

するとbuildできるのでtarget/debug 生成された hoge_project バイナリ実行できる

なお、これらをまとめて $ cargo runにて実行できるのでそれでもよい。

実装完了したらあとはこれをバイナリとして配布できるようにする。

シングルバイナリ化

$ rustup target add x86_64-unknown-linux-musl
$ cargo build --release --target=x86_64-unknown-linux-musl

これで行けたのかな・・・・??

target/release に生成されたバイナリファイルを
gitプロジェクトの直下にbinディレクトリ用意して設置して上げておいた(これでいいのかな?)

5
3
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
5
3