Skip to content

loongarch64-linux-musl broken after libc v0.2.179 #4939

@heiher

Description

@heiher

Reproduce

# Install cross
cargo install cross --git https://github.com/cross-rs/cross

# Create reproducer
cargo new hello
cd hello
cargo add gix-index

# Build
cross build --target loongarch64-unknown-linux-musl

Expected behavior

Build successful.

Unexpected behavior

error[E0609]: no field `st_mtime` on type `libc::stat`
  --> /home/hev/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/gix-index-0.46.0/src/fs.rs:58:34
   |
58 |             let seconds = self.0.st_mtime;
   |                                  ^^^^^^^^ unknown field
   |
help: a field with a similar name exists
   |
58 -             let seconds = self.0.st_mtime;
58 +             let seconds = self.0.st_mtim;
   |

I've bisected the issue to commit 55fa65b (PR #4463). That commit changes the member fields of struct stat based on the musl_v1_2_3 condition. Since musl_v1_2_3 is currently enabled for LoongArch64, while most libc users have not yet switched to the new fields, LoongArch64 ends up hitting build failures more easily than other targets.

Rust libc:

#[cfg(not(musl_v1_2_3))]
pub st_atime: crate::time_t,
#[cfg(not(musl_v1_2_3))]
pub st_atime_nsec: c_long,
#[cfg(not(musl_v1_2_3))]
pub st_mtime: crate::time_t,
#[cfg(not(musl_v1_2_3))]
pub st_mtime_nsec: c_long,
#[cfg(not(musl_v1_2_3))]
pub st_ctime: crate::time_t,
#[cfg(not(musl_v1_2_3))]
pub st_ctime_nsec: c_long,
#[cfg(musl_v1_2_3)]
pub st_atim: crate::timespec,
#[cfg(musl_v1_2_3)]
pub st_mtim: crate::timespec,
#[cfg(musl_v1_2_3)]
pub st_ctim: crate::timespec,

Upstream musl:
https://github.com/kraj/musl/blob/0784374d561435f7c787a555aeab8ede699ed298/arch/loongarch64/bits/stat.h#L14-L16

	struct timespec st_atim;
	struct timespec st_mtim;
	struct timespec st_ctim;

I think it makes sense to more toward musl_v1_2_3. However, we may need more time to properly prepare and align downstream users before fully enabling it.

How about introducing a new, more explicit condition (for example, musl_stat_use_timespec) and only enabling it for targets whose downstream is ready? Thanks!

cc @xbjfk @tgross35 @alexcrichton @martinetd

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions