Skip to content

Conversation

emilio
Copy link
Contributor

@emilio emilio commented Nov 28, 2018

No description provided.

@jethrogb
Copy link
Contributor

jethrogb commented Nov 28, 2018

Cool, looks good, except for #1221 (comment)

Mini-repro:

# Cargo.toml
[package]
name = "bgtest"
version = "0.1.0"

[dependencies]
bindgen = { git = "https://github.com/emilio/rust-bindgen/", branch = "whitelist-name" }
// src/main.rs
extern crate bindgen;

#[derive(Debug)]
struct ParseCallbacks {}

impl bindgen::callbacks::ParseCallbacks for ParseCallbacks {
    fn item_name(&self, original_item_name: &str) -> Option<String> {
        if original_item_name.starts_with("prefix_") {
            Some(original_item_name.trim_start_matches("prefix_").to_string())
        } else {
            None
        }
    }
}


fn main() {
    let bindings = bindgen::builder()
        .header_contents("test.h", "int prefix_testfn();")
        .parse_callbacks(Box::new(ParseCallbacks{}))
        .whitelist_function("(?i)prefix_.*")
        .trust_clang_mangling(false)
        .generate()
        .expect("bindgen error");

    bindings.write(Box::new(std::io::stdout())).unwrap();
}

Output:

/* automatically generated by rust-bindgen */

extern "C" {
    #[link_name = "\u{1}prefix_testfn"]
    pub fn testfn() -> ::std::os::raw::c_int;
}

@emilio
Copy link
Contributor Author

emilio commented Nov 30, 2018

Added a test for this.

@emilio emilio merged commit 33912cf into rust-lang:master Nov 30, 2018
@emilio emilio deleted the whitelist-name branch November 30, 2018 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants