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

perf(toml): Avoid inferring when targets are known #13849

Merged
merged 2 commits into from
May 2, 2024

Conversation

epage
Copy link
Contributor

@epage epage commented May 2, 2024

What does this PR try to resolve?

We read the file system to infer two different data points

  • Implicit targets
  • Implicit path values for targets

I took a shortcut for this case and recognize the scenario where we can
bypass both and do so.
I went with a bypass, rather than this being integrating into the
inferring code because the inferring code is complex and I didn't want
to add to it further in isolating the inferring to only when its needed.

The validation gets duplicated because having it in the middle of the resolve code provides a better user experience and it would be messy to add the conditionals to get all of that working. I at least worked to keep the duplicated validation close to each other.

How should we test and review this PR?

Additional information

epage added 2 commits May 1, 2024 19:42
We read the file system to infer two different data points
- Implicit targets
- Implicit `path` values for targets

I took a shortcut for this case and recognize the scenario where we can
bypass both and do so.
I went with a bypass, rather than this being integrating into the
inferring code because the inferring code is complex and I didn't want
to add to it further in isolating the inferring to only when its needed.
@rustbot
Copy link
Collaborator

rustbot commented May 2, 2024

r? @ehuss

rustbot has assigned @ehuss.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 2, 2024
@weihanglo
Copy link
Member

Looks pretty neat. Thanks!

@bors r+

@bors
Copy link
Contributor

bors commented May 2, 2024

📌 Commit f5892f2 has been approved by weihanglo

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 2, 2024
@bors
Copy link
Contributor

bors commented May 2, 2024

⌛ Testing commit f5892f2 with merge 9e57a8d...

@bors
Copy link
Contributor

bors commented May 2, 2024

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing 9e57a8d to master...

@bors bors merged commit 9e57a8d into rust-lang:master May 2, 2024
21 checks passed
bors added a commit to rust-lang-ci/rust that referenced this pull request May 3, 2024
Update cargo

