rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

wrap_static_fns not generating extern.c when -x c++

Open sehnryr opened this issue 9 months ago • 0 comments

Calling option wrap-static-fns with -x c++ to force C++ mode (this also happens when simply calling bindgen on a .hpp file) (https://rust-lang.github.io/rust-bindgen/cpp.html) fails to create extern.cpp.

Considering this simple test.h file:

static void testing();

Calling bindgen with -x c++ to force C++ mode:

❯ bindgen test.h --wrap-static-fns -- -x c++
/* automatically generated by rust-bindgen 0.71.1 */

unsafe extern "C" {
    #[link_name = "\u{1}_ZL7testingv"]
    pub fn testing();
}

Doesn't generate extern.c at the default path (/tmp/bindgen on unix systems):

❯ cat /tmp/bindgen/extern.cpp 
cat: /tmp/bindgen/extern.cpp: No such file or directory

Here's the default behavior without C++ mode (or .hpp):

❯ bindgen test.h --wrap-static-fns
/* automatically generated by rust-bindgen 0.71.1 */

unsafe extern "C" {
    #[link_name = "testing__extern"]
    pub fn testing();
}

Which does generate the static wrapper:

❯ cat /tmp/bindgen/extern.c
#include "test.h"

// Static wrappers

void testing__extern(void) { testing(); }

sehnryr avatar Feb 25 '25 22:02 sehnryr