-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
initial version of checksum based freshness #14137
base: master
Are you sure you want to change the base?
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @weihanglo (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
320f73c
to
310cd79
Compare
cce62ba
to
59441b6
Compare
27e2a18
to
c83be55
Compare
Add unstable support for outputting file checksums for use in cargo Adds an unstable option that appends file checksums and expected lengths to the end of the dep-info file such that `cargo` can read and use these values as an alternative to file mtimes. This PR powers the changes made in this cargo PR rust-lang/cargo#14137 Here's the tracking issue for the cargo feature rust-lang/cargo#14136.
☔ The latest upstream changes (presumably #13947) made this pull request unmergeable. Please resolve the merge conflicts. |
c83be55
to
b8c21fa
Compare
Merge conflicts resolved. |
5fd5b21
to
6e41031
Compare
This commit is not really necessary to be in the commit history. It is just for me to start over the test porting.
* cargo_env_changes * fingerprint_cleaner_does_not_rebuild * modify_only_some_files * rebuild_if_build_artifacts_move_forward_in_time * simulated_docker_deps_stay_cached * update_dependency_mtime_does_not_rebuild
These tests are modified or renamed to reflect the switch to checksum fingerprint: * bust_patched_dep * modifying_and_moving * rebuild_on_mid_build_file_modification * rebuild_sub_package_then_while_package * skip_mtime_check_in_selected_cargo_home_subdirs * use_mtime_cache_in_cargo_home
We don't rely on mtime anymore for checksum-based fingerprint
Two new tests: * checksum_actually_uses_checksum: chekcsum works when mtime forwards * same_size_different_content: checksum does check content
…yukang Add unstable support for outputting file checksums for use in cargo Adds an unstable option that appends file checksums and expected lengths to the end of the dep-info file such that `cargo` can read and use these values as an alternative to file mtimes. This PR powers the changes made in this cargo PR rust-lang/cargo#14137 Here's the tracking issue for the cargo feature rust-lang/cargo#14136.
Rollup merge of rust-lang#126930 - Xaeroxe:file-checksum-hint, r=chenyukang Add unstable support for outputting file checksums for use in cargo Adds an unstable option that appends file checksums and expected lengths to the end of the dep-info file such that `cargo` can read and use these values as an alternative to file mtimes. This PR powers the changes made in this cargo PR rust-lang/cargo#14137 Here's the tracking issue for the cargo feature rust-lang/cargo#14136.
Add unstable support for outputting file checksums for use in cargo Adds an unstable option that appends file checksums and expected lengths to the end of the dep-info file such that `cargo` can read and use these values as an alternative to file mtimes. This PR powers the changes made in this cargo PR rust-lang/cargo#14137 Here's the tracking issue for the cargo feature rust-lang/cargo#14136.
@bors try Let's see how it really goes. |
initial version of checksum based freshness Implementation for #14136 and resolves #6529 This PR implements the use of checksums in cargo fingerprints as an alternative to using mtimes. This is most useful on systems with poor mtime implementations. This has a dependency on rust-lang/rust#126930. It's expected this will increase the time it takes to declare a build to be fresh. Still this loss in performance may be preferable to the issues the ecosystem has had with the use of mtimes for determining freshness.
💔 Test failed - checks-actions |
All tests are passed. I will do another round of review today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be willing to rearrange commits and make them easier to review/track for future readers?
Some intermediate commits like a45d663 and 5b36d64 could be squashed, and some like what I've done for tests are helpful to understand they were copied from the other file.
If that sounds too much a burden, no worries. I can do a simple cleanup before this PR merges. Thank you :)
let mut cmd = p.cargo("build").arg("-Zchecksum-freshness").build_command(); | ||
let output = cmd.output().unwrap(); | ||
assert!( | ||
String::from_utf8(output.stderr) | ||
.unwrap() | ||
.contains("error: the `-Z` flag is only accepted on the nightly channel of Cargo, but this is the `stable` channel") | ||
); | ||
assert!(!output.status.success()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually use Cargo-idiom test to write stuff, such as this one
Could you tweak it a bit to something like this?
let mut cmd = p.cargo("build").arg("-Zchecksum-freshness").build_command(); | |
let output = cmd.output().unwrap(); | |
assert!( | |
String::from_utf8(output.stderr) | |
.unwrap() | |
.contains("error: the `-Z` flag is only accepted on the nightly channel of Cargo, but this is the `stable` channel") | |
); | |
assert!(!output.status.success()); | |
p.cargo("build -Zchecksum-freshness") | |
.with_stderr_data(str![[ | |
r#"[ERROR] the `-Z` flag is only accepted on the nightly channel of Cargo, but this is the `stable` channel | |
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels. | |
"#]]) | |
.with_status(101) | |
.run(); |
#[derive(Debug, Eq, PartialEq, Hash, Copy, Clone)] | ||
pub enum DepInfoPathType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't needed, right?
#[derive(Debug, Eq, PartialEq, Hash, Copy, Clone)] | |
pub enum DepInfoPathType { | |
enum DepInfoPathType { |
#[derive(Copy, Clone, Debug, Eq, PartialEq)] | ||
pub struct InvalidChecksumAlgo {} | ||
|
||
impl Display for InvalidChecksumAlgo { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "expected `sha256`, or `blake3`") | ||
} | ||
} | ||
|
||
impl std::error::Error for InvalidChecksumAlgo {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type doesn't seem needed. We can inline the string message into InvalidChecksum::InvalidChecksumAlgo
.
} | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, Eq, PartialEq, thiserror::Error)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be sufficient.
#[derive(Clone, Copy, Debug, Eq, PartialEq, thiserror::Error)] | |
#[derive(Debug, thiserror::Error)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have a test checking that switch -Zfreshness-checksum
on and off, and check they still build successfully?
#[cfg_attr( | ||
not(all(target_arch = "x86_64", target_os = "windows", target_env = "msvc")), | ||
ignore | ||
)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be sufficient
#[cfg_attr( | |
not(all(target_arch = "x86_64", target_os = "windows", target_env = "msvc")), | |
ignore | |
)] | |
#[cfg(all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have a test verifying that the Cargo-flavored dep-info under fingerprint folder is correctly encoded? Something like relative_depinfo_paths_ws
but simpler
Implementation for #14136 and resolves #6529
This PR implements the use of checksums in cargo fingerprints as an alternative to using mtimes. This is most useful on systems with poor mtime implementations.
This has a dependency on rust-lang/rust#126930. It's expected this will increase the time it takes to declare a build to be fresh. Still this loss in performance may be preferable to the issues the ecosystem has had with the use of mtimes for determining freshness.