diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index 253de9a9692..0d2197f4491 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -337,23 +337,7 @@ To pass the arguments to the subcommand, remove `--`", } } if commands::run::is_manifest_command(cmd) { - if gctx.cli_unstable().script { - return Ok((args, GlobalArgs::default())); - } else { - gctx.shell().print_report( - &[ - Level::WARNING.secondary_title( - format!("user-defined alias `{cmd}` has the appearance of a manifest-command") - ).element( - Level::NOTE.message( - "this was previously accepted but will be phased out when `-Zscript` is stabilized; \ - see " - ) - ) - ], - false - )?; - } + return Ok((args, GlobalArgs::default())); } let mut alias = alias @@ -490,31 +474,12 @@ impl Exec { match self { Self::Builtin(exec) => exec(gctx, subcommand_args), Self::Manifest(cmd) => { - let ext_path = super::find_external_subcommand(gctx, &cmd); - if !gctx.cli_unstable().script && ext_path.is_some() { - gctx.shell().print_report( - &[ - Level::WARNING.secondary_title( - format!("external subcommand `{cmd}` has the appearance of a manifest-command") - ).element( - Level::NOTE.message( - "this was previously accepted but will be phased out when `-Zscript` is stabilized; \ - see " - ) - ) - ], - false - )?; - - Self::External(cmd).exec(gctx, subcommand_args) - } else { - let ext_args: Vec = subcommand_args - .get_many::("") - .unwrap_or_default() - .cloned() - .collect(); - commands::run::exec_manifest_command(gctx, &cmd, &ext_args) - } + let ext_args: Vec = subcommand_args + .get_many::("") + .unwrap_or_default() + .cloned() + .collect(); + commands::run::exec_manifest_command(gctx, &cmd, &ext_args) } Self::External(cmd) => { let mut ext_args = vec![OsStr::new(&cmd)]; @@ -581,11 +546,11 @@ pub fn cli(gctx: &GlobalContext) -> Command { let usage = if is_rustup() { color_print::cstr!( - "cargo [+toolchain] [OPTIONS] [COMMAND]\n cargo [+toolchain] [OPTIONS] -Zscript <> [ARGS]..." + "cargo [+toolchain] [OPTIONS] [COMMAND]\n cargo [+toolchain] [OPTIONS] <> [ARGS]..." ) } else { color_print::cstr!( - "cargo [OPTIONS] [COMMAND]\n cargo [OPTIONS] -Zscript <> [ARGS]..." + "cargo [OPTIONS] [COMMAND]\n cargo [OPTIONS] <> [ARGS]..." ) }; diff --git a/src/bin/cargo/commands/run.rs b/src/bin/cargo/commands/run.rs index e95ba196e15..920aefbb428 100644 --- a/src/bin/cargo/commands/run.rs +++ b/src/bin/cargo/commands/run.rs @@ -96,84 +96,42 @@ pub fn is_manifest_command(arg: &str) -> bool { pub fn exec_manifest_command(gctx: &mut GlobalContext, cmd: &str, args: &[OsString]) -> CliResult { let manifest_path = Path::new(cmd); - match (manifest_path.is_file(), gctx.cli_unstable().script) { - (true, true) => {} - (true, false) => { - return Err(anyhow::anyhow!("running the file `{cmd}` requires `-Zscript`").into()); - } - (false, true) => { - let possible_commands = crate::list_commands(gctx); - let is_dir = if manifest_path.is_dir() { - format!(": `{cmd}` is a directory") - } else { - "".to_owned() - }; - let suggested_command = if let Some(suggested_command) = possible_commands - .keys() - .filter(|c| cmd.starts_with(c.as_str())) - .max_by_key(|c| c.len()) - { - let actual_args = cmd.strip_prefix(suggested_command).unwrap(); - let args = if args.is_empty() { - "".to_owned() - } else { - format!( - " {}", - args.into_iter().map(|os| os.to_string_lossy()).join(" ") - ) - }; - format!( - "\nhelp: there is a command with a similar name: `{suggested_command} {actual_args}{args}`" - ) - } else { + if !manifest_path.is_file() { + let possible_commands = crate::list_commands(gctx); + let is_dir = if manifest_path.is_dir() { + format!(": `{cmd}` is a directory") + } else { + "".to_owned() + }; + let suggested_command = if let Some(suggested_command) = possible_commands + .keys() + .filter(|c| cmd.starts_with(c.as_str())) + .max_by_key(|c| c.len()) + { + let actual_args = cmd.strip_prefix(suggested_command).unwrap(); + let args = if args.is_empty() { "".to_owned() - }; - let suggested_script = if let Some(suggested_script) = suggested_script(cmd) { - format!("\nhelp: there is a script with a similar name: `{suggested_script}`") } else { - "".to_owned() - }; - return Err(anyhow::anyhow!( - "no such file or subcommand `{cmd}`{is_dir}{suggested_command}{suggested_script}" - ) - .into()); - } - (false, false) => { - // HACK: duplicating the above for minor tweaks but this will all go away on - // stabilization - let possible_commands = crate::list_commands(gctx); - let suggested_command = if let Some(suggested_command) = possible_commands - .keys() - .filter(|c| cmd.starts_with(c.as_str())) - .max_by_key(|c| c.len()) - { - let actual_args = cmd.strip_prefix(suggested_command).unwrap(); - let args = if args.is_empty() { - "".to_owned() - } else { - format!( - " {}", - args.into_iter().map(|os| os.to_string_lossy()).join(" ") - ) - }; format!( - "\nhelp: there is a command with a similar name: `{suggested_command} {actual_args}{args}`" + " {}", + args.into_iter().map(|os| os.to_string_lossy()).join(" ") ) - } else { - "".to_owned() - }; - let suggested_script = if let Some(suggested_script) = suggested_script(cmd) { - format!( - "\nhelp: there is a script with a similar name: `{suggested_script}` (requires `-Zscript`)" - ) - } else { - "".to_owned() }; - return Err(anyhow::anyhow!( - "no such subcommand `{cmd}`{suggested_command}{suggested_script}" + format!( + "\nhelp: there is a command with a similar name: `{suggested_command} {actual_args}{args}`" ) - .into()); - } + } else { + "".to_owned() + }; + let suggested_script = if let Some(suggested_script) = suggested_script(cmd) { + format!("\nhelp: there is a script with a similar name: `{suggested_script}`") + } else { + "".to_owned() + }; + return Err(anyhow::anyhow!( + "no such file or subcommand `{cmd}`{is_dir}{suggested_command}{suggested_script}" + ) + .into()); } let manifest_path = root_manifest(Some(manifest_path), gctx)?; diff --git a/src/bin/cargo/main.rs b/src/bin/cargo/main.rs index aa20372644b..447f60b42bb 100644 --- a/src/bin/cargo/main.rs +++ b/src/bin/cargo/main.rs @@ -276,9 +276,7 @@ fn execute_external_subcommand(gctx: &GlobalContext, cmd: &str, args: &[&OsStr]) let command = match path { Some(command) => command, None => { - let script_suggestion = if gctx.cli_unstable().script - && std::path::Path::new(cmd).is_file() - { + let script_suggestion = if std::path::Path::new(cmd).is_file() { let sep = std::path::MAIN_SEPARATOR; format!( "\nhelp: To run the file `{cmd}`, provide a relative path like `.{sep}{cmd}`" diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 34cab04b167..d5cec2afaf3 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -794,13 +794,8 @@ fn prepare_rustc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult .compilation .rustc_process(unit, is_primary, is_workspace)?; build_base_args(build_runner, &mut base, unit)?; + // TODO: remove once frontmatter hits nightly if unit.pkg.manifest().is_embedded() { - if !gctx.cli_unstable().script { - anyhow::bail!( - "parsing `{}` requires `-Zscript`", - unit.pkg.manifest_path().display() - ); - } base.arg("-Z").arg("crate-attr=feature(frontmatter)"); } @@ -849,13 +844,8 @@ fn prepare_rustdoc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResu let bcx = build_runner.bcx; // script_metadata is not needed here, it is only for tests. let mut rustdoc = build_runner.compilation.rustdoc_process(unit, None)?; + // TODO: remove once frontmatter hits nightly if unit.pkg.manifest().is_embedded() { - if !bcx.gctx.cli_unstable().script { - anyhow::bail!( - "parsing `{}` requires `-Zscript`", - unit.pkg.manifest_path().display() - ); - } rustdoc.arg("-Z").arg("crate-attr=feature(frontmatter)"); } rustdoc.inherit_jobserver(&build_runner.jobserver); diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index 0a4835ccdcc..663471674f8 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -891,7 +891,6 @@ unstable_cli_options!( rustdoc_mergeable_info: bool = ("Use rustdoc mergeable cross-crate-info files"), rustdoc_scrape_examples: bool = ("Allows Rustdoc to scrape code examples from reverse-dependencies"), sbom: bool = ("Enable the `sbom` option in build config in .cargo/config.toml file"), - script: bool = ("Enable support for single-file, `.rs` packages"), section_timings: bool = ("Enable support for extended compilation sections in --timings output"), separate_nightlies: bool, skip_rustdoc_fingerprint: bool, @@ -985,6 +984,8 @@ const STABILIZED_BUILD_DIR: &str = "build.build-dir is now always enabled."; const STABILIZED_CONFIG_INCLUDE: &str = "The `include` config key is now always available"; +const STABILIZED_SCRIPT: &str = "Cargo scripts are now always available"; + fn deserialize_comma_separated_list<'de, D>( deserializer: D, ) -> Result>, D::Error> @@ -1373,6 +1374,7 @@ impl CliUnstable { "package-workspace" => stabilized_warn(k, "1.89", STABILIZED_PACKAGE_WORKSPACE), "build-dir" => stabilized_warn(k, "1.91", STABILIZED_BUILD_DIR), "config-include" => stabilized_warn(k, "1.93", STABILIZED_CONFIG_INCLUDE), + "script" => stabilized_warn(k, "1.95", STABILIZED_SCRIPT), // Unstable features // Sorted alphabetically: @@ -1436,7 +1438,6 @@ impl CliUnstable { "separate-nightlies" => self.separate_nightlies = parse_empty(k, v)?, "checksum-freshness" => self.checksum_freshness = parse_empty(k, v)?, "skip-rustdoc-fingerprint" => self.skip_rustdoc_fingerprint = parse_empty(k, v)?, - "script" => self.script = parse_empty(k, v)?, "target-applies-to-host" => self.target_applies_to_host = parse_empty(k, v)?, "panic-immediate-abort" => self.panic_immediate_abort = parse_empty(k, v)?, "unstable-options" => self.unstable_options = parse_empty(k, v)?, diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index 58b98f1cbed..9a397cf49d8 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -1097,9 +1097,6 @@ pub fn root_manifest(manifest_path: Option<&Path>, gctx: &GlobalContext) -> Carg manifest_path.display() ) } - if crate::util::toml::is_embedded(&path) && !gctx.cli_unstable().script { - anyhow::bail!("embedded manifest `{}` requires `-Zscript`", path.display()) - } Ok(path) } else { find_root_manifest_for_wd(gctx.cwd()) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index c31faf1ae46..b933315a005 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -158,9 +158,6 @@ pub fn read_manifest( fn read_toml_string(path: &Path, is_embedded: bool, gctx: &GlobalContext) -> CargoResult { let mut contents = paths::read(path).map_err(|err| ManifestError::new(err, path.into()))?; if is_embedded { - if !gctx.cli_unstable().script { - anyhow::bail!("parsing `{}` requires `-Zscript`", path.display()); - } contents = embedded::expand_manifest(&contents) .map_err(|e| emit_frontmatter_diagnostic(e, &contents, path, gctx))?; } diff --git a/src/doc/man/cargo.md b/src/doc/man/cargo.md index 21bfe620aee..8015a24047e 100644 --- a/src/doc/man/cargo.md +++ b/src/doc/man/cargo.md @@ -7,6 +7,7 @@ cargo --- The Rust package manager ## SYNOPSIS `cargo` [_options_] _command_ [_args_]\ +`cargo` [_options_] _script_ [_args_]\ `cargo` [_options_] `--version`\ `cargo` [_options_] `--list`\ `cargo` [_options_] `--help`\ @@ -232,7 +233,11 @@ stable yet and may be subject to change. mkdir foo && cd foo cargo init . -6. Learn about a command's options and usage: +6. Run a script + + cargo task.rs --action + +7. Learn about a command's options and usage: cargo help clean diff --git a/src/doc/man/generated_txt/cargo-add.txt b/src/doc/man/generated_txt/cargo-add.txt index b65a80c7ad1..05096dcbc17 100644 --- a/src/doc/man/generated_txt/cargo-add.txt +++ b/src/doc/man/generated_txt/cargo-add.txt @@ -164,8 +164,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. -p spec, --package spec Add dependencies to only the specified package. diff --git a/src/doc/man/generated_txt/cargo-bench.txt b/src/doc/man/generated_txt/cargo-bench.txt index 089ed26453a..234033484d8 100644 --- a/src/doc/man/generated_txt/cargo-bench.txt +++ b/src/doc/man/generated_txt/cargo-bench.txt @@ -335,8 +335,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --ignore-rust-version Ignore rust-version specification in packages. diff --git a/src/doc/man/generated_txt/cargo-build.txt b/src/doc/man/generated_txt/cargo-build.txt index 027ddf2c585..5fbdd1e47ff 100644 --- a/src/doc/man/generated_txt/cargo-build.txt +++ b/src/doc/man/generated_txt/cargo-build.txt @@ -259,8 +259,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --ignore-rust-version Ignore rust-version specification in packages. diff --git a/src/doc/man/generated_txt/cargo-check.txt b/src/doc/man/generated_txt/cargo-check.txt index 31218f8b6a6..879761597bb 100644 --- a/src/doc/man/generated_txt/cargo-check.txt +++ b/src/doc/man/generated_txt/cargo-check.txt @@ -253,8 +253,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --ignore-rust-version Ignore rust-version specification in packages. diff --git a/src/doc/man/generated_txt/cargo-clean.txt b/src/doc/man/generated_txt/cargo-clean.txt index a25c8f2a8ef..67c0443ef02 100644 --- a/src/doc/man/generated_txt/cargo-clean.txt +++ b/src/doc/man/generated_txt/cargo-clean.txt @@ -104,8 +104,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --locked Asserts that the exact same dependencies and versions are used as diff --git a/src/doc/man/generated_txt/cargo-doc.txt b/src/doc/man/generated_txt/cargo-doc.txt index 57d0cb89a08..5aacf7c58ca 100644 --- a/src/doc/man/generated_txt/cargo-doc.txt +++ b/src/doc/man/generated_txt/cargo-doc.txt @@ -228,8 +228,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --ignore-rust-version Ignore rust-version specification in packages. diff --git a/src/doc/man/generated_txt/cargo-fetch.txt b/src/doc/man/generated_txt/cargo-fetch.txt index 0ab31bfef45..9c614f98531 100644 --- a/src/doc/man/generated_txt/cargo-fetch.txt +++ b/src/doc/man/generated_txt/cargo-fetch.txt @@ -81,8 +81,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --locked Asserts that the exact same dependencies and versions are used as diff --git a/src/doc/man/generated_txt/cargo-fix.txt b/src/doc/man/generated_txt/cargo-fix.txt index 11c3b361e5c..2eaca73a78b 100644 --- a/src/doc/man/generated_txt/cargo-fix.txt +++ b/src/doc/man/generated_txt/cargo-fix.txt @@ -327,8 +327,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --ignore-rust-version Ignore rust-version specification in packages. diff --git a/src/doc/man/generated_txt/cargo-generate-lockfile.txt b/src/doc/man/generated_txt/cargo-generate-lockfile.txt index 61a5c182fc2..26ea8c669d8 100644 --- a/src/doc/man/generated_txt/cargo-generate-lockfile.txt +++ b/src/doc/man/generated_txt/cargo-generate-lockfile.txt @@ -43,8 +43,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --ignore-rust-version Ignore rust-version specification in packages. diff --git a/src/doc/man/generated_txt/cargo-locate-project.txt b/src/doc/man/generated_txt/cargo-locate-project.txt index 68a563bfbec..486923d1b54 100644 --- a/src/doc/man/generated_txt/cargo-locate-project.txt +++ b/src/doc/man/generated_txt/cargo-locate-project.txt @@ -60,8 +60,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. Common Options +toolchain diff --git a/src/doc/man/generated_txt/cargo-metadata.txt b/src/doc/man/generated_txt/cargo-metadata.txt index 82eb6e2aaef..5e7d3479f52 100644 --- a/src/doc/man/generated_txt/cargo-metadata.txt +++ b/src/doc/man/generated_txt/cargo-metadata.txt @@ -412,8 +412,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --locked Asserts that the exact same dependencies and versions are used as diff --git a/src/doc/man/generated_txt/cargo-package.txt b/src/doc/man/generated_txt/cargo-package.txt index e0a636a7c62..6a9a3f7e1a6 100644 --- a/src/doc/man/generated_txt/cargo-package.txt +++ b/src/doc/man/generated_txt/cargo-package.txt @@ -246,8 +246,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --locked Asserts that the exact same dependencies and versions are used as diff --git a/src/doc/man/generated_txt/cargo-pkgid.txt b/src/doc/man/generated_txt/cargo-pkgid.txt index 3123dcad20b..f71d2e908ec 100644 --- a/src/doc/man/generated_txt/cargo-pkgid.txt +++ b/src/doc/man/generated_txt/cargo-pkgid.txt @@ -81,8 +81,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --locked Asserts that the exact same dependencies and versions are used as diff --git a/src/doc/man/generated_txt/cargo-publish.txt b/src/doc/man/generated_txt/cargo-publish.txt index 328f0d3cc61..db602720dfb 100644 --- a/src/doc/man/generated_txt/cargo-publish.txt +++ b/src/doc/man/generated_txt/cargo-publish.txt @@ -159,8 +159,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --locked Asserts that the exact same dependencies and versions are used as diff --git a/src/doc/man/generated_txt/cargo-remove.txt b/src/doc/man/generated_txt/cargo-remove.txt index 9d8c14afcc9..d6e9de6fa0e 100644 --- a/src/doc/man/generated_txt/cargo-remove.txt +++ b/src/doc/man/generated_txt/cargo-remove.txt @@ -58,8 +58,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --locked Asserts that the exact same dependencies and versions are used as diff --git a/src/doc/man/generated_txt/cargo-run.txt b/src/doc/man/generated_txt/cargo-run.txt index e7d0708eb6d..aeaaf0e04ff 100644 --- a/src/doc/man/generated_txt/cargo-run.txt +++ b/src/doc/man/generated_txt/cargo-run.txt @@ -173,8 +173,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --ignore-rust-version Ignore rust-version specification in packages. diff --git a/src/doc/man/generated_txt/cargo-rustc.txt b/src/doc/man/generated_txt/cargo-rustc.txt index a01cc112b93..d0cfaaeaa10 100644 --- a/src/doc/man/generated_txt/cargo-rustc.txt +++ b/src/doc/man/generated_txt/cargo-rustc.txt @@ -271,8 +271,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --ignore-rust-version Ignore rust-version specification in packages. diff --git a/src/doc/man/generated_txt/cargo-rustdoc.txt b/src/doc/man/generated_txt/cargo-rustdoc.txt index ab78e282046..4f3d68f78cf 100644 --- a/src/doc/man/generated_txt/cargo-rustdoc.txt +++ b/src/doc/man/generated_txt/cargo-rustdoc.txt @@ -240,8 +240,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --ignore-rust-version Ignore rust-version specification in packages. diff --git a/src/doc/man/generated_txt/cargo-test.txt b/src/doc/man/generated_txt/cargo-test.txt index 00449b09541..a94ea02257f 100644 --- a/src/doc/man/generated_txt/cargo-test.txt +++ b/src/doc/man/generated_txt/cargo-test.txt @@ -361,8 +361,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --ignore-rust-version Ignore rust-version specification in packages. diff --git a/src/doc/man/generated_txt/cargo-tree.txt b/src/doc/man/generated_txt/cargo-tree.txt index 8ac8207797a..62de82248f6 100644 --- a/src/doc/man/generated_txt/cargo-tree.txt +++ b/src/doc/man/generated_txt/cargo-tree.txt @@ -211,8 +211,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --locked Asserts that the exact same dependencies and versions are used as diff --git a/src/doc/man/generated_txt/cargo-update.txt b/src/doc/man/generated_txt/cargo-update.txt index 1e3500481ad..43c0d98a015 100644 --- a/src/doc/man/generated_txt/cargo-update.txt +++ b/src/doc/man/generated_txt/cargo-update.txt @@ -102,8 +102,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --ignore-rust-version Ignore rust-version specification in packages. diff --git a/src/doc/man/generated_txt/cargo-vendor.txt b/src/doc/man/generated_txt/cargo-vendor.txt index 771e75326d6..0fed5556c03 100644 --- a/src/doc/man/generated_txt/cargo-vendor.txt +++ b/src/doc/man/generated_txt/cargo-vendor.txt @@ -50,8 +50,9 @@ OPTIONS Manifest Options --manifest-path path - Path to the Cargo.toml file. By default, Cargo searches for the - Cargo.toml file in the current directory or any parent directory. + Path to the Cargo.toml or cargo script file. By default, Cargo + searches for the Cargo.toml file in the current directory or any + parent directory. --locked Asserts that the exact same dependencies and versions are used as diff --git a/src/doc/man/generated_txt/cargo.txt b/src/doc/man/generated_txt/cargo.txt index b2e359fa5f1..af6822985f1 100644 --- a/src/doc/man/generated_txt/cargo.txt +++ b/src/doc/man/generated_txt/cargo.txt @@ -5,6 +5,7 @@ NAME SYNOPSIS cargo [options] command [args] + cargo [options] script [args] cargo [options] --version cargo [options] --list cargo [options] --help @@ -299,7 +300,11 @@ EXAMPLES mkdir foo && cd foo cargo init . - 6. Learn about a command’s options and usage: + 6. Run a script + + cargo task.rs --action + + 7. Learn about a command’s options and usage: cargo help clean diff --git a/src/doc/man/includes/options-manifest-path.md b/src/doc/man/includes/options-manifest-path.md index b1d6eab76ee..6038a28e268 100644 --- a/src/doc/man/includes/options-manifest-path.md +++ b/src/doc/man/includes/options-manifest-path.md @@ -1,4 +1,4 @@ {{#option "`--manifest-path` _path_" }} -Path to the `Cargo.toml` file. By default, Cargo searches for the +Path to the `Cargo.toml` or cargo script file. By default, Cargo searches for the `Cargo.toml` file in the current directory or any parent directory. {{/option}} diff --git a/src/doc/src/commands/cargo-add.md b/src/doc/src/commands/cargo-add.md index 1a22d87efdf..0937b7d6b47 100644 --- a/src/doc/src/commands/cargo-add.md +++ b/src/doc/src/commands/cargo-add.md @@ -201,7 +201,7 @@ terminal.
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-bench.md b/src/doc/src/commands/cargo-bench.md index 3e871f27105..509cf9c6b97 100644 --- a/src/doc/src/commands/cargo-bench.md +++ b/src/doc/src/commands/cargo-bench.md @@ -393,7 +393,7 @@ coming from rustc are still emitted. Cannot be used with human or <
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-build.md b/src/doc/src/commands/cargo-build.md index ffebb33a11e..edbc5fa5518 100644 --- a/src/doc/src/commands/cargo-build.md +++ b/src/doc/src/commands/cargo-build.md @@ -316,7 +316,7 @@ coming from rustc are still emitted. Cannot be used with human or <
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-check.md b/src/doc/src/commands/cargo-check.md index b513c6209c1..f77ffee7ef2 100644 --- a/src/doc/src/commands/cargo-check.md +++ b/src/doc/src/commands/cargo-check.md @@ -304,7 +304,7 @@ coming from rustc are still emitted. Cannot be used with human or <
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-clean.md b/src/doc/src/commands/cargo-clean.md index 22da161097d..6acc1bba0ef 100644 --- a/src/doc/src/commands/cargo-clean.md +++ b/src/doc/src/commands/cargo-clean.md @@ -127,7 +127,7 @@ terminal.
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-doc.md b/src/doc/src/commands/cargo-doc.md index 88b509ddfb3..93bf7cb82e8 100644 --- a/src/doc/src/commands/cargo-doc.md +++ b/src/doc/src/commands/cargo-doc.md @@ -279,7 +279,7 @@ coming from rustc are still emitted. Cannot be used with human or <
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-fetch.md b/src/doc/src/commands/cargo-fetch.md index 279558343b0..d8e7357c7fa 100644 --- a/src/doc/src/commands/cargo-fetch.md +++ b/src/doc/src/commands/cargo-fetch.md @@ -83,7 +83,7 @@ terminal.
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-fix.md b/src/doc/src/commands/cargo-fix.md index b0dc3395307..5d80ec6ff8e 100644 --- a/src/doc/src/commands/cargo-fix.md +++ b/src/doc/src/commands/cargo-fix.md @@ -390,7 +390,7 @@ coming from rustc are still emitted. Cannot be used with human or <
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-generate-lockfile.md b/src/doc/src/commands/cargo-generate-lockfile.md index 758278142bc..b38edf4fb82 100644 --- a/src/doc/src/commands/cargo-generate-lockfile.md +++ b/src/doc/src/commands/cargo-generate-lockfile.md @@ -57,7 +57,7 @@ terminal.
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-locate-project.md b/src/doc/src/commands/cargo-locate-project.md index d0f24148089..66087f6a332 100644 --- a/src/doc/src/commands/cargo-locate-project.md +++ b/src/doc/src/commands/cargo-locate-project.md @@ -79,7 +79,7 @@ terminal.
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-metadata.md b/src/doc/src/commands/cargo-metadata.md index bb1c4da0b4c..4c89f2aa9db 100644 --- a/src/doc/src/commands/cargo-metadata.md +++ b/src/doc/src/commands/cargo-metadata.md @@ -443,7 +443,7 @@ terminal.
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-package.md b/src/doc/src/commands/cargo-package.md index d13ac23adca..e133e06a87d 100644 --- a/src/doc/src/commands/cargo-package.md +++ b/src/doc/src/commands/cargo-package.md @@ -274,7 +274,7 @@ be specified multiple times, which enables all specified features.

