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

chore: tidy up examples #533

Merged
merged 6 commits into from
Jun 5, 2024
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ Cargo.lock

*.csv

# Compiled wasm
www/wasm
# Built wasm files
built-wasm/
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ tracing = { version = "0.1" }
either = "1"
void = "1"

#ipfs dependency
# ipfs dependency
rust-ipfs = "0.11.18"

# wasm crates
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ outside of localhost.
| Rust | `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \| sh` |
| CMake | `brew install cmake` |

## Building to WASM and using it within the browser
## Usage

[See wasm docs](./tools/wasm-example/README.md)
[See warp-ipfs examples](./extensions/warp-ipfs/examples/README.md)

## Docs

Expand Down
2 changes: 2 additions & 0 deletions extensions/warp-ipfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ clap = { version = "4.0", features = ["derive"] }

rpassword = "7.3"

# crates for examples
tiny_file_server = "0.1.5"

[features]
default = []
Expand Down
50 changes: 50 additions & 0 deletions extensions/warp-ipfs/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Examples

Example usages of warp-ipfs

## Using from Rust (desktop)

CLI for interacting with Multipass (identity):
```
cargo run --example identity-interface
```

Basic ipfs setup example:
```
cargo run --example ipfs-example
```

Basic friends example:
```
cargo run --example ipfs-friends
```

Basic identity example:
```
cargo run --example ipfs-identity
```

CLI for interacting with Constellation (file management):
```
cargo run --example ipfs-persisent
```

CLI messenger example:
```
cargo run --example messenger
```

## Using from Rust (WASM)

[wasm-ipfs-friends](./wasm-ipfs-friends/README.md)

[wasm-ipfs-identity](./wasm-ipfs-identity/README.md)

[wasm-ipfs-storage](./wasm-ipfs-storage/README.md)

## Using from Javascript

Serves web files that contain examples of javascript calling into wasm built from `warp-ipfs`:
```
cargo run --example from-js
```
55 changes: 55 additions & 0 deletions extensions/warp-ipfs/examples/from-js.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use std::process::Command;
use tiny_file_server::FileServer;
use tracing_subscriber::{filter::LevelFilter, EnvFilter};

const ADDR: &str = "127.0.0.1:9080";
const PATH: &str = "extensions/warp-ipfs/examples/from-js";

fn main() {
//set up logger so we can get an output from tiny_file_server
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy(),
)
.init();

println!("\nInstalling wasm-pack ...");
let cmd = get_cmd("cargo install wasm-pack");
spawn_and_wait(cmd);

println!("\nBuilding warp-ipfs wasm files ...");
let cmd = get_cmd("wasm-pack build extensions/warp-ipfs --target web --out-dir examples/from-js/built-wasm/warp-ipfs");
spawn_and_wait(cmd);

println!("\nStarting file server ...");
FileServer::http(ADDR)
.expect("Server should be created")
.run(PATH)
.expect("Server should start");
}

// assumes all spaces are argument separators. args containing spaces will yield unexpected results (such as strings)
fn get_cmd(cmd_str: &str) -> Command {
let mut split = cmd_str.split(" ");

// first item is the program, then the rest of the items are the args
let mut cmd = Command::new(split.nth(0).unwrap());
for arg in split {
cmd.arg(arg);
}
cmd
}

fn spawn_and_wait(mut cmd: Command) {
let status = cmd
.spawn()
.expect("command failed to start")
.wait()
.expect("failed to get ExitStatus");

if !status.success() {
panic!("cmd ExitStatus not successful");
};
}
8 changes: 8 additions & 0 deletions extensions/warp-ipfs/examples/wasm-ipfs-friends/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# wasm-ipfs-friends

To build do the following:

1. Install wasm32-unknown-unknown target by doing `rustup target add wasm32-unknown-unknown`
2. Install wasm-pack by doing `cargo install wasm-pack`
3. Run `wasm-pack build --target web --out-dir static`
4. Use a web server to serve the content from `static` directory. E.g with python install you can do `python3 -m http.server -d ./static`
16 changes: 0 additions & 16 deletions tools/wasm-example/Cargo.toml

This file was deleted.

14 changes: 0 additions & 14 deletions tools/wasm-example/README.md

This file was deleted.

28 changes: 0 additions & 28 deletions tools/wasm-example/src/lib.rs

This file was deleted.