Skip to content

Conversation

@smaeul
Copy link

@smaeul smaeul commented Nov 15, 2025

I'd like to use this library in a no_std environment (embassy on esp32), so here's an attempt at getting it to build. It at least builds for the target platform, and I can run cargo test --no-default-features on my desktop. extensions::meta_ext is compiled out, because changing it from std::collections::HashMap would affect the API, and I don't currently need that module.

I'm marking this as a draft because it depends on a speedate release containing pydantic/speedate#96. I'm happy to adjust anything as needed.

It was only used in one place, and since it may conflict with other
logging frameworks (e.g. defmt), it likely should be gated behind a
feature.
This is the same hash algorithm as used by std::collections::hash_map
aka hashbrown, but configured with a fixed seed to remove the dependency
on the OS RNG (and thus std). The seed is unimportant because we do not
rely on any security properties of the hash function.
In addition to being no_std friendly, this significantly reduces code
size. speedate also has a faster/smaller DateTime parser compared to
chrono, but speedate's parser only supports microsecond precision.
The std functions and types are aliases of the ones from core, so this
causes no functional change.
Barring the few exceptions covered in the following commits, the library
doesn't depend on anything in std itself, only String/Vec/collections
re-exported from alloc. So supporting no_std mostly requires switching
the imports over to alloc, and ensuring dependencies do not pull in any
features that depend on std.
std::collections::HashMap has no equivalent in alloc.
The equivalent function is available on recent rustc versions behind an
unstable feature, but is not part of the f64 impl. Use a wrapper trait
to provide the function on no_std without affecting the std build.
@smaeul smaeul marked this pull request as draft November 15, 2025 07:42
@schaze
Copy link
Owner

schaze commented Nov 15, 2025

Hi @smaeul, thanks for the PR!
While I am not opposed to the idea of nostd support, I will need some time to evaluate and test this as it is quite an extensive change and I am not sure what the implications might be.

Please allow me the question: Why do need nostd for embassy on esp32? Is it a limited device? I do have a small esp32 project (BLE Keyboard emulator exposed via homie) that also uses embassy but with std. It works just fine.

@smaeul
Copy link
Author

smaeul commented Nov 15, 2025

While I am not opposed to the idea of nostd support, I will need some time to evaluate and test this as it is quite an extensive change and I am not sure what the implications might be.

Sure, no worries! There's no hurry.

Please allow me the question: Why do need nostd for embassy on esp32? Is it a limited device? I do have a small esp32 project (BLE Keyboard emulator exposed via homie) that also uses embassy but with std. It works just fine.

I'm assuming you use tokio + rumqttc on top of esp-idf-svc? Do you use TLS?

It's a combination of a few factors:

  1. esp-hal is officially supported, while esp-idf-hal/esp-idf-svc is not.
  2. ESP-IDF takes up a large portion of RAM/flash on small chips (ESP32-C3), and has limited support for conditional compilation/linking where it matters. Even if I want to use a safe rust TLS/TCP/IP stack, I must also have a copy of mbedtls and LWIP in the binary as well.
  3. I have some hardware that is supported by neither esp-idf-svc nor esp-hal (ESP32-P4), and I'd rather help implement support in the pure rust HAL than the HAL that wraps lots of unsafe C.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants