`steady_time` module fails to compile on Windows
Closed this issue · 5 comments
The steady_time
module introduced in a0d8c8e causes compile errors on Windows:
error[E0425]: cannot find function `clock_gettime` in crate `libc`
Error: --> C:\Users\runneradmin\.cargo\git\checkouts\ros2-client-1852ea698eaf7825\008b76c\src\steady_time.rs:35:27
|
35 | assert_eq!(0, libc::clock_gettime(libc::CLOCK_MONOTONIC, &mut ts));
| ^^^^^^^^^^^^^ not found in `libc`
error[E0425]: cannot find value `CLOCK_MONOTONIC` in crate `libc`
Error: --> C:\Users\runneradmin\.cargo\git\checkouts\ros2-client-1852ea698eaf7825\008b76c\src\steady_time.rs:35:47
|
35 | assert_eq!(0, libc::clock_gettime(libc::CLOCK_MONOTONIC, &mut ts));
| ^^^^^^^^^^^^^^^ not found in `libc`
The clock_gettime
POSIX function is not available on Windows.
rust
's std::time::Instant
uses the same system call on unix
system's that steady_time
is using: clock_gettime
with CLOCK_MONOTINC
.
It's guaranteed to be non-decreasing, and it seems like the implementation is as to monotonic as possible for the given hardware. The monotonicity section of the docs also states (emphasis added):
On all platforms Instant will try to use an OS API that guarantees monotonic behavior if available, which is the case for all tier 1 platforms. In practice such guarantees are – under rare circumstances – broken by hardware, virtualization or operating system bugs.
What does steady_time
's implementation offer above what std::time::Instant
does?
For reference - the unix
implementation:
Digging further down this rabbit hole because this if the first that I've encountered it.
Based on the stackoverflow discussion Does Rust have a steady clock, Rust's Instant
and steady_time
in c++
are equivalent on rust's tier 1 systems.
However, a big caveat is that CLOCK_MONOTONIC
operates differently depending on the platform. On Linux and FreeBSD, it does not include time that the machine was suspended. On Darwin and OpenBSD, it does include time suspended.
This comment on rust's github summarizes the semantics of the different clocks available on the different platforms.
I am a novice to the robot domain, so I don't know how important that caveat is. If it is, someone published an Instant
crate that unifies the semantics between the different platforms to always include suspended time - announced in that same rust-lang thread.
Thank you for reporting.
We do not routinely test on Windows, so this was released by accident.
The latest master
branch changes the steady_time
implementation to be a wrapper around std::time::Instant
. This should be more portable, as noted in the comments above. As a downside, we lose the ability to convert between steady_time::Time
and other representations, as Instant
is opaque.
Please check if this works for you and report the result here.
Version 0.7.1 also contains the fix.
I can confirm that this is fixed. Thanks a lot for the quick fix & release!