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

feat: add rust & python plugin templates #1747

Merged
merged 4 commits into from
May 10, 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
9 changes: 6 additions & 3 deletions .github/workflows/ci-javascript.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,13 @@ jobs:
mv wrappers packages/test-cases/cases

- name: Test cli:unit
run: yarn test:cli:unit
run: yarn test:unit
working-directory: ./packages/cli

- name: Test cli:e2e:p1
run: yarn test:cli:e2e:p1
run: yarn test:e2e:p1
working-directory: ./packages/cli

- name: Test cli:e2e:p2
run: yarn test:cli:e2e:p2
run: yarn test:e2e:p2
working-directory: ./packages/cli
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Polywrap Origin (0.10.3)
## Features
**`polywrap` CLI:**
* [PR-1747](https://github.com/polywrap/toolchain/pull/1747) **Add Rust & Python plugin template projects to CLI's `create` command**
* The `create` command now supports `plugin/rust` and `plugin/python` project types.

## Bugs
**`@polywrap/schema-bind`:**
* [PR-1734](https://github.com/polywrap/toolchain/pull/1734) **Update `plugin/python` Bindings**
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const urlStr = intlMsg.commands_create_options_t_url();
export const supportedLangs = {
wasm: ["assemblyscript", "rust", "interface"] as const,
app: ["typescript"] as const,
plugin: ["typescript"] as const,
plugin: ["typescript", "rust", "python"] as const,
};

export type ProjectType = keyof typeof supportedLangs;
Expand Down
2 changes: 1 addition & 1 deletion packages/templates/app/typescript/polywrap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ project:
name: Sample
type: app/typescript
source:
schema: ./schema.graphql
schema: ./polywrap.graphql
4 changes: 2 additions & 2 deletions packages/templates/plugin/python/polywrap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ project:
name: Sample
type: plugin/python
source:
schema: ./schema.graphql
module: ./sample/__init__.py
schema: ./polywrap.graphql
module: ./sample/__init__.py
21 changes: 21 additions & 0 deletions packages/templates/plugin/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "template_plugin_rs"
version = "0.1.0"
license = "MIT"
description = "Polywrap Rust Plugin Template"
edition = "2021"

include = [
"src/wrap/*",
"src/lib.rs"
]

[dependencies]
polywrap_core = { version = "0.1.6-beta.1" }
polywrap_plugin = { version = "0.1.6-beta.1" }
polywrap_msgpack = { version = "0.1.6-beta.1" }
wrap_manifest_schemas = { version = "0.1.6-beta.1" }
serde = {version = "1.0.145", features = ["derive"]}

[dev-dependencies]
polywrap_client = { version = "~0.1.6-beta.1" }
7 changes: 7 additions & 0 deletions packages/templates/plugin/rust/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "templates-plugin-rust",
"private": true,
"dependencies": {
"polywrap": "~0.10.2"
}
}
7 changes: 7 additions & 0 deletions packages/templates/plugin/rust/polywrap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
format: 0.3.0
project:
name: Sample
type: plugin/rust
source:
schema: ./polywrap.graphql
module: ./Cargo.toml
22 changes: 22 additions & 0 deletions packages/templates/plugin/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::wrap::wrap_info::get_manifest;
use polywrap_core::invoke::Invoker;
use polywrap_plugin::{error::PluginError, implementor::plugin_impl, JSON};
use wrap::{
module::{ArgsSampleMethod, Module},
};
use std::{sync::Arc};
pub mod wrap;

#[derive(Debug)]
pub struct SamplePlugin {}

#[plugin_impl]
impl Module for SamplePlugin {
fn sample_method(
&mut self,
args: &ArgsSampleMethod,
_: Arc<dyn Invoker>,
) -> Result<String, PluginError> {
Ok(format!("{:} from sample_method", args.data).to_string())
}
}
50 changes: 50 additions & 0 deletions packages/templates/plugin/rust/tests/e2e.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use template_plugin_rs::SamplePlugin;
use polywrap_core::{
client::ClientConfig,
resolvers::{
static_resolver::{StaticResolver, StaticResolverLike},
uri_resolution_context::UriPackage,
},
uri::Uri,
};
use polywrap_msgpack::{msgpack};
use polywrap_plugin::{package::PluginPackage};
use polywrap_client::{
client::PolywrapClient,
};
use std::{
sync::{Arc, Mutex},
};

fn get_client() -> PolywrapClient {
let sample_plugin = SamplePlugin {};
let plugin_pkg: PluginPackage = sample_plugin.into();
let package = Arc::new(Mutex::new(plugin_pkg));

let resolver = StaticResolver::from(vec![StaticResolverLike::Package(UriPackage {
uri: Uri::try_from("plugin/sample").unwrap(),
package,
})]);

PolywrapClient::new(ClientConfig {
resolver: Arc::new(resolver),
interfaces: None,
envs: None,
})
}

#[test]
fn sample_method() {
let response = get_client()
.invoke::<String>(
&Uri::try_from("plugin/sample").unwrap(),
"sampleMethod",
Some(&msgpack!({
"data": "input data",
})),
None,
None,
)
.unwrap();
assert_eq!(response, "input data from sample_method");
}
Loading