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

feat: Support wasm32-wasi #544

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 --exclude 'ssi-did-test' --exclude 'ssi-vc-test'

- name: Test examples
run: |
cargo test --examples
Expand Down
6 changes: 3 additions & 3 deletions ssi-dids/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 3 additions & 1 deletion ssi-json-ld/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions ssi-json-ld/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<RwLock<_>> 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<Arc<RwLock<ContextMap>>>,
}

Expand Down Expand Up @@ -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,
}
}
Expand All @@ -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<String, String>,
Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -454,6 +460,7 @@ impl Loader<IriBuf, Span> 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()
Expand All @@ -464,6 +471,8 @@ impl Loader<IriBuf, Span> for ContextLoader {
} else {
Err(UnknownContext(url))
}
#[cfg(all(target_arch = "wasm32", target_os = "wasi"))]
Err(UnknownContext(url))
}
.boxed()
}
Expand Down
4 changes: 2 additions & 2 deletions ssi-jwt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
6 changes: 3 additions & 3 deletions ssi-ldp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions ssi-ucan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions ssi-vc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down