--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-pkgid.md b/src/doc/src/commands/cargo-pkgid.md index c697496af42..0ac34f534f2 100644 --- a/src/doc/src/commands/cargo-pkgid.md +++ b/src/doc/src/commands/cargo-pkgid.md @@ -90,7 +90,7 @@ terminal.
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-publish.md b/src/doc/src/commands/cargo-publish.md index 2a7754a49ba..a5625ee6605 100644 --- a/src/doc/src/commands/cargo-publish.md +++ b/src/doc/src/commands/cargo-publish.md @@ -182,7 +182,7 @@ be specified multiple times, which enables all specified features.

--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-remove.md b/src/doc/src/commands/cargo-remove.md index 4eca891b7a2..e8762bfa9a5 100644 --- a/src/doc/src/commands/cargo-remove.md +++ b/src/doc/src/commands/cargo-remove.md @@ -84,7 +84,7 @@ terminal.
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-run.md b/src/doc/src/commands/cargo-run.md index c09f293565d..063f632102e 100644 --- a/src/doc/src/commands/cargo-run.md +++ b/src/doc/src/commands/cargo-run.md @@ -213,7 +213,7 @@ coming from rustc are still emitted. Cannot be used with human or <
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-rustc.md b/src/doc/src/commands/cargo-rustc.md index 364c05fcb64..3e32e86b0e5 100644 --- a/src/doc/src/commands/cargo-rustc.md +++ b/src/doc/src/commands/cargo-rustc.md @@ -317,7 +317,7 @@ coming from rustc are still emitted. Cannot be used with human or <
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-rustdoc.md b/src/doc/src/commands/cargo-rustdoc.md index 4e73cd5f937..faac1de877c 100644 --- a/src/doc/src/commands/cargo-rustdoc.md +++ b/src/doc/src/commands/cargo-rustdoc.md @@ -297,7 +297,7 @@ coming from rustc are still emitted. Cannot be used with human or <
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-test.md b/src/doc/src/commands/cargo-test.md index 2b2246ada40..451bac49f68 100644 --- a/src/doc/src/commands/cargo-test.md +++ b/src/doc/src/commands/cargo-test.md @@ -424,7 +424,7 @@ coming from rustc are still emitted. Cannot be used with human or <
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-tree.md b/src/doc/src/commands/cargo-tree.md index a656bc3cd1f..13b4fc750ac 100644 --- a/src/doc/src/commands/cargo-tree.md +++ b/src/doc/src/commands/cargo-tree.md @@ -233,7 +233,7 @@ single quotes or double quotes around each pattern.

