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 app codegen template #1864

Merged
merged 13 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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 packages/cli/src/__tests__/e2e/p1/create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Commands:
wasm [options] <language> <name> Create a Polywrap wasm wrapper. langs:
assemblyscript, rust, golang, interface
app [options] <language> <name> Create a Polywrap application. langs:
typescript, python
typescript, python, rust
plugin [options] <language> <name> Create a Polywrap plugin. langs:
typescript, rust, python
template [options] <url> <name> Download template from a URL. formats:
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 @@ -28,7 +28,7 @@ const urlStr = intlMsg.commands_create_options_t_url();

export const supportedLangs = {
wasm: ["assemblyscript", "rust", "golang", "interface"] as const,
app: ["typescript", "python"] as const,
app: ["typescript", "python", "rust"] as const,
plugin: ["typescript", "rust", "python"] as const,
};

Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/lib/project/manifests/app/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BindLanguage } from "@polywrap/schema-bind";
export const appManifestLanguages = {
"app/typescript": "app/typescript",
"app/python": "app/python",
"app/rust": "app/rust",
};

export type AppManifestLanguages = typeof appManifestLanguages;
Expand All @@ -25,6 +26,8 @@ export function appManifestLanguageToBindLanguage(
return "app-ts";
case "app/python":
return "app-py";
case "app/rust":
return "app-rs";
default:
throw Error(
intlMsg.lib_language_unsupportedManifestLanguage({
Expand Down
4 changes: 4 additions & 0 deletions packages/schema/bind/src/bindings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export function getGenerateBindingFn(
return WrapBindgen.getGenerateBindingFn(
"wrapscan.io/polywrap/app-python-abi-bindgen@1"
);
case "app-rs":
return WrapBindgen.getGenerateBindingFn(
"wrapscan.io/polywrap/app-rust-abi-bindgen@1"
);
case "app-swift":
return WrapBindgen.getGenerateBindingFn(
"wrapscan.io/polywrap/app-swift-abi-bindgen@1"
Expand Down
1 change: 1 addition & 0 deletions packages/schema/bind/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const bindLanguage = {
"plugin-swift": "plugin-swift",
"app-ts": "app-ts",
"app-py": "app-py",
"app-rs": "app-rs",
"app-swift": "app-swift",
"app-kt": "app-kt",
};
Expand Down
23 changes: 23 additions & 0 deletions packages/templates/app/rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
1 change: 1 addition & 0 deletions packages/templates/app/rust/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v17.9.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be v18.15.0 like all other .nvmrc files in the CLI repo

17 changes: 17 additions & 0 deletions packages/templates/app/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "template_plugin_rs"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be "template_app_rs"

version = "0.1.0"
license = "MIT"
description = "Polywrap Rust Plugin Template"
edition = "2021"

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

[dependencies]
polywrap = { version = "~0.1.8" }
serde = {version = "1.0.145", features = ["derive"]}

[dev-dependencies]
21 changes: 21 additions & 0 deletions packages/templates/app/rust/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "templates-app-rust",
"description": "Polywrap App Rust Template",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for name, description, version

"private": true,
"version": "0.11.2",
"scripts": {
"build": "npx polywrap codegen",
"test": "ts-node ./src/index.ts",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't work

"ipfs:up": "npx polywrap infra up --modules=eth-ens-ipfs",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forget to remove! before I was using local ipfs in template but then migrate to just cat instead of add and cat

"ipfs:down": "npx polywrap infra down --modules=eth-ens-ipfs"
},
"dependencies": {
"@polywrap/client-js": "~0.12.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed right

},
"devDependencies": {
"@types/node": "18.15.0",
"polywrap": "0.11.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can only keep polywrap?

"ts-node": "10.9.1",
"typescript": "4.9.5"
}
}
1 change: 1 addition & 0 deletions packages/templates/app/rust/polywrap.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#import * into Ipfs from "wrapscan.io/polywrap/ipfs-http-client@1.0"
6 changes: 6 additions & 0 deletions packages/templates/app/rust/polywrap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
format: 0.3.0
project:
name: Sample
type: app/rust
source:
schema: ./polywrap.graphql
28 changes: 28 additions & 0 deletions packages/templates/app/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
mod wrap;

use polywrap::ByteBuf;
use wrap::types::*;

pub fn main() {
let ipfs_provider = "https://ipfs.io";
let cid = "Qmc5gCcjYypU7y28oCALwfSvxCBskLuPKWpK4qpterKC7z";
let ipfs = IpfsModule::new(None, None, None);

let data = ipfs.cat(&IpfsModuleArgsCat{
cid: cid.to_string(),
ipfs_provider: ipfs_provider.to_string(),
timeout: None,
cat_options: None
}, None, None, None).unwrap();

assert_eq!(data, ByteBuf::from("Hello World!\r\n".as_bytes().to_vec()));
}

#[cfg(test)]
mod client_tests {

#[test]
fn test_client() {
super::main();
}
}
30 changes: 30 additions & 0 deletions packages/templates/app/rust/tsconfig.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can also remove this one right

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file isn't needed

"compilerOptions": {
"esModuleInterop": true,
"lib": [
"es2015",
"es5",
"dom"
],
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"declaration": true,
"preserveSymlinks": true,
"preserveWatchOutput": true,
"pretty": false,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"module": "commonjs",
"sourceMap": true,
"target": "es5",
"resolveJsonModule": true,
"strictNullChecks": true
},
"include": [
"./src/**/*"
],
}
5 changes: 5 additions & 0 deletions packages/templates/tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ describe("Templates", () => {
build: "cargo build",
test: "cargo test",
},
"app/rust": {
codegen: "npx polywrap codegen",
build: "cargo build",
test: "cargo test",
},
interface: { build: "npx polywrap build" },
};

Expand Down
22 changes: 11 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@
js-tokens "^4.0.0"

"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.22.11", "@babel/parser@^7.22.5":
version "7.22.13"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.22.13.tgz#23fb17892b2be7afef94f573031c2f4b42839a2b"
integrity sha512-3l6+4YOvc9wx7VlCSw4yQfcBo01ECA8TicQfbnCPuCEpRQrf+gTUyGdxNw+pyTUyywp6JRD1w0YQs9TpBXYlkw==
version "7.22.14"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.22.14.tgz#c7de58e8de106e88efca42ce17f0033209dfd245"
integrity sha512-1KucTHgOvaw/LzCVrEOAyXkr9rQlp0A1HiHRYnSUE9dmb8PvPW7o5sscg+5169r54n3vGlbx6GevTE/Iw/P3AQ==

"@babel/plugin-syntax-async-generators@^7.8.4":
version "7.8.4"
Expand Down Expand Up @@ -3039,13 +3039,13 @@ array.prototype.flat@^1.2.3:
es-shim-unscopables "^1.0.0"

array.prototype.reduce@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/array.prototype.reduce/-/array.prototype.reduce-1.0.5.tgz#6b20b0daa9d9734dd6bc7ea66b5bbce395471eac"
integrity sha512-kDdugMl7id9COE8R7MHF5jWk7Dqt/fs4Pv+JXoICnYwqpjjjbUurz6w5fT5IG6brLdJhv6/VoHB0H7oyIBXd+Q==
version "1.0.6"
resolved "https://registry.yarnpkg.com/array.prototype.reduce/-/array.prototype.reduce-1.0.6.tgz#63149931808c5fc1e1354814923d92d45f7d96d5"
integrity sha512-UW+Mz8LG/sPSU8jRDCjVr6J/ZKAGpHfwrZ6kWTG5qCxIEiXdVshqGnu5vEZA8S1y6X4aCSbQZ0/EEsfvEvBiSg==
dependencies:
call-bind "^1.0.2"
define-properties "^1.1.4"
es-abstract "^1.20.4"
define-properties "^1.2.0"
es-abstract "^1.22.1"
es-array-method-boxes-properly "^1.0.0"
is-string "^1.0.7"

Expand Down Expand Up @@ -4262,9 +4262,9 @@ ecc-jsbn@~0.1.1:
safer-buffer "^2.1.0"

electron-to-chromium@^1.4.477:
version "1.4.505"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.505.tgz#00571ade5975b58413f0f56a665b065bfc29cdfc"
integrity sha512-0A50eL5BCCKdxig2SsCXhpuztnB9PfUgRMojj5tMvt8O54lbwz3t6wNgnpiTRosw5QjlJB7ixhVyeg8daLQwSQ==
version "1.4.506"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.506.tgz#59f64a211102db4c3ebae2f39cc0e8e1b12b3a07"
integrity sha512-xxGct4GPAKSRlrLBtJxJFYy74W11zX6PO9GyHgl/U+2s3Dp0ZEwAklDfNHXOWcvH7zWMpsmgbR0ggEuaYAVvHA==

elliptic@6.5.4:
version "6.5.4"
Expand Down
Loading