Skip to content

Auto-generate reverse mappings for rd_kafka_resp_err_t #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2019

Conversation

igozali
Copy link
Contributor

@igozali igozali commented Dec 11, 2019

Wanted to see if you'd be interested in this?

The idea is so that we don't have to manually update helpers.rs. Moving the bindgen logic to build.rs would also allow us to generate the bindings as part of the cargo build process.

@benesch
Copy link
Collaborator

benesch commented Dec 11, 2019

Hi @igozali, thanks very much for the PR. Unfortunately I just recently switched us back to manually running bindgen (1c7a58c), as running it during compile time requires users to have libclang installed, which is problematic for more than a few folks.

The enum stuff looks interesting! Could we use num_enum instead of rolling our own support, though?

@igozali
Copy link
Contributor Author

igozali commented Dec 11, 2019

Oh, I see, good to know, and oops, didn't know about num_enum 🤦‍♂ Was quite fun learning about procedural macros, though.

Without bindgen inside build.rs, I wasn't able to figure out how to add an additional trait to derive from for rd_kafka_resp_err_t using bindgen (which we seem to need even if we use num_enum). Actually, even my solution right now using str::replace is totally a hack. Do you have any thoughts on this? Otherwise it'd be a sed somewhere in update_bindings.sh probably.

@igozali igozali force-pushed the error-enum-proc-macro branch from 04bb75f to 0ebbc84 Compare December 11, 2019 08:00
@igozali igozali changed the title Move bindgen to build.rs + auto-generate reverse mappings for rd_kafka_resp_err_t Auto-generate reverse mappings for rd_kafka_resp_err_t Dec 11, 2019
@benesch benesch force-pushed the error-enum-proc-macro branch from 0ebbc84 to c1af7e0 Compare December 11, 2019 17:02
@benesch
Copy link
Collaborator

benesch commented Dec 11, 2019

This is great, thanks! Merged with some minor modifications to elide the now-unnecessary primitive_to_rd_kafka_resp_err_t function entirely.

@benesch benesch merged commit 68d12d6 into fede1024:master Dec 11, 2019
@benesch
Copy link
Collaborator

benesch commented Dec 11, 2019

And yeah, unfortunately there is presently no way to ask bindgen to derive nonstandard traits for the types, so we're stuck with regex mashing. Oh well. There's an open bindgen issue about it, so perhaps it gets fixed eventually: rust-lang/rust-bindgen#1097

@igozali
Copy link
Contributor Author

igozali commented Dec 11, 2019

Sweet, also I like that perl version of regex mashing better 😃

@igozali igozali deleted the error-enum-proc-macro branch December 11, 2019 19:12
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