Steamworks SDK bindgen inline function

Hey,

I am currently working on a small project with the latest version of the Steamworks SDK, v1.58. In order to use the SDK properly, I am generating Rust bindings using bindgen which works fine except for a couple functions that are defined as inline.

// sdk/public/steam/steam_api.h

[...]

inline bool SteamAPI_Init() {
    return SteamAPI_InitEx( NULL ) == k_ESteamAPIInitResult_OK;
}

[...]

Since I am not compiling the C++ code myself, using generate_inline_functions on the bindgen builder won't work in this instance.

My current workaround for this issue is to write my own C++ code that wraps the inline functions, which I then compile using cc.

// interop.cpp

#include "sdk/public/steam/steam_api.h"

extern "C" {
    bool init() { return SteamAPI_Init(); }
}
// build.rs

[...]

Build::new()
    .cpp(true)
    .file("interop.cpp")
    .include("sdk/public/steam")
    .compile("interop");

[...]
// main.rs

extern "C" {
    fn init() -> bool;
}

fn main() {
    unsafe {
        let res = init();
    }
}

Is there another preferred or correct way to solve this that I may be missing?

Thanks!

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.