SoftbearStudios / bitcode

A binary encoder/decoder for Rust
https://crates.io/crates/bitcode/
MIT License
369 stars 19 forks source link

Add #![no_std] compatibility #26

Closed poshcoe closed 6 months ago

poshcoe commented 6 months ago

Adds #![no_std] (with alloc) compatibility by introducing a "std" cargo feature.

I'm interested in evaluating bitcode for embedded applications. I found adding support relatively painless, most of the changes are swapping use std::* for use::core::*, and adding explicit use of alloc.

Notable changes:

cargo +nightly bench bench_pack:

Screenshot_20240419_104158

cargo +nightly bench bench_unpack_u:

Screenshot_20240419_124131

At a glance the performance impact is minimal, resulting in a < 1% average performance deficit on both pack and unpack without std.

It remains to be seen if bitcode performs well on no_std target architectures. I'll likely be testing this in the near future.

finnbear commented 6 months ago

Thanks for the PR! LGTM. In the interest of not inadvertently breaking #![no_std] in the future, is it possible to add a GitHub Actions job that runs a subset of the tests?

poshcoe commented 6 months ago

In the interest of not inadvertently breaking #![no_std] in the future, is it possible to add a GitHub Actions job that runs a subset of the tests?

Sure, I'll tack it on along with fixes for the lints

poshcoe commented 6 months ago

I also took the chance to enable compat of the "serde", "glam" and "arrayvec" features with #![no_std].

The new test therefore enables --features derive,serde,glam,arrayvec

caibear commented 6 months ago

Build is failing because cargo fmt's output changed between nightly-2023-04-25 and your rust version.

caibear commented 6 months ago

Ok, I've fixed the issues I noticed.

poshcoe commented 6 months ago

thanks!