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

derive_debug(false) still derives Debug for rustified Enum #1899

Closed
trinity-1686a opened this issue Oct 13, 2020 · 1 comment · Fixed by #1900
Closed

derive_debug(false) still derives Debug for rustified Enum #1899

trinity-1686a opened this issue Oct 13, 2020 · 1 comment · Fixed by #1900

Comments

@trinity-1686a
Copy link

trinity-1686a commented Oct 13, 2020

Input C/C++ Header

enum boolean { false, true };

Bindgen Invocation

bindgen::Builder::default()
        .header("wrapper.h")
        .default_enum_style(bindgen::EnumVariation::Rust{ non_exhaustive: false })
        .derive_debug(false)
        .impl_debug(false)
        .no_debug(".*")
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        .generate()
        .expect("Unable to generate bindings")
        .write_to_file(out_path.join("bindings.rs"))
        .expect("Couldn't write bindings!");

Actual Results

/* automatically generated by rust-bindgen 0.55.1 */

#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum boolean {
    false_ = 0,
    true_ = 1,
}

Expected Results

#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq, Hash)] // <= no Debug
pub enum boolean {
    false_ = 0,
    true_ = 1,
}

Use case :

I'm trying to build some bpf program to run inside Linux kernel. It's pretty restrictive on what is allowed, and apparently having Debug implemented break something related to the "only one ELF section" rule (pretty much anything related to strings does).
I tried as hard as I could to tell Bindgen to not derive/generate Debug, but apparently it still does for enumerations. Stripping off all derive Debug fixes loading the program, but I feel like derive_debug(false) or no_debug(".*") should already have done that.

@trinity-1686a trinity-1686a changed the title derived_debug(false) still derives Debug for rustified Enum derive_debug(false) still derives Debug for rustified Enum Oct 13, 2020
emilio added a commit that referenced this issue Oct 13, 2020
Fixes #1899.

This code predated all the derive machinery, and always hardcoded its
derives.

We could avoid hard-coding the other traits, but those seem
usually-useful, so leave them there for backwards compat for now.
@emilio
Copy link
Contributor

emilio commented Oct 13, 2020

Fix at #1900, thanks for filing it!

emilio added a commit that referenced this issue Oct 13, 2020
Fixes #1899.

This code predated all the derive machinery, and always hardcoded its
derives.

We could avoid hard-coding the other traits, but those seem
usually-useful, so leave them there for backwards compat for now.
emilio added a commit that referenced this issue Oct 16, 2020
Fixes #1899.

This code predated all the derive machinery, and always hardcoded its
derives.

We could avoid hard-coding the other traits, but those seem
usually-useful, so leave them there for backwards compat for now.
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 a pull request may close this issue.

2 participants