rust-lang / rust-lang/rust-bindgen

Bindgen features not additive

Open
#2,030 8 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

If you have two different dependencies that both depend on bindgen, but dependency A uses static linking and dependency B using dynamic linking, this will fail to build.

You can test this easily with the following Cargo.toml:

[dependencies]
bindgen57 = { version = "0.57", package = "bindgen", default-features = false, features = ["static"] }
bindgen58 = { version = "0.58", package = "bindgen", default-features = false, features = ["runtime"] }

Cargo features are supposed to be additive, i.e. one crate in your dependency tree should never fail to build because another crate elsewhere in your dependency tree enables some feature.

There's also a related issue where if you do something like this:

[dependencies]
bindgen57 = { version = "0.57", package = "bindgen", default-features = false }
bindgen58 = { version = "0.58", package = "bindgen", default-features = false, features = ["runtime"] }

This will build, but it will panic at runtime:

thread 'main' panicked at 'a `libclang` shared library is not loaded on this thread', .../.cargo/registry/src/github.com-1ecc6299db9ec823/clang-sys-1.2.0/src/lib.rs:1682:1

See also https://github.com/KyleMayes/clang-rs/issues/146

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 reproducing both dependency combinations from the issue's Cargo.toml examples, including the static/runtime feature combinations. Then inspect bindgen's feature definitions and the related clang-sys behavior referenced in the panic and linked issue. Done means feature combinations remain additive, both dependency versions build, and the runtime panic no longer occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.