From 6464940974db6f8118e96bb526e5a39b1848ec90 Mon Sep 17 00:00:00 2001 From: Danny Browning Date: Tue, 30 Jan 2024 14:23:20 -0700 Subject: [PATCH 1/2] feat: Support wasm32-wasi Adds support and checks for wasm32-wasi --- .github/workflows/build.yml | 7 ++++++- ssi-dids/Cargo.toml | 6 +++--- ssi-json-ld/Cargo.toml | 4 +++- ssi-json-ld/src/lib.rs | 9 +++++++++ ssi-jwt/Cargo.toml | 4 ++-- ssi-ldp/Cargo.toml | 6 +++--- ssi-ucan/Cargo.toml | 4 ++-- ssi-vc/Cargo.toml | 4 ++-- 8 files changed, 30 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 497f07c29..45d35d6b8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,11 +48,16 @@ jobs: cp ../vc-test/config.json . npm test - - name: Test WASM compilation + - name: Test wasm + bindgen compilation run: | rustup target add wasm32-unknown-unknown cargo check --workspace --target wasm32-unknown-unknown + - name: Test wasm32-wasi compilation + run: | + rustup target add wasm32-wasi + cargo check --workspace --target wasm32-wasi + - name: Test examples run: | cargo test --examples diff --git a/ssi-dids/Cargo.toml b/ssi-dids/Cargo.toml index 318c9e3bf..3f3069a7a 100644 --- a/ssi-dids/Cargo.toml +++ b/ssi-dids/Cargo.toml @@ -27,16 +27,16 @@ reqwest = { version = "0.11", default-features = false, features = ["json", "rus percent-encoding = { version = "2.1", optional = true } iref = { version = "2.2.2", features = ["serde"] } static-iref = "2.0.0" -ssi-jwk = { path = "../ssi-jwk", version = "0.1", default-features = false } ssi-json-ld = { path = "../ssi-json-ld", version = "0.2" } +ssi-jwk = { path = "../ssi-jwk", version = "0.1", default-features = false } ssi-core = { path = "../ssi-core", version = "0.1"} ssi-caips = { path = "../ssi-caips", version = "0.1", default-features = false } -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +[target.'cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))'.dependencies] chrono = { version = "0.4", features = ["serde"] } -[target.'cfg(target_arch = "wasm32")'.dependencies] +[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dependencies] chrono = { version = "0.4", features = ["serde", "wasmbind"] } [dev-dependencies] diff --git a/ssi-json-ld/Cargo.toml b/ssi-json-ld/Cargo.toml index 89bcc3428..2513309aa 100644 --- a/ssi-json-ld/Cargo.toml +++ b/ssi-json-ld/Cargo.toml @@ -10,7 +10,6 @@ documentation = "https://docs.rs/ssi-json-ld/" [dependencies] thiserror = "1.0" -async-std = { version = "1.9", features = ["attributes"] } json-ld = "0.12.1" iref = "^2.0.3" static-iref = "2" @@ -24,6 +23,9 @@ grdf = "0.16.2" ssi-contexts = { version = "0.1.5", path = "../contexts/" } ssi-crypto = { path = "../ssi-crypto", version = "0.1" } +[target.'cfg(not(all(target_arch = "wasm32", target_os = "wasi")))'.dependencies] +async-std = { version = "1.9", features = ["attributes"] } + [dev-dependencies] difference = "2.0" nquads-syntax = "0.10.0" diff --git a/ssi-json-ld/src/lib.rs b/ssi-json-ld/src/lib.rs index fb9f5660c..40b56e29a 100644 --- a/ssi-json-ld/src/lib.rs +++ b/ssi-json-ld/src/lib.rs @@ -1,11 +1,13 @@ //! JSON-LD context loaders. use std::collections::HashMap; +#[cfg(not(all(target_arch = "wasm32", target_os = "wasi")))] use std::sync::Arc; pub mod rdf; pub mod urdna2015; +#[cfg(not(all(target_arch = "wasm32", target_os = "wasi")))] use async_std::sync::RwLock; use futures::future::{BoxFuture, FutureExt}; use iref::{Iri, IriBuf}; @@ -342,6 +344,7 @@ pub struct ContextLoader { // This map holds the optional, additional context objects. This is where any app-specific context // objects would go. The Arc> is necessary because json_ld::Loader trait unfortunately // has a method that uses `&mut self`. + #[cfg(not(all(target_arch = "wasm32", target_os = "wasi")))] context_map: Option>>, } @@ -376,6 +379,7 @@ impl ContextLoader { pub fn empty() -> Self { Self { static_loader: None, + #[cfg(not(all(target_arch = "wasm32", target_os = "wasi")))] context_map: None, } } @@ -388,6 +392,7 @@ impl ContextLoader { /// Using the builder pattern, the map of additional contexts can be set. These context objects /// will be checked after StaticLoader (if it's specified). preparsed_context_map should map /// the context URLs to their JSON content. + #[cfg(not(all(target_arch = "wasm32", target_os = "wasi")))] pub fn with_context_map_from( mut self, preparsed_context_map: HashMap, @@ -417,6 +422,7 @@ impl std::default::Default for ContextLoader { fn default() -> Self { Self { static_loader: Some(StaticLoader), + #[cfg(not(all(target_arch = "wasm32", target_os = "wasi")))] context_map: None, } } @@ -454,6 +460,7 @@ impl Loader for ContextLoader { }; // If we fell through, then try `self.context_map`. + #[cfg(not(all(target_arch = "wasm32", target_os = "wasi")))] if let Some(context_map) = &mut self.context_map { context_map .read() @@ -464,6 +471,8 @@ impl Loader for ContextLoader { } else { Err(UnknownContext(url)) } + #[cfg(all(target_arch = "wasm32", target_os = "wasi"))] + Err(UnknownContext(url)) } .boxed() } diff --git a/ssi-jwt/Cargo.toml b/ssi-jwt/Cargo.toml index 4807ec5e7..28adba471 100644 --- a/ssi-jwt/Cargo.toml +++ b/ssi-jwt/Cargo.toml @@ -17,8 +17,8 @@ ssi-jws = { path = "../ssi-jws", version = "0.1", default-features = false } serde_with = "2.3.2" -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +[target.'cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))'.dependencies] chrono = { version = "0.4", features = ["serde"] } -[target.'cfg(target_arch = "wasm32")'.dependencies] +[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dependencies] chrono = { version = "0.4", features = ["serde", "wasmbind"] } diff --git a/ssi-ldp/Cargo.toml b/ssi-ldp/Cargo.toml index e45ecbdf2..9889ac3d4 100644 --- a/ssi-ldp/Cargo.toml +++ b/ssi-ldp/Cargo.toml @@ -57,19 +57,19 @@ k256 = { version = "0.13.1", optional = true, features = ["ecdsa"] } p256 = { version = "0.13.2", optional = true, features = ["ecdsa"] } keccak-hash = { version = "0.7", optional = true } ssi-jwk = { path = "../ssi-jwk", version = "0.1.1" } -ssi-json-ld = { path = "../ssi-json-ld", version = "0.2" } ssi-core = { path = "../ssi-core", version = "0.1" } ssi-dids = { path = "../ssi-dids", version = "0.1" } ssi-crypto = { path = "../ssi-crypto", version = "0.1" } +ssi-json-ld = { path = "../ssi-json-ld", version = "0.2" } ssi-jws = { path = "../ssi-jws", version = "0.1" } ssi-tzkey = { path = "../ssi-tzkey", version = "0.1", optional = true } ssi-caips = { path = "../ssi-caips", version = "0.1" } ssi-contexts = { version = "0.1.5", path = "../contexts" } -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +[target.'cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))'.dependencies] chrono = { version = "0.4", features = ["serde"] } -[target.'cfg(target_arch = "wasm32")'.dependencies] +[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dependencies] chrono = { version = "0.4", features = ["serde", "wasmbind"] } [dev-dependencies] diff --git a/ssi-ucan/Cargo.toml b/ssi-ucan/Cargo.toml index 4ba414339..4241a37d1 100644 --- a/ssi-ucan/Cargo.toml +++ b/ssi-ucan/Cargo.toml @@ -23,10 +23,10 @@ ssi-caips = { path = "../ssi-caips", version = "0.1", default-features = false libipld = { version = "0.14", default-features = false, features = ["dag-cbor", "dag-json", "derive", "serde-codec"]} -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +[target.'cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))'.dependencies] chrono = { version = "0.4", features = ["serde"] } -[target.'cfg(target_arch = "wasm32")'.dependencies] +[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dependencies] chrono = { version = "0.4", features = ["serde", "wasmbind"] } [dev-dependencies] diff --git a/ssi-vc/Cargo.toml b/ssi-vc/Cargo.toml index 835f99e02..aa61d8560 100644 --- a/ssi-vc/Cargo.toml +++ b/ssi-vc/Cargo.toml @@ -39,10 +39,10 @@ ssi-json-ld = { path = "../ssi-json-ld", version = "0.2", default-features = fal ssi-ldp = { path = "../ssi-ldp", version = "0.3.0", default-features = false } serde_with = "2.3.2" -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +[target.'cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))'.dependencies] chrono = { version = "0.4", features = ["serde"] } -[target.'cfg(target_arch = "wasm32")'.dependencies] +[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dependencies] chrono = { version = "0.4", features = ["serde", "wasmbind"] } [dev-dependencies] From 728fb9b37b2b0f78121310c3d17fa34b27add558 Mon Sep 17 00:00:00 2001 From: Danny Browning Date: Wed, 31 Jan 2024 12:46:59 -0700 Subject: [PATCH 2/2] fix: exclude test packages --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 45d35d6b8..acf78a0fd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -56,7 +56,7 @@ jobs: - name: Test wasm32-wasi compilation run: | rustup target add wasm32-wasi - cargo check --workspace --target wasm32-wasi + cargo check --workspace --target wasm32-wasi --exclude 'ssi-did-test' --exclude 'ssi-vc-test' - name: Test examples run: |