Skip to content

Commit

Permalink
Try #12:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Jul 21, 2023
2 parents c4cc86f + 9c8db68 commit 345b3dd
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 19 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ pkg-config = "0.3"
[features]
default = ["fuse_highlevel", "fuse_lowlevel"]

# Generate highlevel bindings
# Generate highlevel fuse bindings
fuse_highlevel = []
# Generate lowlevel bindings
# Generate lowlevel fuse bindings
fuse_lowlevel = []
# Generate lowlevel cuse bindings
cuse_lowlevel = []

# API versions
fuse_11 = []
Expand Down
71 changes: 54 additions & 17 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,39 @@ macro_rules! version {
};
}

fn generate_fuse_bindings(header: &str, api_version: u32, fuse_lib: &pkg_config::Library) {
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("(?i)^fuse.*")
.allowlist_function("(?i)^fuse.*")
.allowlist_var("(?i)^fuse.*")
.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("(?i)^cuse.*")
.allowlist_function("(?i)^cuse.*")
.allowlist_var("(?i)^cuse.*")
}

fn generate_fuse_bindings(
header: &str,
api_version: u32,
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() {
Expand Down Expand Up @@ -59,20 +91,9 @@ fn generate_fuse_bindings(header: &str, api_version: u32, fuse_lib: &pkg_config:
.derive_copy(true)
.derive_debug(true)
// Add CargoCallbacks so build.rs is rerun on header changes
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
// Whitelist "fuse_*" symbols and blocklist everything else
.allowlist_recursively(false)
.allowlist_type("(?i)^fuse.*")
.allowlist_function("(?i)^fuse.*")
.allowlist_var("(?i)^fuse.*")
.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
.parse_callbacks(Box::new(bindgen::CargoCallbacks));

if cfg!(target_os = "macos") {
// osxfuse needs this type
builder = builder.allowlist_type("setattr_x");
}
builder = binding_filter(builder);

// Generate bindings
let bindings = builder
Expand Down Expand Up @@ -116,7 +137,10 @@ fn main() {
let try_fuse_lib = pkg_config::Config::new().probe("fuse");
let try_fuse3_lib = pkg_config::Config::new().probe("fuse3");
let fuse_lib = match (try_fuse_lib, try_fuse3_lib) {
(Err(err), Err(err3)) => panic!("Failed to find pkg-config modules fuse ({}) or fuse3 ({})", err, err3),
(Err(err), Err(err3)) => panic!(
"Failed to find pkg-config modules fuse ({}) or fuse3 ({})",
err, err3
),
(Ok(fuse_lib), Err(_)) => fuse_lib,
(Err(_), Ok(fuse3_lib)) => fuse3_lib,
(Ok(fuse_lib), Ok(fuse3_lib)) => {
Expand All @@ -132,8 +156,21 @@ fn main() {

// Generate highlevel bindings
#[cfg(feature = "fuse_highlevel")]
generate_fuse_bindings("fuse.h", api_version, &fuse_lib);
generate_fuse_bindings("fuse.h", api_version, &fuse_lib, fuse_binding_filter);
// Generate lowlevel bindings
#[cfg(feature = "fuse_lowlevel")]
generate_fuse_bindings("fuse_lowlevel.h", api_version, &fuse_lib);
generate_fuse_bindings(
"fuse_lowlevel.h",
api_version,
&fuse_lib,
fuse_binding_filter,
);
// Generate lowlevel cuse bindings
#[cfg(feature = "cuse_lowlevel")]
generate_fuse_bindings(
"cuse_lowlevel.h",
api_version,
&fuse_lib,
cuse_binding_filter,
);
}
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,12 @@ pub mod fuse_lowlevel {
use super::*;
include!(concat!(env!("OUT_DIR"), "/fuse_lowlevel.rs"));
}

#[cfg(feature = "cuse_lowlevel")]
pub mod cuse_lowlevel {
use super::*;
use fuse_lowlevel::{
fuse_args, fuse_conn_info, fuse_file_info, fuse_pollhandle, fuse_req_t, fuse_session,
};
include!(concat!(env!("OUT_DIR"), "/cuse_lowlevel.rs"));
}

0 comments on commit 345b3dd

Please sign in to comment.