Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: clarify dash replacement rule in target name #13887

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/doc/man/cargo-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ The JSON output has the following format:
"crate_types": [
"bin"
],
/* The name of the target. */
/* The name of the target.
For lib targets, dashes will be replaced with underscores.
*/
"name": "my-package",
/* Absolute path to the root source file of the target. */
"src_path": "/path/to/my-package/src/main.rs",
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ OUTPUT FORMAT
"crate_types": [
"bin"
],
/* The name of the target. */
/* The name of the target.
For lib targets, dashes will be replaced with underscores.
*/
"name": "my-package",
/* Absolute path to the root source file of the target. */
"src_path": "/path/to/my-package/src/main.rs",
Expand Down
4 changes: 3 additions & 1 deletion src/doc/src/commands/cargo-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ The JSON output has the following format:
"crate_types": [
"bin"
],
/* The name of the target. */
/* The name of the target.
For lib targets, dashes will be replaced with underscores.
*/
"name": "my-package",
/* Absolute path to the root source file of the target. */
"src_path": "/path/to/my-package/src/main.rs",
Expand Down
13 changes: 7 additions & 6 deletions src/doc/src/reference/cargo-targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ configuring the settings for a target.

The library target defines a "library" that can be used and linked by other
libraries and executables. The filename defaults to `src/lib.rs`, and the name
of the library defaults to the name of the package. A package can have only
one library. The settings for the library can be [customized] in the `[lib]`
table in `Cargo.toml`.
of the library defaults to the name of the package, with any dashes replaced
with underscores. A package can have only one library. The settings for the
library can be [customized] in the `[lib]` table in `Cargo.toml`.

```toml
# Example of customizing the library in Cargo.toml.
Expand Down Expand Up @@ -198,9 +198,10 @@ The `name` field specifies the name of the target, which corresponds to the
filename of the artifact that will be generated. For a library, this is the
crate name that dependencies will use to reference it.

For the `[lib]` and the default binary (`src/main.rs`), this defaults to the
name of the package, with any dashes replaced with underscores. For other
[auto discovered](#target-auto-discovery) targets, it defaults to the
For the library target, this defaults to the name of the package , with any
dashes replaced with underscores. For the default binary (`src/main.rs`),
it also defaults to the name of the package, with no replacement for dashes.
For [auto discovered](#target-auto-discovery) targets, it defaults to the
directory or file name.

This is required for all targets except `[lib]`.
Expand Down
8 changes: 5 additions & 3 deletions src/doc/src/reference/external-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ structure:
"crate_types": [
"lib"
],
/* The name of the target. */
"name": "my-package",
/* The name of the target.
For lib targets, dashes will be replaced with underscores.
*/
"name": "my_package",
/* Absolute path to the root source file of the target. */
"src_path": "/path/to/my-package/src/lib.rs",
/* The Rust edition of the target.
Expand Down Expand Up @@ -152,7 +154,7 @@ following structure:
"crate_types": [
"lib"
],
"name": "my-package",
"name": "my_package",
"src_path": "/path/to/my-package/src/lib.rs",
"edition": "2018",
"doc": true,
Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ The following is a description of the JSON structure:
"target": {
"kind": ["lib"],
"crate_types": ["lib"],
"name": "my-package",
"name": "my_package",
"src_path": "/path/to/my-package/src/lib.rs",
"edition": "2018",
"test": true,
Expand Down
4 changes: 3 additions & 1 deletion src/etc/man/cargo-metadata.1
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ The JSON output has the following format:
"crate_types": [
"bin"
],
/* The name of the target. */
/* The name of the target.
For lib targets, dashes will be replaced with underscores.
*/
"name": "my\-package",
/* Absolute path to the root source file of the target. */
"src_path": "/path/to/my\-package/src/main.rs",
Expand Down