diff --git a/packages/cli/src/__tests__/e2e/p1/create.spec.ts b/packages/cli/src/__tests__/e2e/p1/create.spec.ts index f7d7507ef0..38671b99bb 100644 --- a/packages/cli/src/__tests__/e2e/p1/create.spec.ts +++ b/packages/cli/src/__tests__/e2e/p1/create.spec.ts @@ -19,7 +19,7 @@ Commands: wasm [options] Create a Polywrap wasm wrapper. langs: assemblyscript, rust, golang, interface app [options] Create a Polywrap application. langs: - typescript, python + typescript, python, rust plugin [options] Create a Polywrap plugin. langs: typescript, rust, python template [options] Download template from a URL. formats: diff --git a/packages/cli/src/commands/create.ts b/packages/cli/src/commands/create.ts index e23b09971c..4e322fc862 100644 --- a/packages/cli/src/commands/create.ts +++ b/packages/cli/src/commands/create.ts @@ -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, }; diff --git a/packages/templates/app/rust/.gitignore b/packages/templates/app/rust/.gitignore new file mode 100644 index 0000000000..4d29575de8 --- /dev/null +++ b/packages/templates/app/rust/.gitignore @@ -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* diff --git a/packages/templates/app/rust/.nvmrc b/packages/templates/app/rust/.nvmrc new file mode 100644 index 0000000000..2f3b977c5b --- /dev/null +++ b/packages/templates/app/rust/.nvmrc @@ -0,0 +1 @@ +v18.15.0 \ No newline at end of file diff --git a/packages/templates/app/rust/Cargo.toml b/packages/templates/app/rust/Cargo.toml new file mode 100644 index 0000000000..565176c7ff --- /dev/null +++ b/packages/templates/app/rust/Cargo.toml @@ -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] diff --git a/packages/templates/app/rust/package.json b/packages/templates/app/rust/package.json new file mode 100644 index 0000000000..e7abd5db4e --- /dev/null +++ b/packages/templates/app/rust/package.json @@ -0,0 +1,10 @@ +{ + "name": "template-app-rust", + "private": true, + "scripts": { + "build": "npx polywrap codegen" + }, + "devDependencies": { + "polywrap": "0.11.2" + } +} diff --git a/packages/templates/app/rust/polywrap.graphql b/packages/templates/app/rust/polywrap.graphql new file mode 100644 index 0000000000..99f9e5a24d --- /dev/null +++ b/packages/templates/app/rust/polywrap.graphql @@ -0,0 +1 @@ +#import * into Ipfs from "wrapscan.io/polywrap/ipfs-http-client@1.0" diff --git a/packages/templates/app/rust/polywrap.yaml b/packages/templates/app/rust/polywrap.yaml new file mode 100644 index 0000000000..506dd2f9f2 --- /dev/null +++ b/packages/templates/app/rust/polywrap.yaml @@ -0,0 +1,6 @@ +format: 0.3.0 +project: + name: Sample + type: app/rust +source: + schema: ./polywrap.graphql diff --git a/packages/templates/app/rust/src/lib.rs b/packages/templates/app/rust/src/lib.rs new file mode 100644 index 0000000000..c744392ca0 --- /dev/null +++ b/packages/templates/app/rust/src/lib.rs @@ -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(); + } +} diff --git a/packages/templates/tests.spec.ts b/packages/templates/tests.spec.ts index 9693ee913d..d16ec6820e 100644 --- a/packages/templates/tests.spec.ts +++ b/packages/templates/tests.spec.ts @@ -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" }, }; diff --git a/yarn.lock b/yarn.lock index 8e44b78e2f..54f41f39d0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -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" @@ -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" @@ -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== @@ -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: