Comments (3)
Could you create a reduced test-case? I suspect something weird is going on, because bindgen padding looks like pub __bindgen_padding_0: ...
.
from rust-bindgen.
Or like, something that I can run locally at least :)
from rust-bindgen.
Sure, here is an example:
# Cargo.toml
[package]
name = "buggy-crate"
version = "0.1.0"
edition = "2021"
[build-dependencies]
bindgen = "0.69.4"
pkg-config = "0.3.30"
// build.rs
use std::{env, iter, path::PathBuf};
pub static FUSE_VERSION: u32 = 316;
pub static FUSE_LIBNAME: &str = "fuse3";
fn fuse_binding_filter(builder: bindgen::Builder) -> bindgen::Builder {
let mut builder = builder
// Whitelist "fuse_*" symbols and blocklist everything else
.allowlist_recursively(false)
.allowlist_type("[fF][uU][sS][eE].*")
.allowlist_function("[fF][uU][sS][eE].*")
.allowlist_var("[fF][uU][sS][eE].*")
.blocklist_type("fuse_log_func_t")
.blocklist_function("fuse_set_log_func");
// TODO: properly bind fuse_log_func_t and allowlist fuse_set_log_func again
if cfg!(target_os = "macos") {
// osxfuse needs this type
builder = builder.allowlist_type("setattr_x");
}
builder
}
fn cuse_binding_filter(builder: bindgen::Builder) -> bindgen::Builder {
builder
// Whitelist "cuse_*" symbols and blocklist everything else
.allowlist_recursively(false)
.allowlist_type("[cC][uU][sS][eE].*")
.allowlist_function("[cC][uU][sS][eE].*")
.allowlist_var("[cC][uU][sS][eE].*")
}
fn generate_fuse_bindings(
header: &str,
fuse_lib: &pkg_config::Library,
binding_filter: fn(bindgen::Builder) -> bindgen::Builder,
) {
// Find header file
let mut header_path: Option<PathBuf> = None;
for include_path in fuse_lib.include_paths.iter() {
let test_path = include_path.join(header);
if test_path.exists() {
header_path = Some(test_path);
break;
}
}
let header_path = header_path
.unwrap_or_else(|| panic!("Cannot find {}", header))
.to_str()
.unwrap_or_else(|| panic!("Path to {} contains invalid unicode characters", header))
.to_string();
// Gather fuse defines
let defines = fuse_lib.defines.iter().map(|(key, val)| match val {
Some(val) => format!("-D{}={}", key, val),
None => format!("-D{}", key),
});
// Gather include paths
let includes = fuse_lib
.include_paths
.iter()
.map(|dir| format!("-I{}", dir.display()));
// API version definition
let api_define = iter::once(format!("-DFUSE_USE_VERSION={FUSE_VERSION}"));
// Chain compile flags
let compile_flags = defines.chain(includes).chain(api_define);
// Create bindgen builder
let mut builder = bindgen::builder()
// Add clang flags
.clang_args(compile_flags)
// Derive Debug, Copy and Default
.derive_default(true)
.derive_copy(true)
.derive_debug(true)
// Add CargoCallbacks so build.rs is rerun on header changes
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()));
builder = binding_filter(builder);
// Generate bindings
let bindings = builder
.header(header_path)
.generate()
.unwrap_or_else(|_| panic!("Failed to generate {} bindings", header));
// Write bindings to file
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let bindings_path = out_dir.join(header.replace(".h", ".rs"));
bindings
.write_to_file(&bindings_path)
.unwrap_or_else(|_| panic!("Failed to write {}", bindings_path.display()));
}
fn main() {
let mut pkgcfg = pkg_config::Config::new();
pkgcfg.cargo_metadata(false);
// Find libfuse
let fuse_lib = pkgcfg
.cargo_metadata(true)
.probe(FUSE_LIBNAME)
.unwrap_or_else(|err| panic!("Failed to find pkg-config module {FUSE_LIBNAME} ({err})"));
// Generate highlevel bindings
generate_fuse_bindings("fuse.h", &fuse_lib, fuse_binding_filter);
// Generate lowlevel bindings
generate_fuse_bindings("fuse_lowlevel.h", &fuse_lib, fuse_binding_filter);
// Generate lowlevel cuse bindings
generate_fuse_bindings("cuse_lowlevel.h", &fuse_lib, cuse_binding_filter);
}
Note: you need to have both pkg-config and libfuse-dev installed.
Run this, and it will generate three bindings files in target
. There you can find many structs with the problem I mentioned.
from rust-bindgen.
Related Issues (20)
- Simplify target conversion further
- UINTMAX64 can never be generated HOT 2
- can not get the non-type template arg?
- allowlist_item does not work for anonymous enums - allowlist_var does HOT 1
- --target=wasm32-unknown-unknown: 'stdio.h' file not found HOT 5
- Unable to generate bindings for Arduino library IRremote.hpp on MacOS HOT 1
- Thread panicking at bindgen .Err state unable to found libclang.dll but it available on the path variable HOT 2
- feature request: Enable deriving `Clone`, `Copy`, etc... for `__IncompleteArrayField` and containing structs. HOT 2
- Support for raw-dylib for Windows
- Support for one set of bindings depending on another (conflicting `__BindgenBitfieldUnit`) HOT 3
- Unable to run bindgen on ubuntu 22.04 HOT 3
- update requirements for OpenBSD HOT 10
- Building tests for LightGBM bindings failes with linker error
- Unable to prevent Clang headers from being used HOT 5
- Update clang-sys HOT 2
- AArch64 Linux va_list not FFI-safe
- "rustified_non_exhaustive_enum" not supported in CLI
- 0.69 introduces issue with constantly rebuilding
- bindgen has bumped MSRV without updating semver HOT 5
- `rewriting static` string in generated bindings HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-bindgen.