Description
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
- Now, to minimize the upstream changes in Rust STD which are branching by
#[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
. - Note that we can have ^^^ all of the above the other way around too: current targets become compatible with ESP-IDF 5, and for backwards compatibility with earlier ESP-IDF targets we can introduce
*-espidf4
targets which would haveespressif-espidf4
asvendor
property
-
Option 2: Rely on the user setting a Rustc flag in
.cargo/config.toml
- I.e. something like
[build] rustflags = ["--cfg", "esp-idf-long-time-t"]
- The fix in the rust libc crate can then do an additional branching by
#[cfg(all(target_os = "esp-idf", "esp-idf-long-time-t"))]
- Problem 1 with that approach is I'm not sure libc maintainers will accept that - but doesn't hurt if we try
- Problem 2 is that if users are switching from ESP-IDF 4.X to ESP-IDF 5 branch or vice versa, they have to comment/uncomment this flag. Note however that this is not much different from asking them to switch to another target (i.e. from
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 that esp-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 bit time_t
and abort the compilation with a suggestion "Please add rustflags = ["--cfg", "esp-idf-long-time-t"]
to your .config/cargo.toml
file. And of course the other way around.
- Option 3: Maintain backwards-compatibility mode for compiling ESP-IDF 5 where
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:
- Option 3 (obviously)
- Option 2
- Option 1