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

Use provided my_api_guard() function to generate bindings instead of assuming just inventory hash #91

Open
kevin-cgc opened this issue Jun 22, 2023 · 2 comments
Labels
c-core Interoptopus Core Crate c-proc Proc Macros

Comments

@kevin-cgc
Copy link

I wanted to bump my api version after some internal bugfixes (without changing the API surface), and was confused when changing the APIVersion returned by my api_guard function did not change the bindings generated.

Here is an example of what I expected would update the version embedded in the (C#) bindings.

pub extern "C" fn ffi_api_guard() -> interoptopus::patterns::api_guard::APIVersion {
    let impl_version = 1;
    let api_version = interoptopus::patterns::api_guard::inventory_hash(&ffi_inventory());
    interoptopus::patterns::api_guard::APIVersion::new(api_version + impl_version)
}

It seems that the assumption that the APIVersion is always the inventory hash is made in the writer. I think it would make more sense, given that the api_guard function is developer defined, to use it's return value when generating the bindings.

let version = inventory_hash(self.inventory());

As a workaround, I am just including a doc comment with "impl version: 1" on the ffi_api_guard function, and bumping that as needed to regenerate the bindings.

@ralfbiedert ralfbiedert added c-core Interoptopus Core Crate c-proc Proc Macros labels Jun 26, 2023
@ralfbiedert
Copy link
Owner

Maybe I misunderstand, but the API guard is (meant to be) strictly for catching mismatches between bindings and binaries, and it's only about catching mismatches between the binary API surface, and the way that surface is expressed in a binding.

@kevin-cgc
Copy link
Author

kevin-cgc commented Jun 26, 2023

I see. I was a bit confused about it initially, but realized that must have been the initial design intent after looking at the writer.

I think, especially since the api guard function is already explicitly implemented by the developer, it would be nice if we could have more control over what constitutes a mismatch between the bindings and binary. For my case, bumping the API guard version has been a very useful sanity check to make sure the correct version of the DLL is actually being loaded whenever I recompile against the latest bindings.

Otherwise, if the API guard pattern should be reserved for just the API surface, it may be less confusing if the API guard function implementation is provided by interoptopus rather than by developers? Not sure about that though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-core Interoptopus Core Crate c-proc Proc Macros
Projects
None yet
Development

No branches or pull requests

2 participants