2.4. プログラムの確認
cargo が管理する Rust プログラムを構築するには、コマンドラインでプロジェクトディレクトリーに移動し、以下のように cargo ツールを実行します。
Red Hat Enterprise Linux 7 の場合:
scl enable rust-toolset-1.35 'cargo check'
$ scl enable rust-toolset-1.35 'cargo check'Copy to Clipboard Copied! Toggle word wrap Toggle overflow Red Hat Enterprise Linux 8 の場合:
cargo check
$ cargo checkCopy to Clipboard Copied! Toggle word wrap Toggle overflow
実行可能なコードが必要ない場合は、Rust プログラム有効性の検証に cargo build ではなく cargo check を使用することを検討してください。この cargo check コマンドは、実行可能なコードを生成しないため、cargo build コマンドを使用した完全なプロジェクトビルドよりも高速です。
デフォルトでは、プロジェクトはデバッグモードでチェックされます。リリースモードでプロジェクトを確認するには、以下のように --release オプションを指定して cargo ツールを実行します。
Red Hat Enterprise Linux 7 の場合:
scl enable rust-toolset-1.35 'cargo check --release'
$ scl enable rust-toolset-1.35 'cargo check --release'Copy to Clipboard Copied! Toggle word wrap Toggle overflow Red Hat Enterprise Linux 8 の場合:
cargo check --release
$ cargo check --releaseCopy to Clipboard Copied! Toggle word wrap Toggle overflow
例2.3 cargo でのプログラムの確認
この例では、例2.2「cargo を使用したプロジェクトのビルド」 従って Rust プロジェクト helloworld を正常に構築していることを前提としています。
ディレクトリー helloworld に移動し、プロジェクトを確認します。
Red Hat Enterprise Linux 7 の場合:
scl enable rust-toolset-1.35 'cargo check' Compiling helloworld v0.1.0 (file:///home/vslavik/helloworld) Finished dev [unoptimized + debuginfo] target(s) in 0.5 secs$ scl enable rust-toolset-1.35 'cargo check' Compiling helloworld v0.1.0 (file:///home/vslavik/helloworld) Finished dev [unoptimized + debuginfo] target(s) in 0.5 secsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Red Hat Enterprise Linux 8 の場合:
cargo check Compiling helloworld v0.1.0 (file:///home/vslavik/helloworld) Finished dev [unoptimized + debuginfo] target(s) in 0.5 secs$ cargo check Compiling helloworld v0.1.0 (file:///home/vslavik/helloworld) Finished dev [unoptimized + debuginfo] target(s) in 0.5 secsCopy to Clipboard Copied! Toggle word wrap Toggle overflow
プロジェクトがチェックされ、cargo build コマンドの出力に似ています。ただし、実行ファイルは生成されません。これを確認するには、現在の時間を実行ファイルのタイムスタンプと比較します。
date Fri Oct 13 08:53:21 CEST 2017 ls -l target/debug/helloworld -rwxrwxr-x. 2 vslavik vslavik 252624 Oct 13 08:48 target/debug/helloworld
$ date
Fri Oct 13 08:53:21 CEST 2017
$ ls -l target/debug/helloworld
-rwxrwxr-x. 2 vslavik vslavik 252624 Oct 13 08:48 target/debug/helloworld