From 03354288e37be2c6ab0a8dfcf887fdf8b0a91d7d Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Wed, 8 May 2024 12:59:29 -0400 Subject: [PATCH 1/2] docs(json): mention dashes replaced with underscores --- src/doc/man/cargo-metadata.md | 4 +++- src/doc/man/generated_txt/cargo-metadata.txt | 4 +++- src/doc/src/commands/cargo-metadata.md | 4 +++- src/doc/src/reference/external-tools.md | 8 +++++--- src/doc/src/reference/unstable.md | 2 +- src/etc/man/cargo-metadata.1 | 4 +++- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/doc/man/cargo-metadata.md b/src/doc/man/cargo-metadata.md index 0057e815134..bb8fef077e3 100644 --- a/src/doc/man/cargo-metadata.md +++ b/src/doc/man/cargo-metadata.md @@ -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", diff --git a/src/doc/man/generated_txt/cargo-metadata.txt b/src/doc/man/generated_txt/cargo-metadata.txt index f1f5b1fc275..ce3907ffbb6 100644 --- a/src/doc/man/generated_txt/cargo-metadata.txt +++ b/src/doc/man/generated_txt/cargo-metadata.txt @@ -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", diff --git a/src/doc/src/commands/cargo-metadata.md b/src/doc/src/commands/cargo-metadata.md index 31c01df85b7..d4ac2b3a4ee 100644 --- a/src/doc/src/commands/cargo-metadata.md +++ b/src/doc/src/commands/cargo-metadata.md @@ -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", diff --git a/src/doc/src/reference/external-tools.md b/src/doc/src/reference/external-tools.md index 7188f8f24de..f89870877b4 100644 --- a/src/doc/src/reference/external-tools.md +++ b/src/doc/src/reference/external-tools.md @@ -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. @@ -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, diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index 12d0816ee25..4850b7082ec 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -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, diff --git a/src/etc/man/cargo-metadata.1 b/src/etc/man/cargo-metadata.1 index e3cc27732e6..3e2ec312627 100644 --- a/src/etc/man/cargo-metadata.1 +++ b/src/etc/man/cargo-metadata.1 @@ -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", From 4b3123ef4fec9217cd1ffcf744ce17a08e1c2b8b Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Wed, 8 May 2024 13:00:45 -0400 Subject: [PATCH 2/2] docs(cargo-target): clarify dashs in bin target name wont be replaced --- src/doc/src/reference/cargo-targets.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/doc/src/reference/cargo-targets.md b/src/doc/src/reference/cargo-targets.md index ef29a520fc5..9129310399c 100644 --- a/src/doc/src/reference/cargo-targets.md +++ b/src/doc/src/reference/cargo-targets.md @@ -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. @@ -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]`.