Skip to content
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

Add feature flag for deriving serde macros. The default is off. #4

Merged
merged 3 commits into from
Dec 5, 2019

Conversation

skywhale
Copy link
Member

@skywhale skywhale commented Dec 5, 2019

This is a workaround. Ideally bindgen supports adding custom derive macros, esp common ones like serde.

Some discussion here:
rust-lang/rust-bindgen#1089
rust-lang/rust-bindgen#1301

@skywhale skywhale requested a review from mcginty December 5, 2019 07:15
Copy link
Contributor

@mcginty mcginty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice lookin good! few change requests.

.replace_all(&contents, "#[derive($d, PartialEq)] pub struct")
.to_string();

#[cfg(feature = "derive_serde")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if cfg!(feature = "derive_serde") {
    ...
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

File::create(&binding_file)?.write_all(new_binding_contents.as_bytes())?;
// Add PartialEq to structs.
// Used for checking partial equality of `Config` struct.
contents = Regex::new(r"#\s*\[\s*derive\s*\((?P<d>[^)]+)\)\s*\]\s*pub\s*struct")?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe best to add a comment to the bindgen issue that is requesting the ability to inject these types of things directly without regex.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was more relevant issue already existing. I just upvoted a comment there.
rust-lang/rust-bindgen#1089

@skywhale skywhale merged commit d477b45 into master Dec 5, 2019
@skywhale skywhale deleted the derivefeature branch December 5, 2019 07:42
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