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

Adapt tests to work for wasm32-wasi and add wasm32-wasi to CI. #1745

Merged
merged 4 commits into from
Oct 14, 2023
Merged
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
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ jobs:
- i686-unknown-linux-musl
- powerpc-unknown-linux-gnu
- riscv64gc-unknown-linux-gnu
- wasm32-wasi
- x86_64-pc-windows-gnu
- x86_64-pc-windows-msvc
- x86_64-apple-darwin
Expand Down Expand Up @@ -254,6 +255,9 @@ jobs:
- target: riscv64gc-unknown-linux-gnu
host_os: ubuntu-22.04

- target: wasm32-wasi
host_os: ubuntu-22.04

- target: x86_64-pc-windows-gnu
host_os: windows-latest

Expand Down Expand Up @@ -435,7 +439,7 @@ jobs:

# The wasm32-unknown-unknown targets have a different set of feature sets and
# an additional `webdriver` dimension.
test-wasm32:
test-wasm32-browser:
# Don't run duplicate `push` jobs for the repo owner's PRs.
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

Expand Down
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
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ fn configure_cc(c: &mut cc::Build, target: &Target, include_dir: &Path) {
// Allow cross-compiling without a target sysroot for these targets.
//
// poly1305_vec.c requires <emmintrin.h> which requires <stdlib.h>.
if (target.arch == "wasm32" && target.os == "unknown")
if (target.arch == "wasm32")
|| (target.os == "linux" && target.is_musl && target.arch != "x86_64")
{
if let Ok(compiler) = c.try_get_compiler() {
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=clang-$llvm_version
export AR_wasm32_wasi=llvm-ar-$llvm_version
export CARGO_TARGET_WASM32_WASI_RUNNER=target/tools/linux-x86_64/wasmtime/wasmtime
;;
*)
;;
esac
Expand Down
8 changes: 8 additions & 0 deletions mk/install-build-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ case $target in
cargo install wasm-bindgen-cli --bin wasm-bindgen-test-runner
use_clang=1
;;
--target=wasm32-wasi)
use_clang=1
git clone \
--branch linux-x86_64 \
--depth 1 \
https://github.com/briansmith/ring-toolchain \
target/tools/linux-x86_64
;;
--target=*)
;;
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
9 changes: 4 additions & 5 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 Expand Up @@ -48,11 +48,10 @@ macro_rules! test_aead {
$(
#[allow(non_snake_case)]
mod $alg { // Provide a separate namespace for each algorithm's test.
#[cfg(not(target_arch = "wasm32"))]
use super::super::*;

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

test_known_answer!(
$alg,
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
Loading