Support --filter-platform=host for cargo metadata #9423 (#16312)

This PR fixes this issue-:  #9423
This commit is contained in:
Weihang Lo
2025-11-29 20:59:42 +00:00
committed by GitHub
5 changed files with 26 additions and 16 deletions

View File

@@ -362,6 +362,7 @@ possible value.
{{#option "`--filter-platform` _triple_" }}
This filters the `resolve` output to only include dependencies for the
given [target triple](../appendix/glossary.html#target).
A literal `"host-tuple"` can be used, which will internally be substituted by the host's target.
Without this flag, the resolve includes all targets.
Note that the dependencies listed in the "packages" array still includes all

View File

@@ -354,8 +354,10 @@ OPTIONS
--filter-platform triple
This filters the resolve output to only include dependencies for the
given target triple
<https://doc.rust-lang.org/cargo/appendix/glossary.html#target>.
Without this flag, the resolve includes all targets.
<https://doc.rust-lang.org/cargo/appendix/glossary.html#target>. A
literal "host-tuple" can be used, which will internally be
substituted by the hosts target. Without this flag, the resolve
includes all targets.
Note that the dependencies listed in the “packages” array still
includes all dependencies. Each package definition is intended to be

View File

@@ -364,6 +364,7 @@ possible value.</p>
<dt class="option-term" id="option-cargo-metadata---filter-platform"><a class="option-anchor" href="#option-cargo-metadata---filter-platform"><code>--filter-platform</code> <em>triple</em></a></dt>
<dd class="option-desc"><p>This filters the <code>resolve</code> output to only include dependencies for the
given <a href="../appendix/glossary.html#target">target triple</a>.
A literal <code>"host-tuple"</code> can be used, which will internally be substituted by the hosts target.
Without this flag, the resolve includes all targets.</p>
<p>Note that the dependencies listed in the “packages” array still includes all
dependencies. Each package definition is intended to be an unaltered

View File

@@ -367,6 +367,7 @@ possible value.
.RS 4
This filters the \fBresolve\fR output to only include dependencies for the
given \fItarget triple\fR <https://doc.rust\-lang.org/cargo/appendix/glossary.html#target>\&.
A literal \fB"host\-tuple"\fR can be used, which will internally be substituted by the host\[cq]s target.
Without this flag, the resolve includes all targets.
.sp
Note that the dependencies listed in the \[lq]packages\[rq] array still includes all

View File

@@ -3842,21 +3842,15 @@ fn filter_platform() {
.run();
clear();
// Filter on host, removes alt and cfg.
p.cargo("metadata --filter-platform")
.arg(&host_target)
.with_stderr_data(
str![[r#"
let host_filtered_stderr = str![[r#"
[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems
[DOWNLOADING] crates ...
[DOWNLOADED] normal-dep v0.0.1 (registry `dummy-registry`)
[DOWNLOADED] host-dep v0.0.1 (registry `dummy-registry`)
"#]]
.unordered(),
)
.with_stdout_data(
str![[r#"
"#]];
let host_filtered_stdout = str![[r#"
{
"packages": [
{
@@ -3945,10 +3939,21 @@ fn filter_platform() {
},
"...": "{...}"
}
"#]]
.is_json()
.unordered(),
)
"#]];
// Filter on host, removes alt and cfg.
p.cargo("metadata --filter-platform")
.arg(&host_target)
.with_stderr_data(host_filtered_stderr.clone().unordered())
.with_stdout_data(host_filtered_stdout.clone().is_json().unordered())
.run();
clear();
// Filter on host-tuple, should produce same result as explicit host target.
p.cargo("metadata --filter-platform")
.arg("host-tuple")
.with_stderr_data(host_filtered_stderr.unordered())
.with_stdout_data(host_filtered_stdout.is_json().unordered())
.run();
clear();