Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a config that not pub out the func variable in struct when using dynamic loading? #2971

Open
Ferry-200 opened this issue Nov 2, 2024 · 1 comment

Comments

@Ferry-200
Copy link

I'm using bindgen to generate un4seen's BASS lib binding. Here is my build.rs:

let bindings = bindgen::Builder::default()
        // The input header we would like to generate
        // bindings for.
        .header("BASS/bass.h")
        .dynamic_library_name("Bass")
        // Tell cargo to invalidate the built crate whenever any of the
        // included header files changed.
        .parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
        .allowlist_item("BASS_.*")
        // Finish the builder and generate the bindings.
        .generate()
        // Unwrap the Result and panic on failure.
        .expect("Unable to generate bindings");

    // Write the bindings to the $OUT_DIR/bindings.rs file.
    let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
    bindings
        .write_to_file(out_path.join("bass.rs"))
        .expect("Couldn't write bindings!");

It will generate the bass.rs file contains:

pub struct Bass {
    __library: ::libloading::Library,
    pub BASS_Init: Result<
        unsafe extern "C" fn(
            device: ::std::os::raw::c_int,
            freq: DWORD,
            flags: DWORD,
            win: HWND,
            dsguid: *const ::std::os::raw::c_void,
        ) -> BOOL,
        ::libloading::Error,
    >,
}

impl Bass {
pub unsafe fn BASS_Init(
        &self,
        device: ::std::os::raw::c_int,
        freq: DWORD,
        flags: DWORD,
        win: HWND,
        dsguid: *const ::std::os::raw::c_void,
    ) -> BOOL {
        (self
            .BASS_Init
            .as_ref()
            .expect("Expected function, got error."))(device, freq, flags, win, dsguid)
    }
}

The variable BASS_Init and function BASS_Init has the same name, which bring some trouble in codeing. For example, when I type BASS_Ini and the vscode will advise me with both variable and func.
Image

Any helps? Thanks!

@pvdrz
Copy link
Contributor

pvdrz commented Nov 11, 2024

There isn't but it shouldn't be to difficult to add (famous last words)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants