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

Refactor wrap-rust bindings to use wrap::prelude::* #102

Merged
merged 3 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion implementations/wrap-rust/URI.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
wrap://http/https://wraps.wrapscan.io/r/polywrap/wrap-rust-abi-bindgen@1.0.0
wrap://ipfs/QmVcfPJK9oNmHBGtLkVzBwAQCRJgESTJTxZPmhBRJSHjwV
Binary file modified implementations/wrap-rust/build/wrap.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion implementations/wrap-rust/polywrap.deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
package: http
uri: $$ipfs_deploy
config:
postUrl: https://wraps.wrapscan.io/r/polywrap/wrap-rust-abi-bindgen@1.0.0
postUrl: https://wraps.wrapscan.io/r/polywrap/wrap-rust-abi-bindgen@2.0.0
headers:
- name: Authorization
value: $POLYWRAP_WRAPSCAN_AUTH_HEADER_PROD
Original file line number Diff line number Diff line change
@@ -1,61 +1,15 @@
pub mod entry;
pub mod prelude;
pub mod custom_type;
pub use custom_type::CustomType;
pub mod another_type;
pub use another_type::AnotherType;
pub mod custom_map_value;
pub use custom_map_value::CustomMapValue;
pub mod _else;
pub use _else::Else;
pub mod custom_enum;
pub use custom_enum::{
get_custom_enum_key,
get_custom_enum_value,
sanitize_custom_enum_value,
CustomEnum
};
pub mod _while;
pub use _while::{
get_while_key,
get_while_value,
sanitize_while_value,
While
};
pub mod env;
pub use env::Env;
pub mod imported;

pub use imported::test_import_object::TestImportObject;
pub use imported::test_import_another_object::TestImportAnotherObject;
pub use imported::test_import_enum::{
get_test_import_enum_key,
get_test_import_enum_value,
sanitize_test_import_enum_value,
TestImportEnum
};
pub use imported::test_import_enum_return::{
get_test_import_enum_return_key,
get_test_import_enum_return_value,
sanitize_test_import_enum_return_value,
TestImportEnumReturn
};
pub use imported::test_import_env::TestImportEnv;
pub use imported::test_import_module::TestImportModule;
pub mod test_import;
pub use test_import::TestImport;
pub mod module;
pub use module::{
Module,
ModuleTrait,
module_method_wrapped,
ArgsModuleMethod,
object_method_wrapped,
ArgsObjectMethod,
optional_env_method_wrapped,
ArgsOptionalEnvMethod,
if_wrapped,
ArgsIf
};

// Override print!(...) & println!(...) macros
#[macro_export]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
use crate::CustomEnum;
use crate::AnotherType;
use crate::Else;
use crate::env::Env;
use crate::Env;

pub struct Module;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use polywrap_wasm_rs::{
JSON,
wrap_load_env
};
use crate::module::{ModuleTrait, Module};
use crate::{ModuleTrait, Module};
use crate::CustomEnum;
use crate::AnotherType;
use crate::Else;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
pub use super::custom_type::CustomType;
pub use super::another_type::AnotherType;
pub use super::custom_map_value::CustomMapValue;
pub use super::_else::Else;
pub use super::custom_enum::{
get_custom_enum_key,
get_custom_enum_value,
sanitize_custom_enum_value,
CustomEnum
};
pub use super::_while::{
get_while_key,
get_while_value,
sanitize_while_value,
While
};
pub use super::env::Env;
pub use super::imported::test_import_object::TestImportObject;
pub use super::imported::test_import_another_object::TestImportAnotherObject;
pub use super::imported::test_import_enum::{
get_test_import_enum_key,
get_test_import_enum_value,
sanitize_test_import_enum_value,
TestImportEnum
};
pub use super::imported::test_import_enum_return::{
get_test_import_enum_return_key,
get_test_import_enum_return_value,
sanitize_test_import_enum_return_value,
TestImportEnumReturn
};
pub use super::imported::test_import_env::TestImportEnv;
pub use super::imported::test_import_module::TestImportModule;
pub use super::test_import::TestImport;
pub use super::module::{
Module,
ModuleTrait,
module_method_wrapped,
ArgsModuleMethod,
object_method_wrapped,
ArgsObjectMethod,
optional_env_method_wrapped,
ArgsOptionalEnvMethod,
if_wrapped,
ArgsIf
};
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
pub mod entry;

pub mod prelude;
pub mod module;
pub use module::{
Module,
ModuleTrait,
function1_wrapped,
ArgsFunction1,
function2_wrapped,
ArgsFunction2
};

// Override print!(...) & println!(...) macros
#[macro_export]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use polywrap_wasm_rs::{
JSON,
wrap_load_env
};
use crate::module::{ModuleTrait, Module};
use crate::{ModuleTrait, Module};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ArgsFunction1 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub use super::module::{
Module,
ModuleTrait,
function1_wrapped,
ArgsFunction1,
function2_wrapped,
ArgsFunction2
};
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
pub mod entry;
pub mod prelude;
pub mod custom_type;
pub use custom_type::CustomType;
pub mod another_type;
pub use another_type::AnotherType;
pub mod custom_map_value;
pub use custom_map_value::CustomMapValue;
pub mod _else;
pub use _else::Else;
pub mod arg;
pub use arg::Arg;
pub mod nested;
pub use nested::Nested;
pub mod output;
pub use output::Output;

pub mod module;
pub use module::{
Module,
ModuleTrait,
method_wrapped,
ArgsMethod
};