18 commits in 6087566b3fa73bfda29702632493e938b12d19e5..05364cb2f61a2c2b091e061c1f42b207dfb5f81f
2024-04-30 20:45:20 +0000 to 2024-05-03 16:48:59 +0000
- chore(deps): update msrv (3 versions) to v1.76 (rust-lang/cargo#13857)
- Stabilize `-Zcheck-cfg` as always enabled (rust-lang/cargo#13571)
- fix(lints): Prevent inheritance from bring exposed for published packages (rust-lang/cargo#13852)
- refactor: remove unnecessary branch for link binary on macOS (rust-lang/cargo#13851)
- perf(toml): Avoid inferring when targets are known (rust-lang/cargo#13849)
- Update continuous-integration.md: Include CircleCI reference (rust-lang/cargo#13850)
- chore(deps): update msrv (1 version) to v1.78 (rust-lang/cargo#13848)
- Workaround copying file returning EAGAIN on ZFS on mac OS (rust-lang/cargo#13845)
- Clean package perf improvements (rust-lang/cargo#13818)
- fix(toml): Validate crates_types/proc-macro for bin like others (rust-lang/cargo#13841)
- fix(toml): On 2024 Edition, disallow ignored `default-features` when inheriting (rust-lang/cargo#13839)
- chore(ci): Ignore openssl deps (rust-lang/cargo#13840)
- fix(lints): Remove ability to specify `-` in lint name (rust-lang/cargo#13837)
- fix(resolver): Treat unset MSRV as compatible (rust-lang/cargo#13791)
- fix(toml): Don't lose 'public' when inheriting a dep (rust-lang/cargo#13836)
- chore(deps): update compatible (rust-lang/cargo#13834)
- Error when unstable lints are specified but not enabled (rust-lang/cargo#13805)
- fix(lint): Warn not Error on unsupported lint tool (rust-lang/cargo#13833)

r? ghost

Note: this includes the fix that was beta backported in rust-lang#124647
bors added a commit to rust-lang-ci/rust that referenced this pull request May 4, 2024
Update cargo

18 commits in 6087566b3fa73bfda29702632493e938b12d19e5..05364cb2f61a2c2b091e061c1f42b207dfb5f81f
2024-04-30 20:45:20 +0000 to 2024-05-03 16:48:59 +0000
- chore(deps): update msrv (3 versions) to v1.76 (rust-lang/cargo#13857)
- Stabilize `-Zcheck-cfg` as always enabled (rust-lang/cargo#13571)
- fix(lints): Prevent inheritance from bring exposed for published packages (rust-lang/cargo#13852)
- refactor: remove unnecessary branch for link binary on macOS (rust-lang/cargo#13851)
- perf(toml): Avoid inferring when targets are known (rust-lang/cargo#13849)
- Update continuous-integration.md: Include CircleCI reference (rust-lang/cargo#13850)
- chore(deps): update msrv (1 version) to v1.78 (rust-lang/cargo#13848)
- Workaround copying file returning EAGAIN on ZFS on mac OS (rust-lang/cargo#13845)
- Clean package perf improvements (rust-lang/cargo#13818)
- fix(toml): Validate crates_types/proc-macro for bin like others (rust-lang/cargo#13841)
- fix(toml): On 2024 Edition, disallow ignored `default-features` when inheriting (rust-lang/cargo#13839)
- chore(ci): Ignore openssl deps (rust-lang/cargo#13840)
- fix(lints): Remove ability to specify `-` in lint name (rust-lang/cargo#13837)
- fix(resolver): Treat unset MSRV as compatible (rust-lang/cargo#13791)
- fix(toml): Don't lose 'public' when inheriting a dep (rust-lang/cargo#13836)
- chore(deps): update compatible (rust-lang/cargo#13834)
- Error when unstable lints are specified but not enabled (rust-lang/cargo#13805)
- fix(lint): Warn not Error on unsupported lint tool (rust-lang/cargo#13833)

r? ghost

Note: this includes the fix that was beta backported in rust-lang#124647
@rustbot rustbot added this to the 1.80.0 milestone May 4, 2024
@epage epage deleted the no-infer branch May 17, 2024 19:30
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request May 24, 2024
Update cargo

18 commits in 6087566b3fa73bfda29702632493e938b12d19e5..05364cb2f61a2c2b091e061c1f42b207dfb5f81f
2024-04-30 20:45:20 +0000 to 2024-05-03 16:48:59 +0000
- chore(deps): update msrv (3 versions) to v1.76 (rust-lang/cargo#13857)
- Stabilize `-Zcheck-cfg` as always enabled (rust-lang/cargo#13571)
- fix(lints): Prevent inheritance from bring exposed for published packages (rust-lang/cargo#13852)
- refactor: remove unnecessary branch for link binary on macOS (rust-lang/cargo#13851)
- perf(toml): Avoid inferring when targets are known (rust-lang/cargo#13849)
- Update continuous-integration.md: Include CircleCI reference (rust-lang/cargo#13850)
- chore(deps): update msrv (1 version) to v1.78 (rust-lang/cargo#13848)
- Workaround copying file returning EAGAIN on ZFS on mac OS (rust-lang/cargo#13845)
- Clean package perf improvements (rust-lang/cargo#13818)
- fix(toml): Validate crates_types/proc-macro for bin like others (rust-lang/cargo#13841)
- fix(toml): On 2024 Edition, disallow ignored `default-features` when inheriting (rust-lang/cargo#13839)
- chore(ci): Ignore openssl deps (rust-lang/cargo#13840)
- fix(lints): Remove ability to specify `-` in lint name (rust-lang/cargo#13837)
- fix(resolver): Treat unset MSRV as compatible (rust-lang/cargo#13791)
- fix(toml): Don't lose 'public' when inheriting a dep (rust-lang/cargo#13836)
- chore(deps): update compatible (rust-lang/cargo#13834)
- Error when unstable lints are specified but not enabled (rust-lang/cargo#13805)
- fix(lint): Warn not Error on unsupported lint tool (rust-lang/cargo#13833)

r? ghost

Note: this includes the fix that was beta backported in #124647
Comment on lines +551 to +562
fn is_resolved(toml_targets: Option<&Vec<TomlTarget>>, autodiscover: Option<bool>) -> bool {
if autodiscover != Some(false) {
return false;
}

let Some(toml_targets) = toml_targets else {
return true;
};
toml_targets
.iter()
.all(|t| t.name.is_some() && t.path.is_some())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this mean that if in the Cargo.toml (whether normalized or not) all [[bin]] entries contain a name and path field then the auto-discovery of additional bins is disabled? that seems to have potential for false positives and would not match https://doc.rust-lang.org/cargo/reference/cargo-targets.html#target-auto-discovery. last time this behavior was changed it was done at an edition boundary 🤔

Copy link
Contributor Author

@epage epage Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only get here if autodiscover is explicitly disabled. We reuse autodiscover logic is reused to fill in name or path and this is checking to see if that is needed.

If there is a behavior change you noticed, could you be more explicit about what it is?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only get here if autodiscover is explicitly disabled.

ahhh, you're right. I misinterpreted the double negation in the code. in that case: sorry for the noise! :)

epage added a commit to epage/cargo that referenced this pull request Jul 25, 2024
I just published all of my packages using Cargo 1.80 and wanted to see
the effect of the enumerating targets during publish (rust-lang#13849).
bors added a commit that referenced this pull request Jul 26, 2024
chore: Update dependencies

I just published all of my packages using Cargo 1.80 and wanted to see the effect of the enumerating targets during publish (#13849).
epage added a commit to epage/cargo that referenced this pull request Sep 24, 2024
PR rust-lang#5335 added `autobins`, etc for rust-lang#5330.  Nowhere in there is
discussion of `autolib`.

Cargo script disables support for additional build-targets by disabling
discovery.
Except we don't have a way to disable discovery of `autolib`, leading to rust-lang#14476.
By adding `autolib`, we can continue in that direction.

This also allows us to bypass inferring of libs on published packages,
like all other build-targets which were handled in rust-lang#13849.

As this seems fairly low controversy, this insta-stabilizes the field.
In prior versions of Cargo, users will get an "unused manifest key"
warning.
For packags where this is set by `cargo publish`, the warning will be suppressed and things will work as normal.
For `cargo vendor`, the same except there will be some churn in the
vendored source as this field will now be set.
For local development, it should be rare to set `autolib` so the lack of
error by discovering a file when this is set shouldn't be a problem.

Fixes rust-lang#14476
@epage epage mentioned this pull request Sep 24, 2024
epage added a commit to epage/cargo that referenced this pull request Sep 24, 2024
PR rust-lang#5335 added `autobins`, etc for rust-lang#5330.  Nowhere in there is
discussion of `autolib`.

Cargo script disables support for additional build-targets by disabling
discovery.
Except we don't have a way to disable discovery of `autolib`, leading to rust-lang#14476.
By adding `autolib`, we can continue in that direction.

This also allows us to bypass inferring of libs on published packages,
like all other build-targets which were handled in rust-lang#13849.

As this seems fairly low controversy, this insta-stabilizes the field.
In prior versions of Cargo, users will get an "unused manifest key"
warning.
For packags where this is set by `cargo publish`, the warning will be suppressed and things will work as normal.
For `cargo vendor`, the same except there will be some churn in the
vendored source as this field will now be set.
For local development, it should be rare to set `autolib` so the lack of
error by discovering a file when this is set shouldn't be a problem.

Fixes rust-lang#14476
epage added a commit to epage/cargo that referenced this pull request Sep 25, 2024
PR rust-lang#5335 added `autobins`, etc for rust-lang#5330.  Nowhere in there is
discussion of `autolib`.

Cargo script disables support for additional build-targets by disabling
discovery.
Except we don't have a way to disable discovery of `autolib`, leading to rust-lang#14476.
By adding `autolib`, we can continue in that direction.

This also allows us to bypass inferring of libs on published packages,
like all other build-targets which were handled in rust-lang#13849.

As this seems fairly low controversy, this insta-stabilizes the field.
In prior versions of Cargo, users will get an "unused manifest key"
warning.
For packags where this is set by `cargo publish`, the warning will be suppressed and things will work as normal.
For `cargo vendor`, the same except there will be some churn in the
vendored source as this field will now be set.
For local development, it should be rare to set `autolib` so the lack of
error by discovering a file when this is set shouldn't be a problem.

Fixes rust-lang#14476
epage added a commit to epage/cargo that referenced this pull request Sep 26, 2024
PR rust-lang#5335 added `autobins`, etc for rust-lang#5330.  Nowhere in there is
discussion of `autolib`.

Cargo script disables support for additional build-targets by disabling
discovery.
Except we don't have a way to disable discovery of `autolib`, leading to rust-lang#14476.
By adding `autolib`, we can continue in that direction.

This also allows us to bypass inferring of libs on published packages,
like all other build-targets which were handled in rust-lang#13849.

As this seems fairly low controversy, this insta-stabilizes the field.
In prior versions of Cargo, users will get an "unused manifest key"
warning.
For packags where this is set by `cargo publish`, the warning will be suppressed and things will work as normal.
For `cargo vendor`, the same except there will be some churn in the
vendored source as this field will now be set.
For local development, it should be rare to set `autolib` so the lack of
error by discovering a file when this is set shouldn't be a problem.

Fixes rust-lang#14476
epage added a commit to epage/cargo that referenced this pull request Sep 26, 2024
PR rust-lang#5335 added `autobins`, etc for rust-lang#5330.  Nowhere in there is
discussion of `autolib`.

Cargo script disables support for additional build-targets by disabling
discovery.
Except we don't have a way to disable discovery of `autolib`, leading to rust-lang#14476.
By adding `autolib`, we can continue in that direction.

This also allows us to bypass inferring of libs on published packages,
like all other build-targets which were handled in rust-lang#13849.

As this seems fairly low controversy, this insta-stabilizes the field.
In prior versions of Cargo, users will get an "unused manifest key"
warning.
For packags where this is set by `cargo publish`, the warning will be suppressed and things will work as normal.
For `cargo vendor`, the same except there will be some churn in the
vendored source as this field will now be set.
For local development, it should be rare to set `autolib` so the lack of
error by discovering a file when this is set shouldn't be a problem.

Fixes rust-lang#14476
bors added a commit that referenced this pull request Sep 27, 2024
feat(toml): Add `autolib`

### What does this PR try to resolve?

PR #5335 added `autobins`, etc for #5330.  Nowhere in there is
discussion of `autolib`.

Cargo script disables support for additional build-targets by disabling
discovery.
Except we don't have a way to disable discovery of `autolib`, leading to #14476.
By adding `autolib`, we can continue in that direction.

This also allows us to bypass inferring of libs on published packages,
like all other build-targets which were handled in #13849.

Fixes #14476

### How should we test and review this PR?

### Additional information

As this seems fairly low controversy, this insta-stabilizes the field.
In prior versions of Cargo, users will get an "unused manifest key"
warning.
For packages where this is set by `cargo publish`, the warning will be suppressed and things will work as normal.
For `cargo vendor`, the same except there will be some churn in the
vendored source as this field will now be set.
For local development, it should be rare to set `autolib` so the lack of
error by discovering a file when this is set shouldn't be a problem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants