fix: build with rustc 1.81 (MSRV lock, stable APIs, deflate64 patch) - #4
Conversation
- declare rust-version = 1.81 across workspace, re-resolve lockfile (toml 1.0.7+spec, time 0.3.44, image 0.25.6 stay 1.81-compatible) - replace 1.82+ APIs: is_none_or -> map_or(true, ..) (rofd-core/paint, rofd-render/cairo_renderer), is_multiple_of -> % != 0 (rofd-ffi/error), iter::repeat_n -> repeat().take() (rofd reader) - patch deflate64 0.1.12: nightly unbounded_shr -> stable checked_shr via [patch.crates-io] path dependency (patches/deflate64) Verified: cargo +1.81 check --release --workspace; dpkg-buildpackage on x86_64 (local), loongarch64 (10.8.12.56), mips64el (10.8.12.58).
Reviewer's GuideThe PR makes the workspace buildable with rustc/Cargo 1.81 by removing newer standard-library APIs, declaring and lock-resolving against the 1.81 MSRV, and locally patching deflate64 to remove its newer compiler intrinsic while preserving the root binary’s zip feature behavior. Flow diagram for the MSRV-compatible dependency resolutionflowchart TD
Start[Build workspace with Rust 1.81]
Declare[Declare rust-version 1.81]
Resolve[Cargo resolves dependencies with fallback]
Downgrade[Select dependency versions compatible with 1.81]
Patch[Apply crates.io patch for deflate64]
Build[Compile workspace and Debian targets]
Success[Build succeeds across supported architectures]
Start --> Declare --> Resolve --> Downgrade --> Patch --> Build --> Success
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="crates/rofd-ffi/src/error.rs" line_range="505-506" />
<code_context>
}
let start = pointer as usize;
- if !start.is_multiple_of(alignment) {
+ if start % alignment != 0 {
return Err(());
}
let end = start.checked_add(size).ok_or(())?;
</code_context>
<issue_to_address>
**issue (bug_risk):** `start % alignment` panics when `alignment` is zero, whereas `is_multiple_of(0)` returns false for a nonzero pointer and the previous code returned `Err(())`. `SlotRange::for_region` accepts the alignment value without rejecting zero.
**Triggers:** When an internal caller passes a non-null pointer with `alignment == 0`.
**Suggested fix:** Reject zero alignment before the modulo operation, or preserve the old zero-divisor behavior explicitly.
```suggestion
if alignment == 0 || start % alignment != 0 {
return Err(());
```
</issue_to_address>
### Comment 2
<location path="Cargo.toml" line_range="39" />
<code_context>
resolver = "2"
[workspace.package]
+rust-version = "1.81"
edition = "2021"
license = "LGPL-2.1-or-later"
</code_context>
<issue_to_address>
**nitpick:** The `ofdrw-compat` workspace member does not set `rust-version.workspace = true`, so the declared 1.81 MSRV is not enforced for that package and its dev-dependency resolution. A future API or dependency update in the compatibility tests can therefore bypass the lockfile's intended workspace-wide MSRV guard.
**Triggers:** When the compatibility-test package gains a Rust-1.82-or-newer API or dependency.
**Suggested fix:** Add `rust-version.workspace = true` to `tests/ofdrw-compat/Cargo.toml`.
</issue_to_address>| if start % alignment != 0 { | ||
| return Err(()); |
There was a problem hiding this comment.
issue (bug_risk): start % alignment panics when alignment is zero, whereas is_multiple_of(0) returns false for a nonzero pointer and the previous code returned Err(()). SlotRange::for_region accepts the alignment value without rejecting zero.
Triggers: When an internal caller passes a non-null pointer with alignment == 0.
Suggested fix: Reject zero alignment before the modulo operation, or preserve the old zero-divisor behavior explicitly.
| if start % alignment != 0 { | |
| return Err(()); | |
| if alignment == 0 || start % alignment != 0 { | |
| return Err(()); |
| resolver = "2" | ||
|
|
||
| [workspace.package] | ||
| rust-version = "1.81" |
There was a problem hiding this comment.
nitpick: The ofdrw-compat workspace member does not set rust-version.workspace = true, so the declared 1.81 MSRV is not enforced for that package and its dev-dependency resolution. A future API or dependency update in the compatibility tests can therefore bypass the lockfile's intended workspace-wide MSRV guard.
Triggers: When the compatibility-test package gains a Rust-1.82-or-newer API or dependency.
Suggested fix: Add rust-version.workspace = true to tests/ofdrw-compat/Cargo.toml.
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 所有 API 替换均语义正确,无需修改。建议在后续 rustc 版本升级时考虑恢复使用标准 API。 2. 代码质量 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 建议定期关注上游 deflate64 crate 是否修复了 unbounded_shr 兼容性问题,以便移除 vendored patch。 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 无性能问题,所有替换对性能无负面影响。 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 无安全建议,代码安全合规。 💡 改进建议代码示例// 本次 PR 的所有 API 替换均为语义等价替换,无需额外修复代码示例
// 以下是各替换点的等价性说明:
// 1. is_none_or → map_or(true, ...)
// Option::is_none_or(f) = match self { None => true, Some(x) => f(x) }
// Option::map_or(true, f) = match self { None => true, Some(x) => f(x) }
// 完全等价
// 2. is_multiple_of → % != 0
// x.is_multiple_of(y) = (x % y == 0)
// !x.is_multiple_of(y) = (x % y != 0)
// 当 y != 0 时完全等价(align_of::<T>() >= 1)
// 3. repeat_n → repeat().take()
// iter::repeat_n(i, n) 产生 n 个 i
// iter::repeat(i).take(n) 产生 n 个 i
// 对 extend() 消费行为完全等价
// 4. unbounded_shr → checked_shr().unwrap_or(0)
// u32::unbounded_shr(n) = if n >= 32 { 0 } else { self >> n }
// u32::checked_shr(n).unwrap_or(0) = if n >= 32 { 0 } else { self >> n }
// 完全等价本报告由 AI 代码审查工具自动生成 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/merge |
背景 / Background
UOS 各架构构建机(loongarch64 / mips64el / aarch64 / sw_64)使用发行版 rustc/cargo 1.81 工具链,当前代码与依赖图无法在 1.81 下构建,导致 OFD 支持无法在这些架构上打包。
变更 / Changes
is_none_or→map_or(true, …)(crates/rofd-core/src/paint.rs、crates/rofd-render/src/cairo_renderer.rs)is_multiple_of→% != 0(crates/rofd-core/src/error.rs)repeat_n→repeat().take()(crates/rofd-core/src/reader.rs)[workspace.package]增加rust-version = "1.81",后续若引入更高 MSRV 的 API/依赖,cargo 会在解析期给出明确报错,防止无意识回归CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS=fallback在 1.98 下重解析,56 项 >1.81 的依赖降级(toml 1.1.5→1.0.7、time 0.3.55→0.3.44、image 0.25.10→0.25.6 及传递链)。注:原 lock 中 toml 1.1.5 → serde_spanned 1.1.1 使用 edition2024,cargo 1.81 连清单都无法解析,lock 重解析是硬前提input_buffer.rs:21使用 1.87 才稳定的unbounded_shr)。根包 bin 自带的zip = "2.2.2"(默认 features)会把 deflate64 拉入构建图,cargo build -p rofd(deb 打包路径)必然编译它。补丁将(!0u32).unbounded_shr(n)替换为语义等价的(!0u32).checked_shr(n).unwrap_or(0),经[patch.crates-io]生效验证 / Verification
cargo check --release --workspace✅;dpkg-buildpackage产出 rofd / librofd-ffi0 / librofd-ffi-dev ✅备注
rust-version,且 0.1.12 无条件使用 1.87 才稳定的 API,stable <1.87 用户全中招,计划向上游报告zip = "2.2.2"改为zip.workspace = true可让 deflate64 彻底离开构建图,但会改变 bin 的 zip feature 语义,故采用无语义变化的 patch 方案Summary by Sourcery
Make the project buildable and packageable with the Rust 1.81 toolchain used by supported distribution build hosts.
Bug Fixes:
Enhancements:
Build:
Tests: