rust-lang / rust-lang/rust-bindgen

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

Open
#3,185 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

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: https://github.com/coreylowman/cudarc/pull/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;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the linked cudarc pull request #366 and the bindgen code it reused; no repository file or test is named in this proposal. Define the scope and integration point for combining bindings from multiple library versions, with feature-gated symbols and reduced generated output as the completion criteria.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.