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

types.rs incompatibility, not clear which should be used #85

Open
joepio opened this issue Mar 30, 2022 · 1 comment
Open

types.rs incompatibility, not clear which should be used #85

joepio opened this issue Mar 30, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@joepio
Copy link
Contributor

joepio commented Mar 30, 2022

The generated rust-wasmer-runtime/types.rs and rust-plugin/src/types.rs both contain types for the same structs. However, they are not compatible.

When I tried compiling the generated example runtime, cargo was nagging about receiving the wrong ComplexGuestToHost type in rust-wasmer-runtime/bindings.rs. I was able to fix this by changing the imports in rust-wasmer-runtime/bindings.rs, changing them from super::* (which, I assume, links to rust-wasmer-runtime/types.rs) to rust-plugin/src/types.rs.

In my case, I changed my import in my generated runtime to this:

use atomic_bindings::{ComplexAlias, ComplexGuestToHost, ComplexHostToGuest, RequestOptions};

But maybe the real solution is to fix the difference in generated type vs original type. I don't know.

@Zagitta
Copy link
Contributor

Zagitta commented Mar 31, 2022

You are indeed right that the current example is quite confusing. To a large degree, it's an older approach we don't use ourselves.

What we do instead is have a separate rust crate with the actual types in and mark them with Serializable and tell the code rust code generators to use that type directly instead.
Here's an example of doing that in a crate called my_types

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Serializable)]
#[fp(rust_plugin_module = "my_types", rust_wasmer_runtime = "my_types")]
pub struct Foobar {
    pub name: String,
}

This will instead generate a types.rs that looks something like this:

use serde::{Deserialize, Serialize};
use std::{collections::BTreeMap, collections::BTreeSet, collections::HashMap, rc::Rc};

pub use my_types::Foobar;

That behavior is documented in a bit more detail here: https://github.com/fiberplane/fp-bindgen#using-existing-rust-types

@Zagitta Zagitta added the documentation Improvements or additions to documentation label Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants