diff --git a/README.md b/README.md index fc5ad729..bf392c1c 100644 --- a/README.md +++ b/README.md @@ -34,15 +34,82 @@ This project will implement a pure rust crate for creating and manipulating IPLD graphs that encode WNFS. Its goal is to be as dependency-less as possible in order to be easily compiled to WASM and used in browsers or other environments. -## -## Building Project +## Building the Project + +#### REQUIREMENTS + +- Rust toolchain + + Rust toolchain can be installed by following the instructions [here](https://doc.rust-lang.org/cargo/getting-started/installation.html) + +- WebAssembly toolchain + + We need to build the project in WebAssembly. To do so, we need to install `wasm-pack` and tweak Rust toolchain context. + +
+ Read more + + - Install `wasm32-unknown-unknown` target + + ```bash + rustup target add wasm32-unknown-unknown + ``` + + - [rust-analyzer](https://rust-analyzer.github.io/manual.html#installation) is the go-to IDE tool for Rust and if you have it set up, you may want to set the `rust-analyzer.cargo.target` [setting](https://code.visualstudio.com/docs/getstarted/settings#_workspace-settings) to `wasm32-unknown-unknown` + + - Install wasm-pack + + ```bash + cargo install wasm-pack + ``` + +
+ +- **wnfs** script + + If you are on a Unix platform, you can optionally install the `wnfs` script. + + ```bash + sh script/wnfs.sh setup + ``` + + And you can use it like this afterwards + + ```bash + wnfs help + ``` + +#### STEPS + +- Clone the repository. + + ```bash + git https://github.com/fission-suite/rs-wnfs.git + ``` + +- Change directory + + ```bash + cd rs-wnfs + ``` + +- Build the project + + ```bash + sh scripts/wnfs.sh build + ``` + +## Testing the Project -- Install [Rustup](https://www.rust-lang.org/tools/install) +- Run all tests -- Clone the repository: + ```bash + sh scripts/wnfs.sh test + ``` -```bash -git clone https://github.com/fission-suite/rs-wnfs.git -``` +- Show code coverage + ```bash + sh scripts/wnfs.sh coverage + ``` diff --git a/crates/fs/README.md b/crates/fs/README.md index 22bb3999..8b145749 100644 --- a/crates/fs/README.md +++ b/crates/fs/README.md @@ -1,17 +1,17 @@ ## The FileSystem -### Building the Project +## Building the Project - Build project -```bash -cargo build --release -``` + ```bash + cargo build --release + ``` -### Testing the Project +## Testing the Project -- Build project +- Run tests -```bash -cargo test --release -``` + ```bash + cargo test --release + ``` diff --git a/crates/fs/public/directory.rs b/crates/fs/public/directory.rs index e44965f4..5a4446b7 100644 --- a/crates/fs/public/directory.rs +++ b/crates/fs/public/directory.rs @@ -479,14 +479,14 @@ mod public_directory_tests { async fn files_added_to_directory_looked_up_unsuccessful() { let root = PublicDirectory::new(Utc::now()); - let mut store = MemoryBlockStore::default(); + let store = MemoryBlockStore::default(); let content_cid = Cid::default(); let time = Utc::now(); let root = root - .write(&[String::from("text.txt")], content_cid, time, &mut store) + .write(&[String::from("text.txt")], content_cid, time, &store) .await .unwrap(); diff --git a/crates/wasm/README.md b/crates/wasm/README.md index 5a5220c5..8037a908 100644 --- a/crates/wasm/README.md +++ b/crates/wasm/README.md @@ -1,29 +1,29 @@ ## The WebAssembly API -### Building the Project +## Building the Project - Install `wasm-pack` -```bash -cargo install wasm-pack -``` + ```bash + cargo install wasm-pack + ``` - Build project -```bash -wasm-pack build --target web -``` + ```bash + wasm-pack build --target web + ``` -### Testing the Project +## Testing the Project - Start the test -```bash -wasm-pack test --chrome -``` + ```bash + wasm-pack test --chrome + ``` - Run tests in the browser -```bash -open http://127.0.0.1:8000 -``` + ```bash + open http://127.0.0.1:8000 + ``` diff --git a/crates/wasm/fs/public/directory.rs b/crates/wasm/fs/public/directory.rs index 6dbda77a..5027abae 100644 --- a/crates/wasm/fs/public/directory.rs +++ b/crates/wasm/fs/public/directory.rs @@ -8,7 +8,6 @@ use wnfs::public::PublicDirectory as WnfsPublicDirectory; #[wasm_bindgen] pub struct PublicDirectory(WnfsPublicDirectory); -#[cfg(target_arch = "wasm32")] #[wasm_bindgen] impl PublicDirectory { /// Creates a new directory using the given metadata. @@ -19,7 +18,6 @@ impl PublicDirectory { } } -#[cfg(target_arch = "wasm32")] #[cfg(test)] mod public_directory_tests { use super::*; diff --git a/crates/wasm/fs/public/file.rs b/crates/wasm/fs/public/file.rs index 443495d5..4b9f012a 100644 --- a/crates/wasm/fs/public/file.rs +++ b/crates/wasm/fs/public/file.rs @@ -12,7 +12,6 @@ use crate::fs::JsResult; #[wasm_bindgen] pub struct PublicFile(WnfsPublicFile); -#[cfg(target_arch = "wasm32")] #[wasm_bindgen] impl PublicFile { /// Creates a new file in a WNFS public file system. @@ -24,7 +23,6 @@ impl PublicFile { } } -#[cfg(target_arch = "wasm32")] #[cfg(test)] mod public_file_tests { use super::*; diff --git a/scripts/wnfs.sh b/scripts/wnfs.sh new file mode 100755 index 00000000..b0bc87b7 --- /dev/null +++ b/scripts/wnfs.sh @@ -0,0 +1,174 @@ +#!/bin/bash + +# PATHS +# Get current working directory +current_dir=`pwd` + +# Get the absolute path of where script is running from +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd)" +script_path="$script_dir/wnfs.sh" + +# RETURN VARIABLE +ret="" + +# ARGUMENTS +args="${@:2}" # All arguments except the first + +# COLORS +red='\033[0;31m' +green='\033[0;32m' +none='\033[0m' + +# DESCRIPTION: +# Where execution starts +# +main() { + case $1 in + build ) + build + ;; + test ) + test + ;; + coverage ) + coverage + ;; + setup ) + setup + ;; + *) + help + ;; + esac + + exit 0 +} + +# DESCRIPTION: +# Prints the help info. +# +# USAGE: +# wnfs build +# +help() { + echo "" + echo "Rust WNFS Utility Script" + echo "" + echo "USAGE:" + echo " wnfs [COMMAND] [...args]" + echo "" + echo "COMMAND:" + echo " * build - build project" + echo " * test - run tests" + echo " * coverage - show code coverage" + echo " * setup - install wnfs script" + echo " * -h, help - print this help message" + echo "" + echo "" +} + +#------------------------------------------------------------------------------- +# Commands +#------------------------------------------------------------------------------- + +# DESCRIPTION: +# Builds the project. +# +# USAGE: +# wnfs build +# +build() { + displayln "build command not implemented yet" +} + + +# DESCRIPTION: +# Runs tests. +# +# USAGE: +# wnfs test +# +test() { + displayln "test command not implemented yet" +} + + +# DESCRIPTION: +# Shows the code coverage of the project +# +# USAGE: +# wnfs coverage +# +coverage() { + displayln "coverage command not implemented yet" +} + +#------------------------------------------------------------------------------ +# Helper functions +#------------------------------------------------------------------------------ + +# DESCRIPTION: +# Gets the value following a flag +# +get_flag_value() { + local found=false + local key=$1 + local count=0 + + # For every argument in the list of arguments + for arg in $args; do + count=$((count + 1)) + # Check if any of the argument matches the key provided + if [[ $arg = $key ]]; then + found=true + break + fi + done + + local args=($args) + local value=${args[count]} + + # Check if argument specified was found + if [[ $found = true ]]; then + + # Check if there exists a word after the key + # And that such word doesn't start with hyphen + if [[ ! -z $value ]] && [[ $value != "-"* ]]; then + ret=$value + else + ret="" + fi + + else + ret="" + fi +} + +# DESCRIPTION: +# Sets up the cript by making it excutable and available system wide +# +setup() { + display "Make script executable" + chmod u+x $script_path + + display "Drop a link to it in /usr/local/bin" + ln -s $script_path /usr/local/bin/wnfs +} + +# DESCRIPTION: +# A custom print function +# +display() { + printf "::: $1 :::\n" +} + + +# DESCRIPTION: +# A custom print function that starts its output with a newline +# +displayln() { + printf "\n::: $1 :::\n" +} + + +main $@