From 9f4b86a6f14069ae81292d5fa849f2c794f0d283 Mon Sep 17 00:00:00 2001 From: ehsan Date: Sat, 23 Nov 2024 22:10:59 -0500 Subject: [PATCH] corrected for wasm --- Cargo.toml | 65 ++++++++----------------------------------- src/private_forest.rs | 63 ++++++++++++++++++++--------------------- 2 files changed, 44 insertions(+), 84 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8959887..fb646e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -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 \ No newline at end of file +[lib] +crate-type = ["cdylib", "rlib"] \ No newline at end of file diff --git a/src/private_forest.rs b/src/private_forest.rs index 89e782c..5686e19 100644 --- a/src/private_forest.rs +++ b/src/private_forest.rs @@ -711,10 +711,11 @@ impl<'a> PrivateDirectoryHelper<'a> { wnfs_key: Vec, ) -> 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( @@ -723,9 +724,9 @@ impl<'a> PrivateDirectoryHelper<'a> { wnfs_key: Vec, ) -> Result, 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, )); @@ -736,9 +737,9 @@ impl<'a> PrivateDirectoryHelper<'a> { forest_cid: Cid, ) -> Result, 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)); } @@ -749,9 +750,9 @@ impl<'a> PrivateDirectoryHelper<'a> { modification_time_seconds: i64, ) -> Result { 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, @@ -761,17 +762,17 @@ impl<'a> PrivateDirectoryHelper<'a> { pub fn synced_read_file(&mut self, path_segments: &[String]) -> Result, 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 { 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)); } @@ -781,9 +782,9 @@ impl<'a> PrivateDirectoryHelper<'a> { target_path_segments: &[String], ) -> Result { 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)); } @@ -793,17 +794,17 @@ impl<'a> PrivateDirectoryHelper<'a> { target_path_segments: &[String], ) -> Result { 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 { 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)); } @@ -812,9 +813,9 @@ impl<'a> PrivateDirectoryHelper<'a> { path_segments: &[String], ) -> Result, 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)); }