Skip to content

Commit

Permalink
Merge pull request #55 from polywrap/develop
Browse files Browse the repository at this point in the history
Release 0.4.3
  • Loading branch information
nerfZael authored Sep 18, 2023
2 parents f497501 + f4be08d commit 7e1beda
Show file tree
Hide file tree
Showing 55 changed files with 9,206 additions and 114 deletions.
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ members = [
"examples/http-server-app",
"examples/simple-storage-app",
"examples/advanced-server-app",
"examples/app-with-ui",
]

default-members = [
Expand All @@ -40,6 +41,7 @@ default-members = [
"examples/http-server-app",
"examples/simple-storage-app",
"examples/advanced-server-app",
"examples/app-with-ui",
]

[workspace.dependencies]
Expand Down
60 changes: 3 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,63 +20,9 @@ Then, to install `pwr`, run:
```bash
pwrup
```
## Script WRAPS (JS and Python)
{lang} = js | py

### REPL
`pwr {lang} repl`
Runs a REPL where you can type scripts.

`pwr {lang} repl -f {name_of_file}`
Runs the repl over a file.
It will read and execute the file first (and create it if it doesn't exist).
It will also store all CLI commands you type inside of it (after evaluating them).
Press enter in the CLI to re-run the whole file (useful if you want to code in the file instead of the CLI).

`pwr {lang} repl -f {name_of_file} -w`
It will read and execute the file first (and create it if it doesn't exist).
Then it will execute the file every time you save it.
It will not listen to CLI input if you use this option ("-w").

### New
`pwr {lang} new -f {name_of_file}`
Creates a new file of the specified name for the script wrap.
It uses a template for that language.

### Build
`pwr {lang} build -f {name_of_file}`
Builds the target script file.

### Deploy
`pwr deploy`
Deploys the build directory.

`pwr {lang} deploy`
Deploys the build directory. (Same as `pwr deploy`)

`pwr {lang} deploy -f {name_of_file}`
Builds and then deploys the script file.

## TODO: Examples PWR app usage:
Input: `pwr wrap://ens/wrap-echo.eth Hello world!`
Output: `Hello world!`

Input: `pwr ens/wrap-echo.eth Hello world!`
Output: `Hello world!`

Input: `pwr wrap-echo.eth Hello world!`
Output: `Hello world!`

Input: `pwr wrap://ipfs/QmebzauKAXoYbywLAYdBvKyPhWsDoHfkUC4wffWvjighKT Hello world!`
Output: `Hello world!`

Input: `pwr ipfs/QmebzauKAXoYbywLAYdBvKyPhWsDoHfkUC4wffWvjighKT Hello world!`
Output: `Hello world!`

Input: `pwr ipfs://QmebzauKAXoYbywLAYdBvKyPhWsDoHfkUC4wffWvjighKT Hello world!`
Output: `Hello world!`

Input: `pwr QmebzauKAXoYbywLAYdBvKyPhWsDoHfkUC4wffWvjighKT Hello world!`
Output: `Hello world!`
[Example PWR Usage](./docs/pwr-usage.md)

[Example PWR Apps](./docs/pwr-apps.md)

[Script WRAPS Guide](./docs/script-wraps.md)
7 changes: 7 additions & 0 deletions docs/pwr-apps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# PWR App Examples

- [Simple PWR App](../examples/simple-pwr-app/README.md)
- [Simple Storage App](../examples/simple-storage-app/README.md)
- [HTTP Server App](../examples/http-server-app/README.md)
- [Advanced HTTP Server App](../examples/app-with-ui/README.md)
- [PWR App with UI](../examples/app-with-ui/README.md)
57 changes: 57 additions & 0 deletions docs/pwr-usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Example PWR CLI usage:

## Migration
After running `pwrup`, you have to run `pwr migrate` to migrate your configuration to the latest version.

## Running pwr apps

### From wrapscan.io
To run a pwr app from wrapscan.io, run:
```bash
pwr wrapscan.io/pwr/say-hello
```

### From wrappers.dev
To run a pwr app from wrappers.dev, run:
```bash
pwr @pwr/say-hello
```
```bash
pwr https/wrappers.dev/u/pwr/say-hello
```

### Local directory
To run a pwr app from a local directory (e.g. `./build`), run:
```bash
pwr ./build
```
```bash
pwr fs/build
```

### From IPFS
To run a pwr app from IPFS, run:
```bash
pwr ipfs/Qm...
```
```bash
pwr Qm...
```
```bash
pwr ipfs://Qm...
```

### From ENS
To run a pwr app from ENS, run:
```bash
pwr ens/say-hello.eth
```
```bash
pwr say-hello.eth
```

## Passing arguments to pwr apps
To pass arguments to a pwr app add them after the WRAP URI, e.g.:
```bash
pwr ./build arg1 arg2
```
36 changes: 36 additions & 0 deletions docs/script-wraps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Script WRAPS (JS and Python)
{lang} = js | py

### REPL
`pwr {lang} repl`
Runs a REPL where you can type scripts.

`pwr {lang} repl -f {name_of_file}`
Runs the repl over a file.
It will read and execute the file first (and create it if it doesn't exist).
It will also store all CLI commands you type inside of it (after evaluating them).
Press enter in the CLI to re-run the whole file (useful if you want to code in the file instead of the CLI).

`pwr {lang} repl -f {name_of_file} -w`
It will read and execute the file first (and create it if it doesn't exist).
Then it will execute the file every time you save it.
It will not listen to CLI input if you use this option ("-w").

### New
`pwr {lang} new -f {name_of_file}`
Creates a new file of the specified name for the script wrap.
It uses a template for that language.

### Build
`pwr {lang} build -f {name_of_file}`
Builds the target script file.

### Deploy
`pwr deploy`
Deploys the build directory.

`pwr {lang} deploy`
Deploys the build directory. (Same as `pwr deploy`)

`pwr {lang} deploy -f {name_of_file}`
Builds and then deploys the script file.
1 change: 1 addition & 0 deletions examples/app-with-ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!src/wrap
1 change: 1 addition & 0 deletions examples/app-with-ui/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v16.13.0
22 changes: 22 additions & 0 deletions examples/app-with-ui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "app_with_ui"
version = "0.1.0"
description = "An example of a PWR HTTP server application with UI"

edition.workspace = true
rust-version.workspace = true
license.workspace = true

[dependencies]
polywrap_msgpack_serde.workspace = true
polywrap-wasm-rs.workspace = true
serde = { version = "1.0", features = ["derive"] }
serde_bytes.workspace = true

[lib]
crate-type = ["cdylib"]

[profile.release]
opt-level = 's'
lto = true
panic = 'abort'
2 changes: 2 additions & 0 deletions examples/app-with-ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# App with UI
An example of a PWR HTTP server application with UI
61 changes: 61 additions & 0 deletions examples/app-with-ui/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/./bin/sh
set -x
set -e
# Install the wasm32 rust build target
rustup target add wasm32-unknown-unknown

# Install the toml-cli
cargo install toml-cli

# Install wasm-snip
cargo install wasm-snip

# Install wasm-bindgen
cargo install wasm-bindgen-cli

# Install wasm-tools
cargo install wasm-tools

cargo install wasm-opt

# Ensure the module at {{dir}} has the crate-type = ["cdylib"]
# toml set ./Cargo.toml lib.crate-type ["cdylib"] > ./Cargo-local.toml && \
# mv ./Cargo.toml ./Cargo-bak.toml && \
# mv ./Cargo-local.toml ./Cargo.toml

# Clean up artifacts left by the toml CLI program ("["cdylib"]" -> ["cdylib"])
# sed -i .bak 's/"\[cdylib\]"/\["cdylib"\]/g' ./Cargo.toml && \
# rm -rf ./Cargo.toml.bak

# # Ensure the package name = "module"
# toml set ./Cargo.toml package.name "module" > ./Cargo-local.toml && \
# rm -rf ./Cargo.toml && \
# mv ./Cargo-local.toml ./Cargo.toml

# Ensure the Wasm module is configured to use imported memory
export RUSTFLAGS="-C link-arg=-z -C link-arg=stack-size=65536 -C link-arg=--import-memory"

# Build the module
cargo build --manifest-path Cargo.toml \
--target wasm32-unknown-unknown --release

# Enable the "WASM_INTERFACE_TYPES" feature, which will remove the __wbindgen_throw import.
# See: https://github.com/rustwasm/wasm-bindgen/blob/7f4663b70bd492278bf0e7bba4eeddb3d840c868/crates/cli-support/src/lib.rs#L397-L403
export WASM_INTERFACE_TYPES=1

# Run wasm-bindgen over the module, replacing all placeholder __wbindgen_... imports
wasm-bindgen ../../target/wasm32-unknown-unknown/release/app_with_ui.wasm --out-dir ./bin --out-name bg_module.wasm

# Run wasm-tools strip to remove the wasm-interface-types custom section
wasm-tools strip ./bin/bg_module.wasm -d wasm-interface-types -o ./bin/strip_module.wasm
rm -rf ./bin/bg_module.wasm

# Run wasm-snip to trip down the size of the binary, removing any dead code
wasm-snip ./bin/strip_module.wasm -o ./bin/snipped_module.wasm
rm -rf ./bin/strip_module.wasm

# Use wasm-opt to perform the "asyncify" post-processing step over all modules
export ASYNCIFY_STACK_SIZE=65535
wasm-opt --asyncify -Os ./bin/snipped_module.wasm -o ./bin/wrap.wasm
rm -rf ./bin/snipped_module.wasm
cp ./bin/wrap.wasm ./build/wrap.wasm
16 changes: 16 additions & 0 deletions examples/app-with-ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"private": true,
"scripts": {
"codegen": "npx polywrap codegen",
"compile": "./build.sh",
"build": "yarn codegen && yarn compile",
"deploy": "pwr deploy"
},
"devDependencies": {
"@types/jest": "26.0.8",
"jest": "26.6.3",
"polywrap": "0.11.2",
"ts-jest": "26.5.4",
"typescript": "4.9.5"
}
}
5 changes: 5 additions & 0 deletions examples/app-with-ui/polywrap.docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
format: 0.1.0
description: An example of a PWR HTTP server application with UI
website: https://polywrap.io
repository: https://github.com/polywrap/pwr
readme: ./README.md
9 changes: 9 additions & 0 deletions examples/app-with-ui/polywrap.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#import { Module, Response, KeyValuePair, Request } into HttpServer from "wrap://https/http.wrappers.dev/u/test/http-server"
#import { Module, KeyValuePair } into KeyValueStore from "wrap://https/http.wrappers.dev/u/test/key-value-store"
#import * into InvocationContext from "https/http.wrappers.dev/u/test/invocation-context"

type Module {
main(args: [String!]!): Int32!
onStart: Boolean!
routeHome(request: HttpServer_Request!): HttpServer_Response!
}
9 changes: 9 additions & 0 deletions examples/app-with-ui/polywrap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
format: 0.4.0
project:
name: app-with-ui
type: wasm/rust
source:
module: ./Cargo.toml
schema: ./polywrap.graphql
extensions:
docs: ./polywrap.docs.yaml
Loading

0 comments on commit 7e1beda

Please sign in to comment.