-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extending time_t to u64 (c_longlong) #110
Comments
Just occurred to my mind that we can have Option 2 and Option 3 together too. |
I like option 2 & 3 together, provided the libc maintainers will allow us that cfg flag. I think most people (excluding us) generally pick a idf version and stick with it. It seems like upgrading to V5 from V4 wouldn't need to change the cargo config, as the cfg would essentially become a no-op, so it would be safe to leave it in there? I suppose that depends on how the feature is implemented in libc though.
|
Sorry, missed this when it was first posted. I think we're probably all in agreement here, options 2 & 3 seem like the best path forward to me as well. Don't really have much else to add that hasn't already been said. |
Not really. Assuming only Option 2 is implemented: Basically the flag is a workaround for the fact that libc cannot really "talk" to Now, with Option 3 it is a bit easier:
|
@igrr ^^^ |
FYI This was recently accepted, so I would imagine we can extend it for the espidf usecase. |
Yep, I saw that 'if' already. We would instead be if-ing on an arbitrary cfg flag, which is not part of the information the compilation target carries with it:
My hope is that because the examination of that flag will be constrained only for the case when the OS is "espidf", it might actually be accepted. |
By the way, when is this change coming to ESP-IDF V5? |
@igrr ^^^. Was this change released for ESP-IDF 5 or not? |
@ivmarkov IDF v5.0 hasn't been released yet, but the |
@igrr Thanks, that's all I needed to know. This means, we have to upstream in Rust |
From the meeting, we made the preliminary decision to use the The default behavior will be to opt-in to 64bit time, this is to not break v4.4 users. In two years we may wish to flip the meaning or add a new flag for opting-out of 64bit time when v4.4 is deprecated and v5.0 becomes the default. Crates that require modification:
|
Compatibility with ESP-IDF V5 The new major release of the ESP-IDF (V5) has extended the `time_t` type from 32 to 64 bits. Unfortunately, this brings the challenge how to simultaneously support older ESP-IDF releases (current stable is V4.4.2) and the V5 one with the `libc` (and Rust STD) crates. After dismissing the option to introduce 5 (or more) additional ESP-IDF targets, [we settled on the introduction of a `rustc` cfg flag, as the most lightweight option](esp-rs/rust#110 (comment)): `espidf_time64`: * This flag needs to be enabled by the user for ESP-IDF V5 (for example, by setting it in the `[build]` section of `.config/cargo.toml` or using one of the other methods to pass flags to the Rust compiler); * This flag should not be set by the user for earlier ESP-IDF versions (we might reverse the logic once ESP-IDF V5 becomes more main-stream in future). The good news in all that is that it is *impossible for the user to set the flag to the wrong value* as his/her build will simply fail. This is because compiling for the ESP-IDF framework does require a *hard dependency* on the `esp-idf-sys` crate, which - besides exposing autogenerated (with bindgen) APIs which are a super-set of the `libc` APIs - also does the heavy-lifting of compiling the ESP-IDF framework itself and emitting the relevant Rust linker flags and a lot of other things. So when compiling `esp-idf-sys`, [we are checking the compatibility of the libc's `type_t` with the bindgen-ed one inside `esp-idf-sys`](https://github.com/esp-rs/esp-idf-sys/blob/master/src/lib.rs#L33) where the latter is the source of truth, so to say.
With rust-lang/libc#2913 merged, I believe we can now close this. |
As per information from @igrr , ESP-IDF 5.0 will soon extend the
time_t
type from 32 to 64 bits.The
esp-idf-*
crates can handle this transparently, as they have full access to the ESP-IDF environment.The situation is not so rosy with our Rust STD support, which relies on manually-defined types in the Rust libc crate:
(In particular, the
time_t
type for newlib is defined here).I was only able to come up with three ways to model this:
Option 1: Introduce new ESP-IDF targets for ESP-IDF 5. I.e.:
riscv32imc-esp-espidf5
in addition toriscv32imc-esp-espidf
xtensa-esp-espidf5
in addition toxtensa-esp-espidf
xtensa-esps2-espidf5
in addition toxtensa-esps2-espidf
xtensa-esps3-espidf5
in addition toxtensa-esps3-espidf
#[cfg(os_target = "esp-idf")]
, we still need - in the*-espidf5
targets - to report asos_target
esp-idf
and then use another target property to differentiate between ESP-IDF5 and earlier. I'm thinking - as terrible as it sounds - to (ab)use the currently unusedvendor
property and have it defined toespressif
for ESP-IDF 4, andespressif-espidf5
in the targets that are suffixed-espidf5
.*-espidf4
targets which would haveespressif-espidf4
asvendor
propertyOption 2: Rely on the user setting a Rustc flag in
.cargo/config.toml
#[cfg(all(target_os = "esp-idf", "esp-idf-long-time-t"))]
xtensa-esp-espidf
toxtensa-esp-espidf5
Note also that for both Option 1 and Option 2 users might try to compile with e.g. 5.X ESP-IDF and 4.x target (or - if Option 2 is used - with 5.X ESP-IDF and the
rustflags = ["--cfg", "esp-idf-long-time-t"]
commented out). However, this has an easy workaround in thatesp-idf-sys
(which they need to compile anyway too) can detect that it is being compiled with 5.X ESP-IDF yet what libc returns is a 32 bittime_t
and abort the compilation with a suggestion "Please addrustflags = ["--cfg", "esp-idf-long-time-t"]
to your.config/cargo.toml
file. And of course the other way around.time_t
is 32 bit. We would use this mode in Rust. Once ESP-IDF5 becomes ubiquitous, we will drop support for ESP-IDF 4.X in Rust and we'll just switch to the 64 bittime_t
.My order of preference:
@MabezDev @jessebraham ^^^
The text was updated successfully, but these errors were encountered: