Update workspace to Rust edition 2024#1902
Conversation
Migrate all crates from edition 2021 to 2024. This includes updating Cargo.toml files and fixing code compatibility issues. The MSRV is bumped to 1.85.0 to support edition 2024. Note: global_init() requires #[allow(unsafe_code)] for std::env::set_var which is now unsafe in edition 2024. This is safe because the function is called early in main() before any threads are spawned. Closes: bootc-dev#1414 Signed-off-by: Daniele Guarascio <guarascio.daniele@gmail.com>
There was a problem hiding this comment.
Code Review
This pull request effectively updates the entire workspace to the Rust 2024 edition. The changes, including updating Cargo.toml files, running cargo fmt, and handling the new unsafe requirement for std::env::set_var, are well-executed and necessary for the edition upgrade. The justification for the unsafe block is clear and sound. I also appreciate the readability improvements from renaming variables in a few places.
I've added two comments supporting your suggestion to update the rust-version in bootc-lib and system-reinstall-bootc to reflect the actual MSRV required by their dependencies. This will ensure the crate metadata is accurate and helps prevent build issues for contributors.
Overall, this is a great contribution that keeps the project up-to-date with the latest Rust standards.
| version = "1.12.0" | ||
| # In general we try to keep this pinned to what's in the latest RHEL9. | ||
| rust-version = "1.84.0" | ||
| rust-version = "1.85.0" |
There was a problem hiding this comment.
As you correctly pointed out in the pull request description, while 1.85.0 is the minimum for the Rust 2024 edition, this crate has dependencies (like composefs) that require a newer Rust version (1.88.0). To ensure the MSRV is accurate and prevent build failures for users with older toolchains, it's best to update this field to reflect the actual minimum required version.
| rust-version = "1.85.0" | |
| rust-version = "1.88.0" |
| publish = false | ||
| # For now don't bump this above what is currently shipped in RHEL9. | ||
| rust-version = "1.75.0" | ||
| rust-version = "1.85.0" |
There was a problem hiding this comment.
There was a problem hiding this comment.
Yeah, can be a followup
There was a problem hiding this comment.
We don't have CI gating on actually testing our MSRV right now, I'm not opposed to it but we don't have anyone asking for it either.
It looks like the openssh-keys bump came in coreos/openssh-keys#115 (comment)
cgwalters
left a comment
There was a problem hiding this comment.
Thanks so much for doing this! Due to all the import and rustfmt changes this will be a conflict fest until merging, and I don't see a reason not to merge now, so let's do it!
| // Silence SELinux log warnings | ||
| ostree::SePolicy::set_null_log(); | ||
| let am_root = rustix::process::getuid().is_root(); | ||
| // Work around bootc-image-builder not setting HOME, in combination with podman (really c/common) |
There was a problem hiding this comment.
That said, this was my bad in not submitting a patch for this at the time, would still make sense to do. Then at least we could in theory eventually remove this code.
Summary
This PR updates the entire workspace to Rust edition 2024, resolving #1414.
Changes
edition = "2024"in all crateCargo.tomlfiles#[allow(unsafe_code)]toglobal_init()function ofcrates/lib/src/cli.rsforstd::env::set_varbootc-libandsystem-reinstall-bootccargo fmt --allgentogeneratorbecausegenis now a reserved keywordMSRV Considerations
The MSRV is set to 1.85.0 (minimum for edition 2024), but some dependencies
require higher versions:
composefs(git dependency) requires 1.88.0openssh-keys@0.6.5requires 1.90.0RHEL 9 Availability: According to the public UBI9 repository, RHEL 9
currently ships
rust-toolset-1.88.0-1.el9This means:
bootc-libcannot build with Rust < 1.88.0system-reinstall-bootccannot build with Rust < 1.90.0Question for maintainers: Should the
rust-versionfields be updated toreflect actual dependency requirements (1.88.0 and 1.90.0 respectively)?
Notes on
unsafeusageThe
global_init()function now uses#[allow(unsafe_code)]becausestd::env::set_varis marked unsafe in Rust 2024 edition. This is safebecause:
main()crates/cli/src/main.rs)I'm seeking maintainer approval for this localized unsafe exception, as the
project policy is
-D unsafe-codeworkspace-wide.Closes #1414