Skip to content

Adjust root package page content #13725

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

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 1 addition & 9 deletions src/bin/cargo/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Example uses:
- Depend on crates with the same name from different registries"),
flag(
"ignore-rust-version",
"Ignore `rust-version` specification in packages (unstable)"
"Ignore `rust-version` specification in packages"
),
])
.arg_manifest_path_without_unsupported_path_tip()
Expand Down Expand Up @@ -206,14 +206,6 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
let dependencies = parse_dependencies(gctx, args)?;

let ignore_rust_version = args.flag("ignore-rust-version");
if ignore_rust_version && !gctx.cli_unstable().msrv_policy {
return Err(CliError::new(
anyhow::format_err!(
"`--ignore-rust-version` is unstable; pass `-Zmsrv-policy` to enable support for it"
),
101,
));
}
let honor_rust_version = !ignore_rust_version;

let options = AddOptions {
Expand Down
3 changes: 3 additions & 0 deletions src/cargo/core/compiler/fingerprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,11 +1526,14 @@ See https://doc.rust-lang.org/cargo/reference/build-scripts.html#rerun-if-change
.collect::<CargoResult<Vec<_>>>()?
};

let rustflags = build_runner.bcx.rustflags_args(unit).to_vec();

Ok(Fingerprint {
local: Mutex::new(local),
rustc: util::hash_u64(&build_runner.bcx.rustc().verbose_version),
deps,
outputs: if overridden { Vec::new() } else { vec![output] },
rustflags,

// Most of the other info is blank here as we don't really include it
// in the execution of the build script, but... this may be a latent
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ fn get_latest_dependency(
)
})?;

