time-rs / time

The most used Rust library for date and time handling.
https://time-rs.github.io
Apache License 2.0
1.09k stars 273 forks source link

Update use of libc::timespec to prepare for future libc version #528

Closed wesleywiser closed 1 year ago

wesleywiser commented 1 year ago

In a future release of the libc crate, libc::timespec will contains private padding fields on 32-bit *-linux-musl targets and so the struct will no longer be able to be created using the literal initializer syntax.

The only uses in this crate of libc::timespec in this way were zero initializing the struct. Thus, these can be replaced by a call to std::mem::zeroed() which is compatible with both current versions of the libc crate as well as the future version which will contain those private padding fields.

I tested this locally both with a modified libc/i686-unknown-linux-musl target and with the current libc/i686-unknown-linux-musl target. The code builds and all tests pass. The GH workflow required disabling a deny(warnings) for new warnings that are emitted since the last time the branch was built but it succeeded other than the test-old tasks which failed because of dependency resolution errors with the cfg-if crate.

Related to https://github.com/rust-lang/libc/pull/2088

jhpratt commented 1 year ago

This will be released as soon as I can fix CI. It's changed a fair amount since the last 0.1 release.

jhpratt commented 1 year ago

Well, CI passes when using the latest stable, but fails with a linker error on MacOS on 1.21.0. I am able to successfully cross-compile it from Linux to MacOS on 1.21.0, so I'm releasing as-is. We'll find out soon enough if there are any issues :smile:

wesleywiser commented 1 year ago

Just FYI that seems to be a common issue with older Rust versions on newer macOS versions: https://github.com/Amanieu/parking_lot/pull/363#issuecomment-1325308038

Thanks so much for your help with this!

jhpratt commented 1 year ago

Well, so be it. I figured if I could cross-compile it, then there was no true issue. Thanks for doing the legwork of the various patches.