Skip to content

Commit

Permalink
corrected for wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Nov 24, 2024
1 parent a1417e7 commit 9f4b86a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 84 deletions.
65 changes: 12 additions & 53 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@
name = "wnfsutils"
version = "1.1.6"
edition = "2021"
description = "WNFS utilities for web applications"
license = "MIT OR Apache-2.0"
repository = "https://github.com/functionland/wnfs-utils-web"
readme = "README.md"
keywords = ["wnfs", "web", "storage", "encryption"]
categories = ["wasm", "web-programming"]

[lib]
crate-type = ["cdylib", "rlib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
wnfs = { git = "https://github.com/wnfs-wg/rs-wnfs.git", rev = "491ce8555d811477e934e6a1a6b6e0d347a32357" }
# Need to implement a put_block_keyed method for datastore after this commit which is required for rs-car-mirror and other structural changes to datastore are done
bytes = "1.4.0"
chrono = { version = "0.4.22", features = ["wasm-bindgen", "serde"] }
chrono = "0.4.22"
crc32fast = "1.3.2"
rand = { version = "0.8", features = ["getrandom", "std"] }
rand = "0.8.5"
libipld = { version = "0.16", features = ["dag-cbor", "derive", "serde-codec"] }
kv = "0.24.0"
async-std = { version = "1.12", features = ["attributes"] }
rand_core = "0.6.4"
serde = { version = "1.0.149", features = ["derive"] }
serde = "1.0.149"
serde_json = "1.0.89"
anyhow = "1.0.66"
async-trait = "0.1.58"
Expand All @@ -30,46 +24,11 @@ sha3 = "0.10"
futures = "0.3"
rsa = "0.9"
rand_chacha = "0.3"
base64 = "0.22.1"
getrandom = { version = "0.2", features = ["js", "wasm-bindgen"] }

# WASM-specific dependencies
[target.'cfg(target_arch = "wasm32")'.dependencies]
tokio = { version = "1.29.1", default-features = false, features = ["rt"] }
console_error_panic_hook = "0.1"
wasm-bindgen = "=0.2.87"
wasm-bindgen-futures = "=0.4.37"
js-sys = "0.3"
web-sys = { version = "0.3", features = [
"console",
"Headers",
"Request",
"RequestInit",
"RequestMode",
"Response",
"Window",
"File",
"FileList",
"FileReader",
"Blob",
"FileSystem"
]}

# Non-WASM dependencies
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1.29.1", features = ["full", "fs"] }
async-std = { version = "1.12.0", features = ["attributes", "default", "std"] }
base64 = "0.13.0"
tempfile = "3.2"
getrandom = { version = "0.2", features = ["js"] }
wasm-bindgen-futures = "0.4.7"
tokio = { version = "1.41.1", features = ["rt", "sync", "macros", "io-util", "time"] }

[features]
default = []
wasm = []
native = []

[profile.release]
opt-level = 3
lto = true
codegen-units = 1

[profile.release.package."*"]
opt-level = 3
[lib]
crate-type = ["cdylib", "rlib"]
63 changes: 32 additions & 31 deletions src/private_forest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,10 +711,11 @@ impl<'a> PrivateDirectoryHelper<'a> {
wnfs_key: Vec<u8>,
) -> Result<(PrivateDirectoryHelper<'a>, AccessKey, Cid), String> {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Unable to create a runtime");
return runtime.block_on(PrivateDirectoryHelper::init(store, wnfs_key));
.enable_time() // Enable time-based features if needed
.build()
.expect("Unable to create a runtime");

runtime.block_on(PrivateDirectoryHelper::init(store, wnfs_key))
}

pub fn synced_load_with_wnfs_key(
Expand All @@ -723,9 +724,9 @@ impl<'a> PrivateDirectoryHelper<'a> {
wnfs_key: Vec<u8>,
) -> Result<PrivateDirectoryHelper<'a>, String> {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Unable to create a runtime");
.enable_time() // Enable time-based features if needed
.build()
.expect("Unable to create a runtime");
return runtime.block_on(PrivateDirectoryHelper::load_with_wnfs_key(
store, forest_cid, wnfs_key,
));
Expand All @@ -736,9 +737,9 @@ impl<'a> PrivateDirectoryHelper<'a> {
forest_cid: Cid,
) -> Result<PrivateDirectoryHelper<'a>, String> {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Unable to create a runtime");
.enable_time() // Enable time-based features if needed
.build()
.expect("Unable to create a runtime");
return runtime.block_on(PrivateDirectoryHelper::reload(store, forest_cid));
}

Expand All @@ -749,9 +750,9 @@ impl<'a> PrivateDirectoryHelper<'a> {
modification_time_seconds: i64,
) -> Result<Cid, String> {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Unable to create a runtime");
.enable_time() // Enable time-based features if needed
.build()
.expect("Unable to create a runtime");
return runtime.block_on(self.write_file(
path_segments,
content,
Expand All @@ -761,17 +762,17 @@ impl<'a> PrivateDirectoryHelper<'a> {

pub fn synced_read_file(&mut self, path_segments: &[String]) -> Result<Vec<u8>, String> {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Unable to create a runtime");
.enable_time() // Enable time-based features if needed
.build()
.expect("Unable to create a runtime");
return runtime.block_on(self.read_file(path_segments));
}

pub fn synced_mkdir(&mut self, path_segments: &[String]) -> Result<Cid, String> {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Unable to create a runtime");
.enable_time() // Enable time-based features if needed
.build()
.expect("Unable to create a runtime");
return runtime.block_on(self.mkdir(path_segments));
}

Expand All @@ -781,9 +782,9 @@ impl<'a> PrivateDirectoryHelper<'a> {
target_path_segments: &[String],
) -> Result<Cid, String> {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Unable to create a runtime");
.enable_time() // Enable time-based features if needed
.build()
.expect("Unable to create a runtime");
return runtime.block_on(self.mv(source_path_segments, target_path_segments));
}

Expand All @@ -793,17 +794,17 @@ impl<'a> PrivateDirectoryHelper<'a> {
target_path_segments: &[String],
) -> Result<Cid, String> {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Unable to create a runtime");
.enable_time() // Enable time-based features if needed
.build()
.expect("Unable to create a runtime");
return runtime.block_on(self.cp(source_path_segments, target_path_segments));
}

pub fn synced_rm(&mut self, path_segments: &[String]) -> Result<Cid, String> {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Unable to create a runtime");
.enable_time() // Enable time-based features if needed
.build()
.expect("Unable to create a runtime");
return runtime.block_on(self.rm(path_segments));
}

Expand All @@ -812,9 +813,9 @@ impl<'a> PrivateDirectoryHelper<'a> {
path_segments: &[String],
) -> Result<Vec<(String, Metadata)>, String> {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Unable to create a runtime");
.enable_time() // Enable time-based features if needed
.build()
.expect("Unable to create a runtime");
return runtime.block_on(self.ls_files(path_segments));
}

Expand Down

0 comments on commit 9f4b86a

Please sign in to comment.