|
| 1 | +<!-- |
1 | 2 | # Cargo changes |
| 3 | +--> |
2 | 4 |
|
| 5 | +# Cargo への変更 |
| 6 | + |
| 7 | +<!-- |
3 | 8 | ## Summary |
| 9 | +--> |
| 10 | + |
| 11 | +## 概要 |
4 | 12 |
|
| 13 | +<!-- |
5 | 14 | - If there is a target definition in a `Cargo.toml` manifest, it no longer |
6 | 15 | automatically disables automatic discovery of other targets. |
7 | 16 | - Target paths of the form `src/{target_name}.rs` are no longer inferred for |
8 | 17 | targets where the `path` field is not set. |
9 | 18 | - `cargo install` for the current directory is no longer allowed, you must |
10 | | - specify `cargo install --path .` to install the current package. |
| 19 | + specify `cargo install --path .` to install the current package. |
| 20 | +--> |
| 21 | + |
| 22 | +- `Cargo.toml` にターゲットの指定がある場合であっても、他のターゲットの自動探索がされなくなるということはなくなりました[^1]。 |
| 23 | +- `path` フィールドが指定されていないターゲットに対して、`src/{target_name}.rs` の形のターゲットパスは自動設定されなくなりました[^2]。 |
| 24 | +- 現在のディレクトリに対して `cargo install` できなくなりました。現在のパッケージをインストールしたい場合は `cargo install --path .` と指定する必要があります[^3]。 |
| 25 | + |
| 26 | +[^1] *訳注*: |
| 27 | + Cargo は、`Cargo.toml` 内に明示的に指定されていなくても、[フォルダ構成の慣習][package-layout]に従っているファイルに関しては、自動でターゲットに追加します。 |
| 28 | + 例えば、`src/bin/my_application.rs` というファイルがプロジェクト内に存在したら、`Cargo.toml` に `[[bin]]` セクションで `my_application` の存在が宣言されていなくても、自動的にこのファイルがバイナリターゲット(つまり、`cargo run --bin my_application` として実行できるもの)としてビルドされるようになっています。 |
| 29 | + これは、[*ターゲットの自動探索*][target-auto-discovery]と呼ばれています。<br> |
| 30 | + Rust 2015 と Rust 2018 の違いは、`Cargo.toml` に明示的にターゲットが1つ以上宣言されている場合(つまり、`[lib]`, `[[bin]]`, `[[test]]`, `[[bench]]`, `[[example]]` のどれかが1つ以上ある場合)に生じます。 |
| 31 | + Rust 2015 では、これらのうちどれか1つが指定されていた場合、ターゲットの自動探索は無効化されました。 |
| 32 | + Rust 2018 では、その場合であっても、ターゲットの自動探索は無効化されません。<br> |
| 33 | + 詳細は、[Cargo Book の "Target auto-discovery"(英語)][target-auto-discovery]も御覧ください。 |
| 34 | + |
| 35 | +[^2] *訳注*: |
| 36 | + [WIP] 詳細は不明です。 |
| 37 | + |
| 38 | +[^3] *訳注*: |
| 39 | + [`cargo install`][cargo-install] コマンドは、指定したクレートのバイナリターゲットをインストールする、つまりビルドして実行ファイルを所定の場所に配置するためのコマンドです。 |
| 40 | + Rust 2015 では、カレントディレクトリが Cargo プロジェクト下であったときに `cargo install` とだけ実行すると、そのプロジェクトに含まれるクレートを対象としてインストールが実行されました。 |
| 41 | + Rust 2018 ではこの挙動は廃止され、`cargo install --path .` と明示的にカレントディレクトリのクレートをインストールの対象にすると宣言しなければならなくなりました。 |
| 42 | + |
| 43 | +[package-layout]: https://doc.rust-lang.org/cargo/guide/project-layout.html |
| 44 | +[target-auto-discovery]: https://doc.rust-lang.org/cargo/reference/cargo-targets.html#the-path-field |
| 45 | +[cargo-install]: https://doc.rust-lang.org/cargo/commands/cargo-install.html |
0 commit comments