Skip to content

Commit

Permalink
Add support for wasm32-wasi.
Browse files Browse the repository at this point in the history
[The files changed in this commit were part of the original PR. The
original PR also changed other files, but those changes were removed.]
  • Loading branch information
JanKaul authored and briansmith committed Oct 14, 2023
1 parent 0f8386d commit 9f9063a
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ libc = { version = "0.2.148", default-features = false }
[target.'cfg(all(target_arch = "aarch64", target_os = "windows"))'.dependencies]
windows-sys = { version = "0.48", features = ["Win32_Foundation", "Win32_System_Threading"] }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
wasm-bindgen-test = { version = "0.3.37", default-features = false }

[target.'cfg(any(unix, windows))'.dev-dependencies]
[target.'cfg(any(unix, windows, target_os = "wasi"))'.dev-dependencies]
libc = { version = "0.2.148", default-features = false }

[build-dependencies]
Expand Down
6 changes: 6 additions & 0 deletions mk/cargo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ case $target in
export CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER=wasm-bindgen-test-runner
export WASM_BINDGEN_TEST_TIMEOUT=60
;;
wasm32-wasi)
# The first two are only needed for when the "wasm_c" feature is enabled.
export CC_wasm32_wasi=$WASI_SDK_PATH/bin/clang
export AR_wasm32_wasi=$WASI_SDK_PATH/bin/llvm-ar
export CARGO_TARGET_WASM32_WASI_RUNNER=wasmtime
;;
*)
;;
esac
Expand Down
1 change: 1 addition & 0 deletions src/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ impl crate::sealed::Sealed for SystemRandom {}
target_os = "solaris",
target_os = "windows",
target_os = "vita",
target_os = "wasi",
all(
feature = "wasm32_unknown_unknown_js",
target_arch = "wasm32",
Expand Down
4 changes: 2 additions & 2 deletions tests/aead_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test_configure!(run_in_browser);

use core::ops::RangeFrom;
Expand Down
4 changes: 2 additions & 2 deletions tests/constant_time_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

use ring::{constant_time, error, rand};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test_configure!(run_in_browser);

// This logic is loosly based on BoringSSL's `TEST(ConstantTimeTest, MemCmp)`.
Expand Down
6 changes: 3 additions & 3 deletions tests/digest_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

use ring::{digest, test, test_file};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test_configure!(run_in_browser);

/// Test vectors from BoringSSL, Go, and other sources.
Expand Down Expand Up @@ -79,7 +79,7 @@ mod digest_shavs {
use super::{run_known_answer_test, run_monte_carlo_test};
use ring::{digest, test_file};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[test]
Expand Down
4 changes: 2 additions & 2 deletions tests/ed25519_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ use ring::{
test, test_file,
};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test_configure!(run_in_browser);

/// Test vectors from BoringSSL.
Expand Down
4 changes: 2 additions & 2 deletions tests/hkdf_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

use ring::{digest, error, hkdf, test, test_file};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test_configure!(run_in_browser);

#[test]
Expand Down
4 changes: 2 additions & 2 deletions tests/hmac_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

use ring::{digest, hmac, test, test_file};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test_configure!(run_in_browser);

#[test]
Expand Down
4 changes: 2 additions & 2 deletions tests/pbkdf2_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
use core::num::NonZeroU32;
use ring::{digest, error, pbkdf2, test, test_file};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test_configure!(run_in_browser);

/// Test vectors from BoringSSL, Go, and other sources.
Expand Down
4 changes: 2 additions & 2 deletions tests/rand_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ use ring::{
test,
};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test_configure!(run_in_browser);

#[test]
Expand Down
4 changes: 2 additions & 2 deletions tests/rsa_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ use ring::{
test, test_file,
};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test_configure!(run_in_browser);

#[test]
Expand Down
4 changes: 2 additions & 2 deletions tests/signature_tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use ring::{signature, test};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
wasm_bindgen_test_configure!(run_in_browser);

#[test]
Expand Down

0 comments on commit 9f9063a

Please sign in to comment.