Skip to content

[Proposal] Bindgen for multiple versions of a given library enabled through feature gating. #3185

Open
@Narsil

Description

@Narsil

Hi

For https://github.com/coreylowman/cudarc there was a need to support multiple versions of cuda C library.

Here cuda 11.4 .. cuda 12.8 for instance. This was done previously by generating a binding for each library, and manually import various files with feature flags.

In this PR: coreylowman/cudarc#366 I implemented something that would take various bindgen created binding files, and fuse them into a single file where every symbol is marked with the feature gating which vastly reduces the amount of code generated in the end.

While writing it, I thought maybe it could become something useful more generally for the bindgen community since I took quite a bit of code from bindgen to write it.

Do you think it's something interesting ?
I could try to look up how to implement if there's enough interest.

For a for visual show:

From

#[cfg(feature = "v1.0.0")]
mod v100{
     pub mysymbol;
}

#[cfg(feature = "v1.1.0")]
mod v110{
     pub mysymbol;
     pub myothersymbol;
}

To

// Feature flag elided since every version has this symbol
pub mysymbol;
#[cfg(any(feature = "v1.0.0"))]
pub myothersymbol;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions