Skip to content

Commit

Permalink
Merge pull request #1864 from polywrap/nk/add-rs-app-template
Browse files Browse the repository at this point in the history
feat: add rust app codegen template
  • Loading branch information
dOrgJelli authored Sep 1, 2023
2 parents 02b2f34 + d541e62 commit 7e311f8
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 23 deletions.
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
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 @@
v18.15.0
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_app_rs"
version = "0.1.0"
license = "MIT"
description = "Polywrap Rust App Template"
edition = "2021"

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

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

[dev-dependencies]
10 changes: 10 additions & 0 deletions packages/templates/app/rust/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "template-app-rust",
"private": true,
"scripts": {
"build": "npx polywrap codegen"
},
"devDependencies": {
"polywrap": "0.11.2"
}
}
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();
}
}
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
42 changes: 21 additions & 21 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 @@ -3038,14 +3038,14 @@ array.prototype.flat@^1.2.3:
es-abstract "^1.20.4"
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==
array.prototype.reduce@^1.0.6:
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 @@ -3490,9 +3490,9 @@ camelcase@^6.0.0:
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

caniuse-lite@^1.0.30001517:
version "1.0.30001524"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001524.tgz#1e14bce4f43c41a7deaeb5ebfe86664fe8dadb80"
integrity sha512-Jj917pJtYg9HSJBF95HVX3Cdr89JUyLT4IZ8SvM5aDRni95swKgYi3TgYLH5hnGfPE/U1dg6IfZ50UsIlLkwSA==
version "1.0.30001525"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001525.tgz#d2e8fdec6116ffa36284ca2c33ef6d53612fe1c8"
integrity sha512-/3z+wB4icFt3r0USMwxujAqRvaD/B7rvGTsKhbhSQErVrJvkZCLhgNLJxU8MevahQVH6hCU9FsHdNUFbiwmE7Q==

capture-exit@^2.0.0:
version "2.0.0"
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.508"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.508.tgz#5641ff2f5ba11df4bd960fe6a2f9f70aa8b9af96"
integrity sha512-FFa8QKjQK/A5QuFr2167myhMesGrhlOBD+3cYNxO9/S4XzHEXesyTD/1/xF644gC8buFPz3ca6G1LOQD0tZrrg==

elliptic@6.5.4:
version "6.5.4"
Expand Down Expand Up @@ -4338,7 +4338,7 @@ error-ex@^1.2.0, error-ex@^1.3.1:
dependencies:
is-arrayish "^0.2.1"

es-abstract@^1.20.4, es-abstract@^1.21.2, es-abstract@^1.22.1:
es-abstract@^1.20.4, es-abstract@^1.22.1:
version "1.22.1"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.22.1.tgz#8b4e5fc5cefd7f1660f0f8e1a52900dfbc9d9ccc"
integrity sha512-ioRRcXMO6OFyRpyzV3kE1IIBd4WG5/kltnzdxSCqoP8CMGs/Li+M1uF5o7lOkZVFjDs+NLesthnF66Pg/0q0Lw==
Expand Down Expand Up @@ -7711,14 +7711,14 @@ object.assign@^4.1.4:
object-keys "^1.1.1"

object.getownpropertydescriptors@^2.0.3:
version "2.1.6"
resolved "https://registry.yarnpkg.com/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.1.6.tgz#5e5c384dd209fa4efffead39e3a0512770ccc312"
integrity sha512-lq+61g26E/BgHv0ZTFgRvi7NMEPuAxLkFU7rukXjc/AlwH4Am5xXVnIXy3un1bg/JPbXHrixRkK1itUzzPiIjQ==
version "2.1.7"
resolved "https://registry.yarnpkg.com/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.1.7.tgz#7a466a356cd7da4ba8b9e94ff6d35c3eeab5d56a"
integrity sha512-PrJz0C2xJ58FNn11XV2lr4Jt5Gzl94qpy9Lu0JlfEj14z88sqbSBJCBEzdlNUCzY2gburhbrwOZ5BHCmuNUy0g==
dependencies:
array.prototype.reduce "^1.0.5"
array.prototype.reduce "^1.0.6"
call-bind "^1.0.2"
define-properties "^1.2.0"
es-abstract "^1.21.2"
es-abstract "^1.22.1"
safe-array-concat "^1.0.0"

object.pick@^1.3.0:
Expand Down

0 comments on commit 7e311f8

Please sign in to comment.