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(package): Speed up verify with 'check' #14930

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

epage
Copy link
Contributor

@epage epage commented Dec 12, 2024

What does this PR try to resolve?

In testing workspace publishing, I was really wishing for the build to be faster when I noticed the sea of status messages was "Compiling", instead of "Checking".
I've been glossing over those messages for years and never noticed!

This makes builds faster by skipping the compiler backend / codegen at the cost of not getting post-monomorphization errors. That seems like a small price to pay.

Fixes #14941

How should we test and review this PR?

I searched through the issues, open and closed, and saw no previous discussions of this. In particular, I was looking to see if this was previously rejected.
My only assumption is this was missed when cargo check was added.

Additional information

In testing workspace publishing, I was really wishing for the build to
be faster when I noticed the sea of status messages was "Compiling",
instead of "Checking".
I've been glossing over those messages for years and never noticed!

This makes builds faster by skipping the compiler backend / codegen at
the cost of not getting post-monomorphization errors.
That seems like a small price to pay.

I searched through the issues, open and closed, and saw no previous
discussions of this.  In particular, I was looking to see if this was
previously rejected.
My only assumption is this was missed when `cargo check` was added.
@rustbot
Copy link
Collaborator

rustbot commented Dec 12, 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 Command-package S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 12, 2024
@epage epage changed the title perf(package): Speed up verify by with 'check' perf(package): Speed up verify with 'check' Dec 12, 2024
@epage epage force-pushed the package-verify branch 2 times, most recently from 3ac2b9d to 3ca10ad Compare December 12, 2024 22:46
@@ -1157,7 +1157,7 @@ fn run_verify(
opts.jobs.clone(),
opts.keep_going,
&opts.targets,
CompileMode::Build,
CompileMode::Check { test: false },
Copy link
Member

Choose a reason for hiding this comment

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

For myself I would keep it a full build.
One reason is that cargo publish is not an operation easy to revert.

The other is, per RFC 3477,

A Rust program must compile with cargo build to be covered by Rust's standard stability guarantee.

If we want the same level of stability guarantee for published crates, we'd better do a full build.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess the question is what is it we intend to be verified and at what cost.

Things that can be verified

In commonly used crates, there is most likely a CI checking for what the author feels is important enough. I don't think cargo publish, especially be default, should or can replicate that.

What verify can help with is helping specifically with packaging specific issues

  • Are all the right files present
  • Can this build in isolation (to a degree)

For those, check is sufficient.

For people who don't have a CI, verify can tell them some but not much. Personally, I don't think we need to be verifying the stability guarantees in these cases, especially at the cost of expensive packaging, which has the most impact when doing it in dry-run mode which is where I most notice this (and tend to avoid dry run because of it).

Copy link
Member

Choose a reason for hiding this comment

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

On one hand, commonly used crates usually tend to have better CI checking support, so less likely to hit errors like this. Yet it depends on where they run cargo build or cargo test under release profile.

On the other hand, we are getting more API in const contexts (81 in 1.83). While const fn doesn't always contribute to error during monomorphization, it still increases the chances of hitting it.
(Check the minimal example in rust-lang/rust#112301 to understand how to get bitten).

There are also diagnostics during MIR passes cannot be caught by cargo check. By just looking at how easy the example is. I am afraid of this may be more troublesome than monomorphization errors.

I searched through the issues, open and closed, and saw no previous discussions of this.

Supposedly this is a starting point of examining all verification Cargo provides and re-position cargo commands, to embrace the potential plumbing commands reorganization (rust-lang/rust-project-goals#178 perhaps). However, instead of merging into this change now, perhaps we could create an issue and solicit feedback first?

Copy link
Member

Choose a reason for hiding this comment

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

By all means, I love how you’re thinking ahead with all these verification categories.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yet it depends on where they run cargo build or cargo test under release profile.

Good point that there is also --release

While const fn doesn't always contribute to error during rust-lang/rust#99682, it still increases the chances of hitting it.

There are also rust-lang/rust#49292 cannot be caught by cargo check

If post-check errors are getting that bad, then I have strong words for T-lang... The RFC test focuses on linker errors and doesn't justify its existence with it being prevalent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created #14941

@joshtriplett
Copy link
Member

joshtriplett commented Dec 17, 2024

I don't personally think this should be the default, because cargo build does catch things cargo check does not, per RFC 3477 as mentioned.

If people want this, for performance, it might make sense as an option people could choose to use. I personally don't think that option should be the default, but zero objections to an option if someone wants it.

That said, if we had an option for package/publish to do a full cargo test before packaging up (since test needs files that might not go into the package), then I think it'd make sense to only do check on the resulting package, because you'd already know tests pass so you only need to smoke-test that you've included everything you need in the package.

@rustbot
Copy link
Collaborator

rustbot commented Dec 25, 2024

☔ The latest upstream changes (possibly 0276088) made this pull request unmergeable. Please resolve the merge conflicts.

@ranger-ross
Copy link
Contributor

Just pitching in my 2 cents.
I also tend to lean towards keeping cargo build as part cargo publish for the additional verification.

I find that most crates publish new version once or twice a week at most.
So to me the tradeoff is saving of one or two builds a week vs keeping the additional validation.
With that framing, I think the extra time building are worth the additional protection against publishing a broken library.

Although I do think having the ability skip the build during publishing would be useful for projects that are large and publish frequently. (ie. internal business logic libraries that change frequently)
So having something like cargo publish --skip-build would make sense to me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Command-package Command-publish S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cargo package (and hence cargo publish) verify step is slow from doing a full build
6 participants