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

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

Closed
scovich opened this issue May 1, 2024 · 6 comments
Closed

Comments

@scovich
Copy link
Contributor

scovich commented May 1, 2024

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.

@emilio
Copy link
Collaborator

emilio commented May 1, 2024

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

@emilio
Copy link
Collaborator

emilio commented May 1, 2024

Triple slash that is, sorry.

@scovich
Copy link
Contributor Author

scovich commented May 2, 2024

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?

@scovich
Copy link
Contributor Author

scovich commented May 2, 2024

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)

@scovich
Copy link
Contributor Author

scovich commented May 2, 2024

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.

@emilio
Copy link
Collaborator

emilio commented May 7, 2024

Fixed by #949.

@emilio emilio closed this as completed May 7, 2024
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

No branches or pull requests

2 participants