Skip to content

Extending time_t to u64 (c_longlong) #110

Closed
@ivmarkov

Description

@ivmarkov

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 to riscv32imc-esp-espidf
    • xtensa-esp-espidf5 in addition to xtensa-esp-espidf
    • xtensa-esps2-espidf5 in addition to xtensa-esps2-espidf
    • xtensa-esps3-espidf5 in addition to xtensa-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 as os_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 unused vendor property and have it defined to espressif for ESP-IDF 4, and espressif-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 have espressif-espidf4 as vendor 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 to xtensa-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 bit time_t.

My order of preference:

  • Option 3 (obviously)
  • Option 2
  • Option 1

@MabezDev @jessebraham ^^^

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions