mirror of
https://github.com/fluencelabs/marine-rs-sdk-test
synced 2024-12-04 23:30:18 +00:00
improve foreign block generation
This commit is contained in:
parent
40774a1107
commit
fc5a0d81cb
@ -52,12 +52,16 @@ pub struct AstExternFnItem {
|
||||
pub signature: AstFunctionSignature,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct AstExternModItem {
|
||||
pub namespace: String,
|
||||
|
||||
// only imports are possible here
|
||||
pub imports: Vec<AstExternFnItem>,
|
||||
|
||||
// Option is needed only for skipping serialization/deserialization of syn::ItemFn
|
||||
#[serde(skip)]
|
||||
pub original: Option<syn::ItemForeignMod>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
|
@ -28,8 +28,8 @@ const WASM_IMPORT_MODULE_DIRECTIVE_NAME: &str = "wasm_import_module";
|
||||
|
||||
impl ParseMacroInput for syn::ItemForeignMod {
|
||||
fn parse_macro_input(self) -> Result<FCEAst> {
|
||||
match self.abi.name {
|
||||
Some(ref name) if name.value() != "C" => {
|
||||
match &self.abi.name {
|
||||
Some(name) if name.value() != "C" => {
|
||||
return Err(Error::new(self.span(), "only 'C' abi is allowed"))
|
||||
}
|
||||
_ => {}
|
||||
@ -39,7 +39,8 @@ impl ParseMacroInput for syn::ItemForeignMod {
|
||||
|
||||
let imports = self
|
||||
.items
|
||||
.into_iter()
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(parse_raw_foreign_item)
|
||||
.collect::<Result<_>>()?;
|
||||
|
||||
@ -47,7 +48,7 @@ impl ParseMacroInput for syn::ItemForeignMod {
|
||||
// #[link(wasm_import_module = "host")]
|
||||
let wasm_import_module: Option<String> = self
|
||||
.attrs
|
||||
.into_iter()
|
||||
.iter()
|
||||
.filter_map(|attr| attr.parse_meta().ok())
|
||||
.filter(|meta| meta.path().is_ident(LINK_DIRECTIVE_NAME))
|
||||
.filter_map(|meta| {
|
||||
@ -73,7 +74,11 @@ impl ParseMacroInput for syn::ItemForeignMod {
|
||||
"import module name should be defined by 'wasm_import_module' directive",
|
||||
)),
|
||||
Some(namespace) => {
|
||||
let extern_mod_item = fce_ast_types::AstExternModItem { namespace, imports };
|
||||
let extern_mod_item = fce_ast_types::AstExternModItem {
|
||||
namespace,
|
||||
imports,
|
||||
original: Some(self),
|
||||
};
|
||||
Ok(FCEAst::ExternMod(extern_mod_item))
|
||||
}
|
||||
None => Err(Error::new(
|
||||
|
@ -35,6 +35,7 @@ impl quote::ToTokens for fce_ast_types::AstExternModItem {
|
||||
);
|
||||
|
||||
let wasm_import_module_name = &self.namespace;
|
||||
let original = &self.original;
|
||||
let generated_imports = generate_extern_section_items(&self);
|
||||
let wrapper_functions = generate_wrapper_functions(&self);
|
||||
|
||||
@ -45,6 +46,9 @@ impl quote::ToTokens for fce_ast_types::AstExternModItem {
|
||||
#generated_imports
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#original
|
||||
|
||||
#wrapper_functions
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
|
@ -32,7 +32,7 @@ impl quote::ToTokens for fce_ast_types::AstRecordItem {
|
||||
let glue_code = quote::quote! {
|
||||
#original
|
||||
|
||||
// #[cfg(target_arch = "wasm32")]
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[doc(hidden)]
|
||||
#[allow(clippy::all)]
|
||||
#[link_section = #section_name]
|
||||
|
Loading…
Reference in New Issue
Block a user