mozilla / cbindgen

A project for generating C bindings from Rust code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cbindgen emits constants in spite of no-export and/or ignore annotations

scovich opened this issue · comments

For the following rust code:

// cbindgen:ignore
// cbindgen:no-export
pub struct Foo;

// cbindgen:ignore
// cbindgen:no-export
impl Foo {
    // cbindgen:ignore
    // cbindgen:no-export
    pub const BAR: i64 = 42;
}

cbindgen still emits the following header code:

constexpr static const int64_t Foo_BAR = 42;

I haven't found any combination of annotations that can suppress it, even tho the docs suggest it should work?

For ignore:

You can manually ignore other stuff with the ignore annotation attribute

For no-export:

cbindgen will usually emit all items it finds, as instructed by the parse and export config sections. This annotation will make cbindgen skip this item from the output, while still being aware of it.

I think you need to use triple-dash, otherwise the comment isn't preserved by syn

Triple slash that is, sorry.

This still emits:

pub struct Foo;

impl Foo {
    /// cbindgen:ignore
    /// cbindgen:no-export
    pub const BAR: i64 = 42;
}

This suppresses it (along with everything else inside the impl Foo block):

pub struct Foo;

/// cbindgen:ignore
/// cbindgen:no-export
impl Foo {
    pub const BAR: i64 = 42;
}

So it still seems like the annotations don't affect constants -- only the surrounding struct impl?

Starting exploring in #949

It turns out /// cbindgen:XXX annotations don't affect anything inside a struct impl block -- in fact, they're not even parsed (verified by inserting a panic! at the NameValue "doc" case of is_skip_item_attr)

I was able to find and add the missing should_skip_parsing calls (#949), which fixes the cbindgen:ignore case. Still looking for the code that processes cbindgen:no-export, tho.