Repository navigation
fix(ulimit): compile against musl and OpenHarmony libcs - #449
Merged
Merged
Conversation
`resource()` and `rlimit_get()` spelled the selector as `libc::__rlimit_resource_t`, which only glibc defines. On musl and on the OpenHarmony libc (`target_os = "linux"`, `target_env = "musl"`/`"ohos"`) that typedef does not exist at all; both libcs take a plain `c_int`. Alias the type once, gated on `target_env`, so one body compiles for all three libcs: target_env = "gnu" -> libc::__rlimit_resource_t (c_uint) otherwise -> libc::c_int Verified with `cargo check` on x86_64-unknown-linux-gnu (host), x86_64-unknown-linux-musl and aarch64-unknown-linux-ohos: all three are clean. Before this change musl and ohos each failed with 2 errors here (`cannot find type __rlimit_resource_t`), and the ohos target is the only thing standing between rubash and HarmonyOS PC support. Note the two `rlimit_get` bodies (linux / other-unix) are now byte-identical and could be merged in a follow-up; left alone here to keep this diff reviewable.
Member
Author
|
配套 PR:unixwin/niubash#210 — 在 niubash 的 那个 job 现在会红,就是在等这个 PR 落地。 反向实测:不打这个补丁,ohos 到底炸不炸为了确认这个修不是「顺手改改」,我在本地把补丁撤掉重跑了一次 niubash 的 ohos 检查: 正好 2 处,跟预期一致。 打上补丁之后的实测不只是 rubash 自己过——整个 niubash workspace 在 ohos 上也编译通过: musl 那边同理(55.12s,全绿)。这是 niubash 本体第一次被证明能在 一句话这个补丁是 HarmonyOS PC 那条路上唯一的编译阻塞点。它落地, |
caomengxuan666
added a commit
to unixwin/niubash
that referenced
this pull request
Oct 9, 2026
`cross-check` runs on ubuntu-latest and macos-latest, which are both x86_64/glibc. Nothing covers musl, and nothing covers aarch64 at all, so whole classes of libc and arch divergence are invisible to CI. That is not hypothetical. rubash's `ulimit` typed its resource selector as `libc::__rlimit_resource_t`, a typedef only glibc defines. musl and the OpenHarmony libc take a plain `c_int`, so both targets failed with two `cannot find type` errors each -- while `cross-check` stayed green, because the host is glibc and the cfg guard was `target_os = "linux"`, which ohos satisfies (`target_env = "ohos"`, not `"gnu"`). Add a `cross-target-check` job that `cargo check --workspace` for an explicit target: x86_64-unknown-linux-musl - the musl libc, and the static/Alpine story aarch64-unknown-linux-ohos - HarmonyOS PC `aarch64-unknown-linux-ohos` is Tier 2 with host tools, so a check-only build needs no OpenHarmony SDK or clang wrapper; `setup-rust-toolchain`'s `target:` input is enough. Both targets are unix, so the sibling rubash checkout and the `[patch]` override behave exactly as in the other jobs -- in particular no `cargo update -p rubash`, same reasoning as the comment already carried by `build-and-test` and `cross-check`. Depends on unixwin/rubash#449 (merged as 2b9c437), which is the fix that makes ohos clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
rubash 现在能不能跑在 HarmonyOS 上,卡点只剩
ulimit一个文件。这一版把那个卡点拆掉了。问题
src/builtins/ulimit.rs里这两处的资源选择器写死了libc::__rlimit_resource_t:这个 typedef 只有 glibc 有:
pub type __rlimit_resource_t = c_uint;(libc/src/unix/linux_like/linux/gnu/mod.rs:6),getrlimit/setrlimit收c_uintgetrlimit/setrlimit直接收c_intlibc 自己在
linux_like/linux/arch/generic/mod.rs里就是按target_env分家的——RLIMIT_CPU在 gnu 下是crate::__rlimit_resource_t(L282),在非 gnu 下是c_int(L302)。所以
target_os = "linux"这层 cfg 拦不住 musl/ohos:它们确实是target_os = "linux"(target_env = "gnu"才是 glibc 的判据),于是走进函数体,然后找不到类型。修法
加一个按
target_env分家的类型别名,两处引用都走它:+11 / −2,只碰这一个文件。
验证
三平台
cargo check全绿:x86_64-unknown-linux-gnu(宿主)x86_64-unknown-linux-muslaarch64-unknown-linux-ohos修前的两个报错都是
cannot find type __rlimit_resource_t in crate libc(resource/rlimit_get各一)。中间踩过一个坑记录一下:第一版我图省事直接全局
sed s/__rlimit_resource_t/c_int/,musl/ohos 是绿了,宿主 glibc 反过来炸了 4 处(expected u32, found i32)——因为 glibc 那边真是c_uint。所以必须是类型别名,不能统一改成c_int。后续
rlimit_get的函数体现在逐字节相同了,理论上可以合成一个;这次没动,想让这个 diff 保持好读,留着以后单独提。cross-checkjob 里目前只有几个 linux target,建议把aarch64-unknown-linux-ohos和x86_64-unknown-linux-musl加进去(niubash 那边同步加),否则这类回归没有 CI 兜着。顺带说明:
__rlimit_resource_t在 upstream master(29baac9a)里仍在这两行,直接git apply就能落。