2.3. プロジェクトのビルド
コマンドラインで Rust プロジェクトをビルドするには、プロジェクトディレクトリーに移動し、以下のように cargo ツールを実行します。
Red Hat Enterprise Linux 7 の場合:
scl enable rust-toolset-1.35 'cargo build'
$ scl enable rust-toolset-1.35 'cargo build'Copy to Clipboard Copied! Toggle word wrap Toggle overflow Red Hat Enterprise Linux 8 の場合:
cargo build
$ cargo buildCopy to Clipboard Copied! Toggle word wrap Toggle overflow
これにより、プロジェクトのすべての依存関係が解決され、不足している依存関係がダウンロードされ、rustc コンパイラーを使用してプロジェクトをコンパイルします。
デフォルトでは、プロジェクトはデバッグモードでビルドおよびコンパイルされます。リリースモードでプロジェクトをビルドするには、以下のように --release オプションを指定して cargo ツールを実行します。
Red Hat Enterprise Linux 7 の場合:
scl enable rust-toolset-1.35 'cargo build --release'
$ scl enable rust-toolset-1.35 'cargo build --release'Copy to Clipboard Copied! Toggle word wrap Toggle overflow Red Hat Enterprise Linux 8 の場合:
cargo build --release
$ cargo build --releaseCopy to Clipboard Copied! Toggle word wrap Toggle overflow
例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 secs$ 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 secsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Red 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$ cargo build Compiling helloworld v0.1.0 (file:///home/vslavik/helloworld) Finished dev [unoptimized + debuginfo] target(s) in 0.51 secsCopy to Clipboard Copied! Toggle word wrap Toggle overflow
結果を確認します。
ディレクトリー target から開始して、サブディレクトリー構造が作成されました。このプロジェクトはデバッグモードでビルドされているため、実際のビルド出力は追加のサブディレクトリー debug に含まれます。実際に生成される実行可能ファイルは target/debug/helloworld です。
tree ツールは、デフォルトの Red Hat Enterprise Linux リポジトリーから利用できます。インストールするには、以下を行います。
yum install tree
# yum install tree