Skip to content

Commit

Permalink
Add wasi compatibility.
Browse files Browse the repository at this point in the history
Compiling to wasi.

OpenSSL

None web wasm versions of files.

Successfully building

wasip1/p2 compatibility

Add backtrace

panic

Fix test targets

Adding ring to web

web and wasi working.

Synchronous web validation.

Reorganize web dependencies.

Build directly to wasip2

Support compiling to wasm32-wasip2

- wasip2 will require +nightly until rust-lang/rust#130323 is resolved and/or std::os::wasip2 is available in stable.
- Support was added to rustix for version 0.38.39 bytecodealliance/rustix#1205
- Support was added to tempfile for version 3.14 Stebalien/tempfile#305
  • Loading branch information
cdmurph32 committed Jan 22, 2025
1 parent 06fc905 commit 0e858dc
Show file tree
Hide file tree
Showing 12 changed files with 1,150 additions and 19 deletions.
2 changes: 1 addition & 1 deletion make_test_images/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ nom = "7.1.3"
regex = "1.5.6"
serde = "1.0.197"
serde_json = { version = "1.0.117", features = ["preserve_order"] }
tempfile = "3.10.1"
tempfile = "3.15.0"

[features]
# prevents these features from being always enabled in the workspace
Expand Down
37 changes: 25 additions & 12 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ byteorder = { version = "1.4.3", default-features = false }
byteordered = "0.6.0"
c2pa-crypto = { path = "../internal/crypto", version = "0.3.0" }
c2pa-status-tracker = { path = "../internal/status-tracker", version = "0.3.0" }
chrono = { version = "0.4.39", default-features = false, features = [
"serde",
"wasmbind",
] }
chrono = { version = "0.4.39", default-features = false, features = ["serde"] }
ciborium = "0.2.2"
config = { version = "0.14.0", default-features = false, features = [
"json",
Expand Down Expand Up @@ -124,30 +121,46 @@ serde_with = "3.11.0"
serde-transcode = "1.1.1"
sha1 = "0.10.6"
sha2 = "0.10.6"
tempfile = "3.10.1"
tempfile = "3.15"
thiserror = "2.0.8"
treeline = "0.1.0"
url = "2.5.3"
uuid = { version = "1.10.0", features = ["serde", "v4", "js"] }
uuid = { version = "1.10.0", features = ["serde", "v4"] }
x509-certificate = "0.23.1"
x509-parser = "0.16.0"
x509-certificate = "0.21.0"
zip = { version = "2.2.1", default-features = false }

[target.'cfg(target_arch = "wasm32")'.dependencies]
rsa = { version = "0.9.6", features = ["sha2"] }
spki = "0.7.3"

[target.'cfg(target_env = "p2")'.dependencies]
tempfile = { version = "3.15", features = ["nightly"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
ureq = "2.4.0"

[target.'cfg(any(target_os = "wasi", not(target_arch = "wasm32")))'.dependencies]
image = { version = "0.24.7", default-features = false, features = [
"jpeg",
"png",
], optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
[target.'cfg(target_os = "wasi")'.dependencies]
getrandom = "0.2.7"


[target.'cfg(all(target_arch = "wasm32",not(target_os = "wasi")))'.dependencies]
chrono = { version = "0.4.39", default-features = false, features = [
"serde",
"wasmbind",
] }
console_log = { version = "1.0.0", features = ["color"] }
getrandom = { version = "0.2.7", features = ["js"] }
js-sys = "0.3.58"
rand_core = "0.9.0-alpha.2"
rsa = { version = "0.9.6", features = ["sha2"] }
serde-wasm-bindgen = "0.6.5"
spki = "0.7.3"
uuid = { version = "1.10.0", features = ["serde", "v4", "js"] }
wasm-bindgen = "0.2.83"
wasm-bindgen-futures = "0.4.31"
web-sys = { version = "0.3.58", features = [
Expand All @@ -168,8 +181,8 @@ hex-literal = "0.4.1"
jumbf = "0.4.0"
mockall = "0.13.1"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.31"
[target.'cfg(all(target_arch = "wasm32",not(target_os = "wasi")))'.dev-dependencies]
wasm-bindgen-test = "0.3.45"

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
actix = "0.13.1"
Expand Down
7 changes: 5 additions & 2 deletions sdk/src/asset_handlers/jpeg_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ pub mod tests {

use std::io::{Read, Seek};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
use wasm_bindgen_test::*;

use super::*;
Expand Down Expand Up @@ -1223,7 +1223,10 @@ pub mod tests {
}

#[cfg_attr(not(target_arch = "wasm32"), actix::test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg_attr(
all(target_arch = "wasm32", not(target_os = "wasi")),
wasm_bindgen_test
)]
async fn test_xmp_read_write_stream() {
let source_bytes = include_bytes!("../../tests/fixtures/CA.jpg");

Expand Down
1 change: 1 addition & 0 deletions sdk/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@ impl Builder {
mod tests {
#![allow(clippy::expect_used)]
#![allow(clippy::unwrap_used)]
#![cfg(not(target_os = "wasi"))]
use std::io::Cursor;

use c2pa_crypto::raw_signature::SigningAlg;
Expand Down
1 change: 1 addition & 0 deletions sdk/src/ingredient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,7 @@ impl IngredientOptions for DefaultOptions {
mod tests {
#![allow(clippy::expect_used)]
#![allow(clippy::unwrap_used)]
#![cfg(not(target_os = wasi))]

#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*;
Expand Down
1 change: 1 addition & 0 deletions sdk/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,7 @@ impl SignatureInfo {
pub(crate) mod tests {
#![allow(clippy::expect_used)]
#![allow(clippy::unwrap_used)]
#![cfg(not(target_os = wasi))]

use std::io::Cursor;

Expand Down
1 change: 1 addition & 0 deletions sdk/src/manifest_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ impl std::fmt::Display for ManifestStore {
mod tests {
#![allow(clippy::expect_used)]
#![allow(clippy::unwrap_used)]
#![cfg(not(target_os = wasi))]

use c2pa_status_tracker::OneShotStatusTracker;
#[cfg(target_arch = "wasm32")]
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/salt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ impl Default for DefaultSalt {

impl SaltGenerator for DefaultSalt {
fn generate_salt(&self) -> Option<Vec<u8>> {
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
{
Some(crate::wasm::util::get_random_values(self.salt_len).ok()?)
}
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
{
use rand::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion sdk/src/utils/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ impl WebCryptoSigner {
}
}

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
#[async_trait::async_trait(?Send)]
impl AsyncSigner for WebCryptoSigner {
fn alg(&self) -> SigningAlg {
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
// specific language governing permissions and limitations under
// each license.

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
pub(crate) mod util;
Loading

0 comments on commit 0e858dc

Please sign in to comment.