Skip to content

if both override_abi and wrap_static_fns are used, targetting macos, wrap_static_fns does not work #3155

New issue

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

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

Already on GitHub? # to your account

Open
usamoi opened this issue Feb 25, 2025 · 0 comments · May be fixed by #3156
Open

Comments

@usamoi
Copy link
Contributor

usamoi commented Feb 25, 2025

use std::error::Error;

fn f(target: &str) -> Result<(), Box<dyn Error>> {
    let bindings = bindgen::Builder::default()
        .clang_arg(format!("--target={target}"))
        .header_contents("embed.h", "static inline int hack() { return 0; }")
        .override_abi(bindgen::Abi::CUnwind, "hack")
        .wrap_static_fns(true)
        .wrap_static_fns_path(format!("wrap_{target}"))
        .generate()?;
    println!("/* binding for {target} */");
    println!("{}", bindings);
    Ok(())
}

fn main() -> Result<(), Box<dyn Error>> {
    f("x86_64-linux-gnu")?;
    f("aarch64-linux-gnu")?;
    f("x86_64-apple-macos")?;
    f("aarch64-apple-macos")?;
    f("x86_64-pc-windows-msvc")?;
    f("aarch64-pc-windows-msvc")?;
    Ok(())
}

Expected to see 6 files are generated. However, only 4 files (wrap_x86_64-linux-gnu.c, wrap_aarch64-linux-gnu.c, wrap_x86_64-pc-windows-msvc.c, wrap_aarch64-pc-windows-msvc.c) are generated.

If .override_abi(bindgen::Abi::CUnwind, "hack") is removed, all 6 files are generated.

The output of this code:

/* binding for x86_64-linux-gnu */
/* automatically generated by rust-bindgen 0.71.1 */

unsafe extern "C-unwind" {
    #[link_name = "hack__extern"]
    pub fn hack() -> ::std::os::raw::c_int;
}

/* binding for aarch64-linux-gnu */
/* automatically generated by rust-bindgen 0.71.1 */

unsafe extern "C-unwind" {
    #[link_name = "hack__extern"]
    pub fn hack() -> ::std::os::raw::c_int;
}

/* binding for x86_64-apple-macos */
/* automatically generated by rust-bindgen 0.71.1 */

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

/* binding for aarch64-apple-macos */
/* automatically generated by rust-bindgen 0.71.1 */

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

/* binding for x86_64-pc-windows-msvc */
/* automatically generated by rust-bindgen 0.71.1 */

unsafe extern "C-unwind" {
    #[link_name = "hack__extern"]
    pub fn hack() -> ::std::os::raw::c_int;
}

/* binding for aarch64-pc-windows-msvc */
/* automatically generated by rust-bindgen 0.71.1 */

unsafe extern "C-unwind" {
    #[link_name = "hack__extern"]
    pub fn hack() -> ::std::os::raw::c_int;
}
@usamoi usamoi changed the title if override_abi and wrap_static_fns are used, wrap_static_fns does not work targetting macos if both override_abi and wrap_static_fns are used, targetting macos, wrap_static_fns does not work Feb 25, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant