immunant / c2rust

Migrate C code to Rust
https://c2rust.com/
Other
4.01k stars 241 forks source link

Make `tinycbor` dependency build offline #471

Open kkysen opened 2 years ago

kkysen commented 2 years ago

Building tinycbor by downloading it in cmake causes many issues:

We should figure out how to build it offline or switch to a solution that can be.

kkysen commented 2 years ago

Could we instead wrap a Rust cbor crate with C bindings and use that from c2rust-ast-exporter? That way cargo handles all the dependencies and we use the same codebase for encoding and decoding cbor. Speaking of that, serde_cbor that we use is now archived and no longer maintained. Maybe we should switch to something like minicbor, which serde_cbor recommends and it also has a lot of downloads.

@milahu, let's discuss cbor stuff here.

kkysen commented 2 years ago

We just use these functions:

cbor_encode_boolean
cbor_encode_byte_string
cbor_encode_double
cbor_encode_int
cbor_encode_null
cbor_encoder_close_container
cbor_encoder_create_array
cbor_encoder_get_buffer_size
cbor_encoder_get_extra_bytes_needed
cbor_encoder_init
cbor_encode_string
cbor_encode_string_array
cbor_encode_text_string
cbor_encode_text_stringz
cbor_encode_uint

and minicbor::encode::Encode has all the equivalent methods.

thedataking commented 2 years ago

@kkysen Nix support and offline builds are not something we're committed to. Unless, minicbor offers a C/C++ API, I'm not sure it is a good replacement. Would adding tinycbor as a git submodule work? Let's discuss before you move ahead with this.

kkysen commented 2 years ago

Making tinycbor a git submodule might work (https://github.com/immunant/c2rust/issues/470#issuecomment-1172257062). But I don't think creating C bindings for minicbor, specifically the type-specific ones in minicbor::encode::Encode<Vec<u8>> to match exactly the ones we use listed above, would be that hard. This comes with a few extra benefits as well:

I think if making tinycbor a git submodule is easy and makes offline builds work, we can do that first as it'd probably be faster, but I think the minicbor bindings route is the better one, and if the git submodule doesn't work well we should do that instead (I haven't had the best experiences with git submodules in the past).