--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-update.md b/src/doc/src/commands/cargo-update.md index a70c7874e0c..a6e10213866 100644 --- a/src/doc/src/commands/cargo-update.md +++ b/src/doc/src/commands/cargo-update.md @@ -122,7 +122,7 @@ terminal.
--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo-vendor.md b/src/doc/src/commands/cargo-vendor.md index d17aa2167d2..aaba0bc724e 100644 --- a/src/doc/src/commands/cargo-vendor.md +++ b/src/doc/src/commands/cargo-vendor.md @@ -68,7 +68,7 @@ only a subset of the packages have changed.

--manifest-path path
-

Path to the Cargo.toml file. By default, Cargo searches for the +

Path to the Cargo.toml or cargo script file. By default, Cargo searches for the Cargo.toml file in the current directory or any parent directory.

diff --git a/src/doc/src/commands/cargo.md b/src/doc/src/commands/cargo.md index 03676e24927..56481e2cf19 100644 --- a/src/doc/src/commands/cargo.md +++ b/src/doc/src/commands/cargo.md @@ -7,6 +7,7 @@ cargo --- The Rust package manager ## SYNOPSIS `cargo` [_options_] _command_ [_args_]\ +`cargo` [_options_] _script_ [_args_]\ `cargo` [_options_] `--version`\ `cargo` [_options_] `--list`\ `cargo` [_options_] `--help`\ @@ -343,7 +344,11 @@ stable yet and may be subject to change. mkdir foo && cd foo cargo init . -6. Learn about a command's options and usage: +6. Run a script + + cargo task.rs --action + +7. Learn about a command's options and usage: cargo help clean diff --git a/src/doc/src/reference/cargo-targets.md b/src/doc/src/reference/cargo-targets.md index 47021a1ce3b..7c905476c5e 100644 --- a/src/doc/src/reference/cargo-targets.md +++ b/src/doc/src/reference/cargo-targets.md @@ -363,6 +363,9 @@ autobins = false > is `false` if at least one target is manually defined in `Cargo.toml`. > Beginning with the 2018 edition, the default is always `true`. +> **Note:** Scripts are self-contained and do not support additional targets +> nor controlling target discovery. + > **MSRV:** Respected as of 1.27 for `autobins`, `autoexamples`, `autotests`, and `autobenches` > **MSRV:** Respected as of 1.83 for `autolib` diff --git a/src/doc/src/reference/manifest.md b/src/doc/src/reference/manifest.md index 5f1074f8ea5..4fa38d1e88c 100644 --- a/src/doc/src/reference/manifest.md +++ b/src/doc/src/reference/manifest.md @@ -4,6 +4,22 @@ The `Cargo.toml` file for each package is called its *manifest*. It is written in the [TOML] format. It contains metadata that is needed to compile the package. Checkout the `cargo locate-project` section for more detail on how cargo finds the manifest file. +The content of the manifest can also be embedded inside of the frontmatter inside of a Rust source file: +```rust +#!/usr/bin/env cargo +--- +[package] +edition = "2024" + +[dependencies] +regex = "1" +--- + +fn main() { + // ... +} +``` + Every manifest file consists of the following sections: * [`cargo-features`](unstable.md) --- Unstable, nightly-only features. @@ -66,10 +82,11 @@ name = "hello_world" # the name of the package version = "0.1.0" # the current version, obeying semver ``` -The only field required by Cargo is [`name`](#the-name-field). If publishing to -a registry, the registry may require additional fields. See the notes below and -[the publishing chapter][publishing] for requirements for publishing to -[crates.io]. +The only field required by Cargo for `Cargo.toml` files is [`name`](#the-name-field). +There are no required fields for cargo scripts. +If publishing to a registry, the registry may require additional fields. See +the notes below and [the publishing chapter][publishing] for requirements for +publishing to [crates.io]. ### The `name` field @@ -88,6 +105,9 @@ a keyword. [crates.io] imposes even more restrictions, such as: - Do not use special Windows names such as "nul". - Use a maximum of 64 characters of length. +This field is optional for scripts and defaults to the file stem. +The field is required for `Cargo.toml` manifests. + [alphanumeric]: ../../std/primitive.char.html#method.is_alphanumeric ### The `version` field @@ -154,7 +174,9 @@ with the latest stable edition. By default `cargo new` creates a manifest with the 2024 edition currently. If the `edition` field is not present in `Cargo.toml`, then the 2015 edition is -assumed for backwards compatibility. Note that all manifests +assumed for backwards compatibility. +In scripts, the current edition is assumed. +Note that all manifests created with [`cargo new`] will not use this historical fallback because they will have `edition` explicitly specified to a newer value. @@ -328,6 +350,8 @@ table defined. That is, a crate cannot both be a root crate in a workspace For more information, see the [workspaces chapter](workspaces.md). +This field is disallowed in scripts. + ### The `build` field The `build` field specifies a file in the package root which is a [build @@ -347,6 +371,8 @@ The default is `"build.rs"`, which loads the script from a file named specify a path to a different file or `build = false` to disable automatic detection of the build script. +This field is disallowed in scripts. + ### The `links` field The `links` field specifies the name of a native library that is being linked @@ -364,6 +390,8 @@ on Linux) may specify: links = "git2" ``` +This field is disallowed in scripts. + ### The `exclude` and `include` fields The `exclude` and `include` fields can be used to explicitly specify which @@ -519,6 +547,8 @@ both `src/bin/a.rs` and `src/bin/b.rs`: default-run = "a" ``` +This field is disallowed in scripts. + ## The `[lints]` section Override the default level of lints from different tools by assigning them to a new level in a diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index 6ca6f108044..0976cf46b7a 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -129,7 +129,6 @@ Each new feature described below should explain how to use it. * [asymmetric-token](#asymmetric-token) --- Adds support for authentication tokens using asymmetric cryptography (`cargo:paseto` provider). * Other * [gitoxide](#gitoxide) --- Use `gitoxide` instead of `git2` for a set of operations. - * [script](#script) --- Enable support for single-file `.rs` packages. * [lockfile-path](#lockfile-path) --- Allows to specify a path to lockfile other than the default path `/Cargo.lock`. * [native-completions](#native-completions) --- Move cargo shell completions to native completions. * [warnings](#warnings) --- controls warning behavior; options for allowing or denying warnings. @@ -1380,99 +1379,6 @@ Valid operations are the following: * When the unstable feature is on, fetching/cloning a git repository is always a shallow fetch. This roughly equals to `git fetch --depth 1` everywhere. * Even with the presence of `Cargo.lock` or specifying a commit `{ rev = "…" }`, gitoxide and libgit2 are still smart enough to shallow fetch without unshallowing the existing repository. -## script - -* Tracking Issue: [#12207](https://github.com/rust-lang/cargo/issues/12207) - -Cargo can directly run `.rs` files as: -```console -$ cargo +nightly -Zscript file.rs -``` -where `file.rs` can be as simple as: -```rust -fn main() {} -``` - -A user may optionally specify a manifest in a `cargo` code fence in a module-level comment, like: -````rust -#!/usr/bin/env -S cargo +nightly -Zscript ----cargo -[dependencies] -clap = { version = "4.2", features = ["derive"] } ---- - -use clap::Parser; - -#[derive(Parser, Debug)] -#[clap(version)] -struct Args { - #[clap(short, long, help = "Path to config")] - config: Option, -} - -fn main() { - let args = Args::parse(); - println!("{:?}", args); -} -```` - -### Single-file packages - -In addition to today's multi-file packages (`Cargo.toml` file with other `.rs` -files), we are adding the concept of single-file packages which may contain an -embedded manifest. There is no required distinguishment for a single-file -`.rs` package from any other `.rs` file. - -Single-file packages may be selected via `--manifest-path`, like -`cargo test --manifest-path foo.rs`. Unlike `Cargo.toml`, these files cannot be auto-discovered. - -A single-file package may contain an embedded manifest. An embedded manifest -is stored using `TOML` in rust "frontmatter", a markdown code-fence with `cargo` -at the start of the infostring at the top of the file. - -Inferred / defaulted manifest fields: -- `package.name = ` -- `package.edition = ` to avoid always having to add an embedded - manifest at the cost of potentially breaking scripts on rust upgrades - - Warn when `edition` is unspecified to raise awareness of this - -Disallowed manifest fields: -- `[workspace]`, `[lib]`, `[[bin]]`, `[[example]]`, `[[test]]`, `[[bench]]` -- `package.workspace`, `package.build`, `package.links`, `package.autolib`, `package.autobins`, `package.autoexamples`, `package.autotests`, `package.autobenches` - -The default `CARGO_TARGET_DIR` for single-file packages is at `$CARGO_HOME/target/`: -- Avoid conflicts from multiple single-file packages being in the same directory -- Avoid problems with the single-file package's parent directory being read-only -- Avoid cluttering the user's directory - -The lockfile for single-file packages will be placed in `CARGO_TARGET_DIR`. In -the future, when workspaces are supported, that will allow a user to have a -persistent lockfile. - -### Manifest-commands - -You may pass a manifest directly to the `cargo` command, without a subcommand, -like `foo/Cargo.toml` or a single-file package like `foo.rs`. This is mostly -intended for being put in `#!` lines. - -The precedence for how to interpret `cargo ` is -1. Built-in xor single-file packages -2. Aliases -3. External subcommands - -A parameter is identified as a manifest-command if it has one of: -- Path separators -- A `.rs` extension -- The file name is `Cargo.toml` - -Differences between `cargo run --manifest-path ` and `cargo ` -- `cargo ` runs with the config for `` and not the current dir, more like `cargo install --path ` -- `cargo ` is at a verbosity level below the normal default. Pass `-v` to get normal output. - -When running a package with an embedded manifest, -[`arg0`](https://doc.rust-lang.org/std/os/unix/process/trait.CommandExt.html#tymethod.arg0) will be the scripts path. -To get the executable's path, see [`current_exe`](https://doc.rust-lang.org/std/env/fn.current_exe.html). - ### Documentation Updates ## Profile `trim-paths` option @@ -2343,3 +2249,7 @@ See the [`include` config documentation](config.md#include) for more. ## pubtime The `pubtime` index field has been stabilized in Rust 1.94.0. + +## Cargo script + +Support for `-Zscript` has been stabilized in 1.95.0. diff --git a/src/etc/man/cargo-add.1 b/src/etc/man/cargo-add.1 index 84a3d528dfd..536373a27e4 100644 --- a/src/etc/man/cargo-add.1 +++ b/src/etc/man/cargo-add.1 @@ -208,7 +208,7 @@ May also be specified with the \fBterm.color\fR .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-bench.1 b/src/etc/man/cargo-bench.1 index 998c747ceca..f2967053aef 100644 --- a/src/etc/man/cargo-bench.1 +++ b/src/etc/man/cargo-bench.1 @@ -410,7 +410,7 @@ coming from rustc are still emitted. Cannot be used with \fBhuman\fR or \fBshort .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-build.1 b/src/etc/man/cargo-build.1 index c90c2200ead..5120c2d936b 100644 --- a/src/etc/man/cargo-build.1 +++ b/src/etc/man/cargo-build.1 @@ -317,7 +317,7 @@ coming from rustc are still emitted. Cannot be used with \fBhuman\fR or \fBshort .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-check.1 b/src/etc/man/cargo-check.1 index e5c1d2f090c..b334c7efc20 100644 --- a/src/etc/man/cargo-check.1 +++ b/src/etc/man/cargo-check.1 @@ -308,7 +308,7 @@ coming from rustc are still emitted. Cannot be used with \fBhuman\fR or \fBshort .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-clean.1 b/src/etc/man/cargo-clean.1 index bbdebd3c8af..8a525249141 100644 --- a/src/etc/man/cargo-clean.1 +++ b/src/etc/man/cargo-clean.1 @@ -128,7 +128,7 @@ May also be specified with the \fBterm.color\fR .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-doc.1 b/src/etc/man/cargo-doc.1 index 891fe20f890..e9043a9f1d1 100644 --- a/src/etc/man/cargo-doc.1 +++ b/src/etc/man/cargo-doc.1 @@ -277,7 +277,7 @@ coming from rustc are still emitted. Cannot be used with \fBhuman\fR or \fBshort .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-fetch.1 b/src/etc/man/cargo-fetch.1 index 41fa1d60b1e..fb6bd424362 100644 --- a/src/etc/man/cargo-fetch.1 +++ b/src/etc/man/cargo-fetch.1 @@ -91,7 +91,7 @@ May also be specified with the \fBterm.color\fR .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-fix.1 b/src/etc/man/cargo-fix.1 index fd73fa0f5cb..812709cd1d4 100644 --- a/src/etc/man/cargo-fix.1 +++ b/src/etc/man/cargo-fix.1 @@ -403,7 +403,7 @@ coming from rustc are still emitted. Cannot be used with \fBhuman\fR or \fBshort .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-generate-lockfile.1 b/src/etc/man/cargo-generate-lockfile.1 index 04d609a8e0a..45809e6309a 100644 --- a/src/etc/man/cargo-generate-lockfile.1 +++ b/src/etc/man/cargo-generate-lockfile.1 @@ -58,7 +58,7 @@ May also be specified with the \fBterm.color\fR .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-locate-project.1 b/src/etc/man/cargo-locate-project.1 index 83f7876a480..9225c3cc16a 100644 --- a/src/etc/man/cargo-locate-project.1 +++ b/src/etc/man/cargo-locate-project.1 @@ -79,7 +79,7 @@ May also be specified with the \fBterm.color\fR .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .SS "Common Options" diff --git a/src/etc/man/cargo-metadata.1 b/src/etc/man/cargo-metadata.1 index ad6dee4ebb5..fce6b8987bb 100644 --- a/src/etc/man/cargo-metadata.1 +++ b/src/etc/man/cargo-metadata.1 @@ -442,7 +442,7 @@ May also be specified with the \fBterm.color\fR .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-package.1 b/src/etc/man/cargo-package.1 index 0e162bbfd12..ad8fa68605a 100644 --- a/src/etc/man/cargo-package.1 +++ b/src/etc/man/cargo-package.1 @@ -299,7 +299,7 @@ Do not activate the \fBdefault\fR feature of the selected packages. .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-pkgid.1 b/src/etc/man/cargo-pkgid.1 index 94c4fd1ea42..45b8ec4bc45 100644 --- a/src/etc/man/cargo-pkgid.1 +++ b/src/etc/man/cargo-pkgid.1 @@ -117,7 +117,7 @@ May also be specified with the \fBterm.color\fR .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-publish.1 b/src/etc/man/cargo-publish.1 index a41c729ff1f..aa5d3136088 100644 --- a/src/etc/man/cargo-publish.1 +++ b/src/etc/man/cargo-publish.1 @@ -180,7 +180,7 @@ Do not activate the \fBdefault\fR feature of the selected packages. .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-remove.1 b/src/etc/man/cargo-remove.1 index 15d964f9981..d213c8d77fc 100644 --- a/src/etc/man/cargo-remove.1 +++ b/src/etc/man/cargo-remove.1 @@ -77,7 +77,7 @@ May also be specified with the \fBterm.color\fR .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-run.1 b/src/etc/man/cargo-run.1 index 2e95cf4f7f3..75787c64bf9 100644 --- a/src/etc/man/cargo-run.1 +++ b/src/etc/man/cargo-run.1 @@ -212,7 +212,7 @@ coming from rustc are still emitted. Cannot be used with \fBhuman\fR or \fBshort .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-rustc.1 b/src/etc/man/cargo-rustc.1 index 971c9218716..0c35dfd69f4 100644 --- a/src/etc/man/cargo-rustc.1 +++ b/src/etc/man/cargo-rustc.1 @@ -327,7 +327,7 @@ coming from rustc are still emitted. Cannot be used with \fBhuman\fR or \fBshort .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-rustdoc.1 b/src/etc/man/cargo-rustdoc.1 index c624de72c2f..c4eedd84038 100644 --- a/src/etc/man/cargo-rustdoc.1 +++ b/src/etc/man/cargo-rustdoc.1 @@ -294,7 +294,7 @@ coming from rustc are still emitted. Cannot be used with \fBhuman\fR or \fBshort .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-test.1 b/src/etc/man/cargo-test.1 index 57175befad3..ce8cd8aa636 100644 --- a/src/etc/man/cargo-test.1 +++ b/src/etc/man/cargo-test.1 @@ -437,7 +437,7 @@ coming from rustc are still emitted. Cannot be used with \fBhuman\fR or \fBshort .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-tree.1 b/src/etc/man/cargo-tree.1 index 8dbda8778d2..a6a496fab57 100644 --- a/src/etc/man/cargo-tree.1 +++ b/src/etc/man/cargo-tree.1 @@ -265,7 +265,7 @@ single quotes or double quotes around each pattern. .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-update.1 b/src/etc/man/cargo-update.1 index 3b6a86d91d7..d4d67525ddd 100644 --- a/src/etc/man/cargo-update.1 +++ b/src/etc/man/cargo-update.1 @@ -134,7 +134,7 @@ May also be specified with the \fBterm.color\fR .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo-vendor.1 b/src/etc/man/cargo-vendor.1 index 0182f8eb37f..49ba9fdcfce 100644 --- a/src/etc/man/cargo-vendor.1 +++ b/src/etc/man/cargo-vendor.1 @@ -58,7 +58,7 @@ only a subset of the packages have changed. .sp \fB\-\-manifest\-path\fR \fIpath\fR .RS 4 -Path to the \fBCargo.toml\fR file. By default, Cargo searches for the +Path to the \fBCargo.toml\fR or cargo script file. By default, Cargo searches for the \fBCargo.toml\fR file in the current directory or any parent directory. .RE .sp diff --git a/src/etc/man/cargo.1 b/src/etc/man/cargo.1 index 80c8682a6ef..df149d2ca40 100644 --- a/src/etc/man/cargo.1 +++ b/src/etc/man/cargo.1 @@ -8,6 +8,8 @@ cargo \[em] The Rust package manager .SH "SYNOPSIS" \fBcargo\fR [\fIoptions\fR] \fIcommand\fR [\fIargs\fR] .br +\fBcargo\fR [\fIoptions\fR] \fIscript\fR [\fIargs\fR] +.br \fBcargo\fR [\fIoptions\fR] \fB\-\-version\fR .br \fBcargo\fR [\fIoptions\fR] \fB\-\-list\fR @@ -400,7 +402,17 @@ cargo init . .RE .sp .RS 4 -\h'-04' 6.\h'+01'Learn about a command\[cq]s options and usage: +\h'-04' 6.\h'+01'Run a script +.sp +.RS 4 +.nf +cargo task.rs \-\-action +.fi +.RE +.RE +.sp +.RS 4 +\h'-04' 7.\h'+01'Learn about a command\[cq]s options and usage: .sp .RS 4 .nf diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index eabe76ea77f..70b102449f8 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -349,7 +349,7 @@ fn cargo_compile_with_unsupported_short_unstable_feature_flag() { tip: a similar argument exists: '-Z' Usage: cargo [..][OPTIONS] [COMMAND] - cargo [..][OPTIONS] -Zscript [ARGS]... + cargo [..][OPTIONS] [ARGS]... For more information, try '--help'. diff --git a/tests/testsuite/cargo/help/stdout.term.svg b/tests/testsuite/cargo/help/stdout.term.svg index bf54694dbf9..c0a44aaf795 100644 --- a/tests/testsuite/cargo/help/stdout.term.svg +++ b/tests/testsuite/cargo/help/stdout.term.svg @@ -1,7 +1,7 @@