// Override print!(...) & println!(...) macros
#[macro_export]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use polywrap_wasm_rs::{
JSON,
wrap_load_env
};
use crate::module::{ModuleTrait, Module};
use crate::{ModuleTrait, Module};
use crate::Arg;
use crate::Output;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pub use super::custom_type::CustomType;
pub use super::another_type::AnotherType;
pub use super::custom_map_value::CustomMapValue;
pub use super::_else::Else;
pub use super::arg::Arg;
pub use super::nested::Nested;
pub use super::output::Output;
pub use super::module::{
Module,
ModuleTrait,
method_wrapped,
ArgsMethod
};
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
pub mod entry;
pub mod prelude;
pub mod env_object;
pub use env_object::EnvObject;
pub mod env_enum;
pub use env_enum::{
get_env_enum_key,
get_env_enum_value,
sanitize_env_enum_value,
EnvEnum
};
pub mod env;
pub use env::Env;

pub mod module;
pub use module::{
Module,
ModuleTrait,
method_no_env_wrapped,
ArgsMethodNoEnv,
method_require_env_wrapped,
ArgsMethodRequireEnv,
method_optional_env_wrapped,
ArgsMethodOptionalEnv
};

// Override print!(...) & println!(...) macros
#[macro_export]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
ArgsMethodRequireEnv,
ArgsMethodOptionalEnv,
};
use crate::env::Env;
use crate::Env;

pub struct Module;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use polywrap_wasm_rs::{
JSON,
wrap_load_env
};
use crate::module::{ModuleTrait, Module};
use crate::{ModuleTrait, Module};
use crate::Env;

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pub use super::env_object::EnvObject;
pub use super::env_enum::{
get_env_enum_key,
get_env_enum_value,
sanitize_env_enum_value,
EnvEnum
};
pub use super::env::Env;
pub use super::module::{
Module,
ModuleTrait,
method_no_env_wrapped,
ArgsMethodNoEnv,
method_require_env_wrapped,
ArgsMethodRequireEnv,
method_optional_env_wrapped,
ArgsMethodOptionalEnv
};
8 changes: 8 additions & 0 deletions implementations/wrap-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ impl ModuleTrait for Module {
)
});

output.files.push(File {
name: "prelude.rs".to_string(),
data: renderer.render(
"prelude.rs",
&abi_value
)
});

let get_dir_name = |value: &JSON::Value| -> String {
let dir_name = value.get("type").unwrap().as_str().unwrap().to_string();
_to_lower(&dir_name)
Expand Down
2 changes: 2 additions & 0 deletions implementations/wrap-rust/src/templates/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod entry_rs;
mod mod_rs;
mod prelude_rs;
mod enum_type;
mod env_type;
mod interface_type;
Expand All @@ -15,6 +16,7 @@ pub struct Template {
pub fn load_templates() -> Vec<Template> {
vec!(
mod_rs::load(),
prelude_rs::load(),
entry_rs::load(),
enum_type::mod_rs::load(),
env_type::mod_rs::load(),
Expand Down
35 changes: 1 addition & 34 deletions implementations/wrap-rust/src/templates/mod_rs.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
lazy_static! {
static ref NAME: String = "mod.rs".to_string();
static ref SOURCE: String = r#"pub mod entry;
pub mod prelude;
{{#each objectTypes}}
pub mod {{detect_keyword (to_lower type)}};
pub use {{detect_keyword (to_lower type)}}::{{detect_keyword (to_upper type)}};
{{/each}}
{{#each enumTypes}}
pub mod {{detect_keyword (to_lower type)}};
pub use {{detect_keyword (to_lower type)}}::{
get_{{to_lower type}}_key,
get_{{to_lower type}}_value,
sanitize_{{to_lower type}}_value,
{{detect_keyword (to_upper type)}}
};
{{/each}}
{{#with envType}}
pub mod {{detect_keyword (to_lower type)}};
pub use {{detect_keyword (to_lower type)}}::{{detect_keyword (to_upper type)}};
{{/with}}
{{#if (array_has_length importedModuleTypes)}}
pub mod imported;
Expand All @@ -27,37 +20,11 @@ pub mod imported;
{{else}}{{#if (array_has_length importedEnvTypes)}}
pub mod imported;
{{/if}}{{/if}}{{/if}}{{/if}}
{{#each importedObjectTypes}}
pub use imported::{{detect_keyword (to_lower type)}}::{{detect_keyword (to_upper type)}};
{{/each}}
{{#each importedEnumTypes}}
pub use imported::{{detect_keyword (to_lower type)}}::{
get_{{to_lower type}}_key,
get_{{to_lower type}}_value,
sanitize_{{to_lower type}}_value,
{{detect_keyword (to_upper type)}}
};
{{/each}}
{{#each importedEnvTypes}}
pub use imported::{{detect_keyword (to_lower type)}}::{{detect_keyword (to_upper type)}};
{{/each}}
{{#each importedModuleTypes}}
pub use imported::{{detect_keyword (to_lower type)}}::{{detect_keyword (to_upper type)}};
{{/each}}
{{#each interfaceTypes}}
pub mod {{detect_keyword (to_lower namespace)}};
pub use {{detect_keyword (to_lower namespace)}}::{{detect_keyword (to_upper namespace)}};
{{/each}}
{{#with moduleType}}
pub mod {{detect_keyword (to_lower type)}};
pub use {{detect_keyword (to_lower type)}}::{
Module,
ModuleTrait,
{{#each methods}}
{{to_lower name}}_wrapped,
Args{{to_upper name}}{{#if (is_not_last @index ../methods)}},{{/if}}
{{/each}}
};
{{/with}}

// Override print!(...) & println!(...) macros
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
use {{_crate}}::{{detect_keyword (to_upper _type)}};
{{/each}}
{{#with ../envType}}
use crate::env::Env;
use crate::Env;
{{/with}}

pub struct Module;
Expand Down
Loading
Loading