if gctx.cli_unstable().msrv_policy && honor_rust_version {
if honor_rust_version {
let (req_msrv, is_msrv) = spec
.rust_version()
.cloned()
Expand Down
5 changes: 5 additions & 0 deletions src/cargo/sources/git/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,7 @@ fn github_fast_path(
// the branch has moved.
if let Some(local_object) = local_object {
if is_short_hash_of(rev, local_object) {
debug!("github fast path already has {local_object}");
return Ok(FastPathRev::UpToDate);
}
}
Expand Down Expand Up @@ -1452,6 +1453,7 @@ fn github_fast_path(
handle.get(true)?;
handle.url(&url)?;
handle.useragent("cargo")?;
handle.follow_location(true)?; // follow redirects
handle.http_headers({
let mut headers = List::new();
headers.append("Accept: application/vnd.github.3.sha")?;
Expand All @@ -1472,14 +1474,17 @@ fn github_fast_path(

let response_code = handle.response_code()?;
if response_code == 304 {
debug!("github fast path up-to-date");
Ok(FastPathRev::UpToDate)
} else if response_code == 200 {
let oid_to_fetch = str::from_utf8(&response_body)?.parse::<Oid>()?;
debug!("github fast path fetch {oid_to_fetch}");
Ok(FastPathRev::NeedsFetch(oid_to_fetch))
} else {
// Usually response_code == 404 if the repository does not exist, and
// response_code == 422 if exists but GitHub is unable to resolve the
// requested rev.
debug!("github fast path bad response code {response_code}");
Ok(FastPathRev::Indeterminate)
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/doc/man/cargo-add.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ which enables all specified features.

{{#option "`--ignore-rust-version`" }}
Ignore `rust-version` specification in packages.

This option is unstable and available only on the
[nightly channel](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html)
and requires the `-Z unstable-options` flag to enable.
See <https://github.com/rust-lang/cargo/issues/5579> for more information.
{{/option}}

{{/options}}
Expand Down
6 changes: 0 additions & 6 deletions src/doc/man/generated_txt/cargo-add.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ OPTIONS
--ignore-rust-version
Ignore rust-version specification in packages.

This option is unstable and available only on the nightly channel
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and
requires the -Z unstable-options flag to enable. See
<https://github.com/rust-lang/cargo/issues/5579> for more
information.

Display Options
-v, --verbose
Use verbose output. May be specified twice for “very verbose”
Expand Down
6 changes: 1 addition & 5 deletions src/doc/src/commands/cargo-add.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,7 @@ which enables all specified features.</dd>


<dt class="option-term" id="option-cargo-add---ignore-rust-version"><a class="option-anchor" href="#option-cargo-add---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
<dd class="option-desc">Ignore <code>rust-version</code> specification in packages.</p>
<p>This option is unstable and available only on the
<a href="https://doc.rust-lang.org/book/appendix-07-nightly-rust.html">nightly channel</a>
and requires the <code>-Z unstable-options</code> flag to enable.
See <a href="https://github.com/rust-lang/cargo/issues/5579">https://github.com/rust-lang/cargo/issues/5579</a> for more information.</dd>
<dd class="option-desc">Ignore <code>rust-version</code> specification in packages.</dd>


</dl>
Expand Down
2 changes: 0 additions & 2 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,6 @@ Documentation updates:

## msrv-policy
- [#9930](https://github.com/rust-lang/cargo/issues/9930) (MSRV-aware resolver)
- [#10653](https://github.com/rust-lang/cargo/issues/10653) (MSRV-aware cargo-add)
- [#10903](https://github.com/rust-lang/cargo/issues/10903) (MSRV-aware cargo-install)

The `msrv-policy` feature enables experiments in MSRV-aware policy for cargo in
preparation for an upcoming RFC.
Expand Down
6 changes: 6 additions & 0 deletions src/doc/src/reference/workspaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ version = "0.1.0" # the current version, obeying semver
authors = ["Alice <[email protected]>", "Bob <[email protected]>"]
```

Unless explicitly set through [`workspace.default-members`](#the-default-members-field),
the root package is considered as the only default member of the workspace.

### Virtual workspace

Alternatively, a `Cargo.toml` file can be created with a `[workspace]` section
Expand All @@ -80,6 +83,9 @@ edition = "2021" # the edition, will have no effect on a resolver used in th
authors = ["Alice <[email protected]>", "Bob <[email protected]>"]
```

Unless explicitly set through [`workspace.default-members`](#the-default-members-field),
every member of a virtual workspace is considered as a default member.

Note that in a virtual manifest the [`resolver = "2"`](resolver.md#resolver-versions)
should be specified manually. It is usually deduced from the [`package.edition`][package-edition]
field which is absent in virtual manifests and the edition field of a member
Expand Down
1 change: 1 addition & 0 deletions src/etc/_cargo
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ _cargo() {
'--path=[local filesystem path to crate to add]: :_directories' \
'--rev=[specific commit to use when adding from git]:commit' \
'--tag=[tag to use when adding from git]:tag' \
'--ignore-rust-version[Ignore rust-version specification in packages]' \
'1: :_guard "^-*" "crate name"' \
'*:args:_default'
;;
Expand Down
2 changes: 1 addition & 1 deletion src/etc/cargo.bashcomp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ _cargo()
local opt_targets="--lib --bin --bins --example --examples --test --tests --bench --benches --all-targets"

local opt___nocmd="$opt_common -V --version --list --explain"
local opt__add="$opt_common -p --package --features --default-features --no-default-features $opt_mani --optional --no-optional --rename --dry-run --path --git --branch --tag --rev --registry --dev --build --target"
local opt__add="$opt_common -p --package --features --default-features --no-default-features $opt_mani --optional --no-optional --rename --dry-run --path --git --branch --tag --rev --registry --dev --build --target --ignore-rust-version"
local opt__bench="$opt_common $opt_pkg_spec $opt_feat $opt_mani $opt_lock $opt_jobs $opt_targets --message-format --target --no-run --no-fail-fast --target-dir --ignore-rust-version"
local opt__build="$opt_common $opt_pkg_spec $opt_feat $opt_mani $opt_lock $opt_parallel $opt_targets --message-format --target --release --profile --target-dir --ignore-rust-version"
local opt__b="$opt__build"
Expand Down
5 changes: 0 additions & 5 deletions src/etc/man/cargo-add.1
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ which enables all specified features.
\fB\-\-ignore\-rust\-version\fR
.RS 4
Ignore \fBrust\-version\fR specification in packages.
.sp
This option is unstable and available only on the
\fInightly channel\fR <https://doc.rust\-lang.org/book/appendix\-07\-nightly\-rust.html>
and requires the \fB\-Z unstable\-options\fR flag to enable.
See <https://github.com/rust\-lang/cargo/issues/5579> for more information.
.RE
.SS "Display Options"
.sp
Expand Down
57 changes: 57 additions & 0 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5537,3 +5537,60 @@ fn test_old_syntax_with_old_msrv() {
p.cargo("build -v").run();
p.cargo("run -v").with_stdout("foo\n").run();
}

#[cargo_test]
fn build_script_rerun_when_target_rustflags_change() {
let target = rustc_host();
let p = project()
.file(
"src/main.rs",
r#"
fn main() {
#[cfg(enable)]
println!("hello");
}
"#,
)
.file(
"build.rs",
r#"
use std::env;

fn main() {
if let Ok(rustflags) = env::var("CARGO_ENCODED_RUSTFLAGS") {
if !rustflags.is_empty() {
println!("cargo::rustc-cfg=enable")
}
}
}
"#,
)
.build();

p.cargo("run --target")
.arg(&target)
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([..])
[FINISHED] [..]
[RUNNING] [..]
",
)
.run();

p.cargo("run --target")
.arg(&target)
.env("RUSTFLAGS", "-C opt-level=3")
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([..])
[FINISHED] [..]
[RUNNING] [..]
",
)
.with_stdout(
"\
hello",
)
.run();
}
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_add/help/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.