如何根据目标操作系统更改功能ABI?

时间:2018-06-13 07:15:29

标签: rust abi

我正在Rust中编写一个跨平台库,我需要为Windows和Unix使用特定的ABI字符串。我目前的解决方案是:

#[macro_export]
macro_rules! create_plugin {
    (@internal $name:ident) => {
        #[no_mangle]
        #[cfg(target_os = "windows")]
        pub unsafe extern "stdcall" fn Test(data: *const *const u32) -> bool {
            // Source 1
        }

        #[no_mangle]
        #[cfg(not(target_os = "windows"))]
        pub unsafe extern "C" fn Test(data: *const *const u32) -> bool {
            // Source 1 (duplicate)
        }
    }

    // ...
}

有没有办法减少定义中的复制粘贴代码?

0 个答案:

没有答案