2.3. プロジェクトのビルド
コマンドラインで Rust プロジェクトをビルドするには、プロジェクトディレクトリーに移動し、以下のように cargo ツールを実行します。
Red Hat Enterprise Linux 7 の場合:
$ scl enable rust-toolset-1.35 'cargo build'Red Hat Enterprise Linux 8 の場合:
$ cargo build
これにより、プロジェクトのすべての依存関係が解決され、不足している依存関係がダウンロードされ、rustc コンパイラーを使用してプロジェクトをコンパイルします。
デフォルトでは、プロジェクトはデバッグモードでビルドおよびコンパイルされます。リリースモードでプロジェクトをビルドするには、以下のように --release オプションを指定して cargo ツールを実行します。
Red Hat Enterprise Linux 7 の場合:
$ scl enable rust-toolset-1.35 'cargo build --release'Red Hat Enterprise Linux 8 の場合:
$ cargo build --release
例2.2 cargo を使用したプロジェクトのビルド
この例では、例2.1「cargo を使用したプロジェクトの作成」 従って Rust プロジェクト helloworld を正常に作成していることを前提としています。
ディレクトリーに移動してhelloworld、プロジェクトをビルドします。
Red Hat Enterprise Linux 7 の場合:
$ scl enable rust-toolset-1.35 'cargo build' Compiling helloworld v0.1.0 (file:///home/vslavik/helloworld) Finished dev [unoptimized + debuginfo] target(s) in 0.51 secsRed Hat Enterprise Linux 8 の場合:
$ cargo build Compiling helloworld v0.1.0 (file:///home/vslavik/helloworld) Finished dev [unoptimized + debuginfo] target(s) in 0.51 secs
結果を確認します。
$ tree
.
├── Cargo.lock
├── Cargo.toml
├── src
│ └── main.rs
└── target
└── debug
├── build
├── deps
│ └── helloworld-b7c6fab39c2d17a7
├── examples
├── helloworld
├── helloworld.d
├── incremental
└── native
8 directories, 6 files
ディレクトリー target から開始して、サブディレクトリー構造が作成されました。このプロジェクトはデバッグモードでビルドされているため、実際のビルド出力は追加のサブディレクトリー debug に含まれます。実際に生成される実行可能ファイルは target/debug/helloworld です。
tree ツールは、デフォルトの Red Hat Enterprise Linux リポジトリーから利用できます。インストールするには、以下を行います。
# yum install tree